blunt_stub_factory 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +1 -0
- data/README.md +8 -4
- data/Rakefile +4 -1
- data/lib/stub_factory.rb +1 -1
- data/lib/stub_factory/version.rb +1 -1
- data/spec/factories/wrong_test.rb +3 -0
- data/spec/lib/stub_factory_spec.rb +15 -8
- data/spec/spec_helper.rb +20 -0
- data/spec/support/helpers/{helper_test.rb → stub_helper_test.rb} +0 -0
- data/spec/support/helpers/wrong_helper_test.rb +1 -0
- data/stub_factory.gemspec +1 -0
- metadata +25 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5891a3f4ef0b257a71df4f74e66bb3c67cfe3b1e
|
4
|
+
data.tar.gz: 7fb27f94176c2d1bcf7e94e955e529d29315d344
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37cd615fd2dd6a1809dca2db6156adfef0fea934950eab64350d07bf9c7b7294cfb66fe6ba43215e2af968a432150dcd52e6884842169a526b53093998ed488d
|
7
|
+
data.tar.gz: 3061def43f2c37316808043e65e9671445a0c673fb3587aae63d67af1fb8bc54792cc9d82a25de944cb2e4ed8e3afb07024343b48ea3fbb95145e112953799a1
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# StubFactory
|
2
|
+
[](https://travis-ci.org/LFDM/stub_factory)
|
3
|
+
[](https://coveralls.io/r/LFDM/stub_factory)
|
4
|
+
[](https://gemnasium.com/LFDM/stub_factory)
|
2
5
|
|
3
6
|
A blunt StubFactory that helps to test tightly coupled code, but handle with care: This is not a best practice. If you find yourself relying on this a lot, you might have to rethink your design.
|
4
7
|
|
@@ -6,7 +9,7 @@ A blunt StubFactory that helps to test tightly coupled code, but handle with car
|
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
8
11
|
|
9
|
-
gem 'stub_factory'
|
12
|
+
gem 'blunt_stub_factory', require: 'stub_factory'
|
10
13
|
|
11
14
|
And then execute:
|
12
15
|
|
@@ -14,12 +17,13 @@ And then execute:
|
|
14
17
|
|
15
18
|
Or install it yourself as:
|
16
19
|
|
17
|
-
$ gem install
|
20
|
+
$ gem install blunt_stub_factory
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
24
|
```ruby
|
22
25
|
require 'stub_factory'
|
26
|
+
# beware: StubFactory resides in the stub_factory file, not as it's gemname would indicate (the name stub_factory was already taken...)
|
23
27
|
|
24
28
|
Class A
|
25
29
|
attr_reader :test, :test2
|
@@ -48,7 +52,7 @@ b.test
|
|
48
52
|
```
|
49
53
|
|
50
54
|
Default as well as custom templates to overwrite variables can be defined - StubFactory automatically looks for such statements
|
51
|
-
in your spec/factories folder.
|
55
|
+
in your spec/factories folder. Only files named template_***.rb are loaded.
|
52
56
|
```ruby
|
53
57
|
StubFactory.define_template(:a) do
|
54
58
|
{ test2 = "template value" }
|
@@ -86,7 +90,7 @@ b.a_method
|
|
86
90
|
```
|
87
91
|
|
88
92
|
For ease of use, helper methods can be defined when they are included in your RSpec configuarion.
|
89
|
-
Place define_helper statements in your spec/support/helpers folder.
|
93
|
+
Place define_helper statements in your spec/support/helpers folder. Only files named stub_***.rb are loaded.
|
90
94
|
```ruby
|
91
95
|
RSpec.configure do |config|
|
92
96
|
config.include StubFactory::Helpers
|
data/Rakefile
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
+
require 'coveralls/rake/task'
|
4
|
+
|
5
|
+
Coveralls::RakeTask.new
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
5
8
|
t.rspec_opts = '-f d --color'
|
6
9
|
end
|
7
10
|
|
8
|
-
task :default => :spec
|
11
|
+
task :default => [:spec, 'coveralls:push']
|
data/lib/stub_factory.rb
CHANGED
@@ -59,7 +59,7 @@ module StubFactory
|
|
59
59
|
path = File.expand_path(rel_path)
|
60
60
|
|
61
61
|
if File.exists?(path)
|
62
|
-
require "#{path}" if File.file?(path)
|
62
|
+
require "#{path}" if File.file?(path) && path.match(/\/(stub_|template_)[^\/]*$/)
|
63
63
|
Dir["#{path}/*"].each { |file| require_path(file) }
|
64
64
|
end
|
65
65
|
end
|
data/lib/stub_factory/version.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'stub_factory'
|
2
3
|
|
3
|
-
# Methods defined by .define_helper will not work without this:
|
4
|
-
RSpec.configure do |config|
|
5
|
-
config.include StubFactory::Helpers
|
6
|
-
end
|
7
|
-
|
8
4
|
describe StubFactory do
|
9
5
|
before :all do
|
10
6
|
# the attr reader is set for convenience
|
@@ -46,10 +42,15 @@ describe StubFactory do
|
|
46
42
|
expect { StubFactory.define_helper(:helper2, :A) }.to raise_error(StubFactory::HelperError)
|
47
43
|
end
|
48
44
|
|
49
|
-
it "helpers can be defined in files - default path is spec/support/helpers" do
|
50
|
-
# required_helper is defined in #spec/support/
|
45
|
+
it "helpers can be defined in files called stub_***.rb - default path is spec/support/helpers" do
|
46
|
+
# required_helper is defined in #spec/support/stub_helper_test.rb
|
51
47
|
stub_required_helper.should be_an_instance_of A
|
52
48
|
end
|
49
|
+
|
50
|
+
it "to allow other files in this folder wrongly named files are not consumed" do
|
51
|
+
# wrong_helper is defined in #spec/support/wrong_helper_test.rb
|
52
|
+
expect { stub_wrong_helper }.to raise_error NameError
|
53
|
+
end
|
53
54
|
end
|
54
55
|
|
55
56
|
describe "#new_stub" do
|
@@ -82,10 +83,16 @@ describe StubFactory do
|
|
82
83
|
o.test.should be_nil
|
83
84
|
end
|
84
85
|
|
85
|
-
it "templates can be defined in files - their default path is spec/factories" do
|
86
|
+
it "templates can be defined in files called template_**.rb - their default path is spec/factories" do
|
86
87
|
# required_template is defined in #spec/factories/template_test.rb
|
87
88
|
A.new_stub(template: :required_template).test.should == 11
|
88
89
|
end
|
90
|
+
|
91
|
+
it "to allow other files in this folder wrongly named files are not consumed" do
|
92
|
+
# wrong_template is defined in #spec/factories/wrong_test.rb
|
93
|
+
# with the variable test == 11
|
94
|
+
A.new_stub(template: :wrong_template).test.should be_nil
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
context "when a custom template exists" do
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter '/spec/'
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'stub_factory'
|
16
|
+
|
17
|
+
# Methods defined by .define_helper will not work without this:
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.include StubFactory::Helpers
|
20
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
StubFactory.define_helper(:wrong_helper, :A)
|
data/stub_factory.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blunt_stub_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LFDM
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
55
69
|
description: Simple StubFactory for rspec
|
56
70
|
email:
|
57
71
|
- 1986gh@gmail.com
|
@@ -60,6 +74,7 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- .gitignore
|
77
|
+
- .travis.yml
|
63
78
|
- Gemfile
|
64
79
|
- LICENSE.txt
|
65
80
|
- README.md
|
@@ -69,8 +84,11 @@ files:
|
|
69
84
|
- lib/stub_factory/helpers.rb
|
70
85
|
- lib/stub_factory/version.rb
|
71
86
|
- spec/factories/template_test.rb
|
87
|
+
- spec/factories/wrong_test.rb
|
72
88
|
- spec/lib/stub_factory_spec.rb
|
73
|
-
- spec/
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/support/helpers/stub_helper_test.rb
|
91
|
+
- spec/support/helpers/wrong_helper_test.rb
|
74
92
|
- stub_factory.gemspec
|
75
93
|
homepage: ''
|
76
94
|
licenses:
|
@@ -98,6 +116,8 @@ specification_version: 4
|
|
98
116
|
summary: Simple StubFactory for rspec, that can help with tightly coupled code
|
99
117
|
test_files:
|
100
118
|
- spec/factories/template_test.rb
|
119
|
+
- spec/factories/wrong_test.rb
|
101
120
|
- spec/lib/stub_factory_spec.rb
|
102
|
-
- spec/
|
103
|
-
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/support/helpers/stub_helper_test.rb
|
123
|
+
- spec/support/helpers/wrong_helper_test.rb
|