sham 1.1.0 → 1.2.0
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 +7 -0
- data/.travis.yml +8 -3
- data/CHANGES.markdown +6 -0
- data/Gemfile +0 -2
- data/README.markdown +19 -0
- data/lib/sham.rb +1 -0
- data/lib/sham/config/assign.rb +3 -11
- data/lib/sham/config/attributes.rb +3 -11
- data/lib/sham/config/base.rb +7 -8
- data/lib/sham/config/hash_options.rb +17 -0
- data/lib/sham/lazy.rb +11 -0
- data/lib/sham/version.rb +1 -1
- data/sham.gemspec +1 -0
- data/spec/lib/sham/base_spec.rb +2 -2
- data/spec/lib/sham/config/assign_spec.rb +2 -2
- data/spec/lib/sham/config/attributes_spec.rb +1 -1
- data/spec/lib/sham/config/no_args_spec.rb +1 -1
- data/spec/lib/sham/config/parameters_spec.rb +2 -2
- data/spec/lib/sham/config_spec.rb +26 -3
- data/spec/lib/sham/lazy_spec.rb +7 -0
- data/spec/lib/sham/nested_spec.rb +2 -2
- metadata +32 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50cf581e1b4b693c14936b60f01fa2d0f3d51664
|
4
|
+
data.tar.gz: a12752f43dd59710089327dd7d481215fac631df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a00f590d9b3ccae87ef6cbd8966ebd958cff872d5587a414ea3ec044538bfa56ffb138e291c214ed80fcedf8dacc2203860638cefe2c5338cb878a3ef22bf76c
|
7
|
+
data.tar.gz: 6b02be8c8a28ccb1b03a36a75ff283671046453525c60478db7e605f4bf95c2ea932fec2ff9670bd7a934843fdf1aa3477068eb03ea8848979920d283737a548
|
data/.travis.yml
CHANGED
data/CHANGES.markdown
CHANGED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -200,6 +200,23 @@ during initialization:
|
|
200
200
|
LineItem.sham!
|
201
201
|
LineItem.sham!(:item => Item.sham!(:weight => 100))
|
202
202
|
|
203
|
+
## Lazy Shams
|
204
|
+
|
205
|
+
A more general form of Nested Sham is the Lazy Sham. Lazy Shams only evaluate
|
206
|
+
their blocks if they are not overwritten.
|
207
|
+
|
208
|
+
# sham/line_item_sham.rb
|
209
|
+
Sham.config(LineItem) do |c|
|
210
|
+
c.attributes do
|
211
|
+
{ :item_id => Sham::Lazy.new { Item.sham!.id } }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
The lazy shams will automatically be evaluated and can also be overwritten
|
216
|
+
during initialization:
|
217
|
+
|
218
|
+
LineItem.sham!
|
219
|
+
LineItem.sham!(:item_id => Item.sham!(:weight => 100).id)
|
203
220
|
|
204
221
|
## Sham Inheritance
|
205
222
|
|
@@ -239,3 +256,5 @@ with Spork. If you take this approach it's important to remove the call to
|
|
239
256
|
`Sham::Config.activate!` from your `test.rb` file.
|
240
257
|
|
241
258
|
## Build Status [](http://travis-ci.org/panthomakos/sham)
|
259
|
+
|
260
|
+
## Code Quality [](https://codeclimate.com/github/panthomakos/sham)
|
data/lib/sham.rb
CHANGED
data/lib/sham/config/assign.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'sham/config/base'
|
2
|
-
require 'sham/
|
2
|
+
require 'sham/config/hash_options'
|
3
3
|
|
4
4
|
module Sham
|
5
5
|
class Config
|
6
6
|
class Assign < Base
|
7
|
+
include HashOptions
|
8
|
+
|
7
9
|
def initialize(config)
|
8
10
|
@config = config
|
9
11
|
end
|
@@ -22,16 +24,6 @@ module Sham
|
|
22
24
|
object
|
23
25
|
end
|
24
26
|
|
25
|
-
def options(*args)
|
26
|
-
@options = ::Sham::Util.extract_options!(args)
|
27
|
-
|
28
|
-
@config.call.each do |key, value|
|
29
|
-
@options[key] = parse!(value) unless @options.has_key?(key)
|
30
|
-
end
|
31
|
-
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
27
|
def args
|
36
28
|
[]
|
37
29
|
end
|
@@ -1,23 +1,15 @@
|
|
1
1
|
require 'sham/config/base'
|
2
|
-
require 'sham/
|
2
|
+
require 'sham/config/hash_options'
|
3
3
|
|
4
4
|
module Sham
|
5
5
|
class Config
|
6
6
|
class Attributes < Base
|
7
|
+
include HashOptions
|
8
|
+
|
7
9
|
def initialize(config)
|
8
10
|
@config = config
|
9
11
|
end
|
10
12
|
|
11
|
-
def options(*args)
|
12
|
-
@options = ::Sham::Util.extract_options!(args)
|
13
|
-
|
14
|
-
@config.call.each do |key, value|
|
15
|
-
@options[key] = parse!(value) unless @options.has_key?(key)
|
16
|
-
end
|
17
|
-
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
13
|
def args
|
22
14
|
[@options]
|
23
15
|
end
|
data/lib/sham/config/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sham/nested'
|
2
|
+
require 'sham/lazy'
|
2
3
|
|
3
4
|
module Sham
|
4
5
|
class Config
|
@@ -20,14 +21,12 @@ module Sham
|
|
20
21
|
private
|
21
22
|
|
22
23
|
def parse! value
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
else
|
30
|
-
value
|
24
|
+
case value
|
25
|
+
when Array then value.map{ |k| parse!(k) }
|
26
|
+
when Hash then value.map{ |k,v| [k, parse!(v)] }.to_h
|
27
|
+
when Sham::Nested then value.sham!
|
28
|
+
when Sham::Lazy then value.sham!
|
29
|
+
else value
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'sham/util'
|
2
|
+
|
3
|
+
module Sham
|
4
|
+
class Config
|
5
|
+
module HashOptions
|
6
|
+
def options(*args)
|
7
|
+
@options = ::Sham::Util.extract_options!(args)
|
8
|
+
|
9
|
+
@config.call.each do |key, value|
|
10
|
+
@options[key] = parse!(value) unless @options.has_key?(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sham/lazy.rb
ADDED
data/lib/sham/version.rb
CHANGED
data/sham.gemspec
CHANGED
data/spec/lib/sham/base_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'sham/base'
|
2
2
|
|
3
3
|
describe Sham::Base do
|
4
|
-
let(:klass){
|
4
|
+
let(:klass){ double }
|
5
5
|
|
6
6
|
it 'should call sham! on the class' do
|
7
7
|
klass.should_receive(:sham!)
|
@@ -9,7 +9,7 @@ describe Sham::Base do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should pass sham options' do
|
12
|
-
options =
|
12
|
+
options = double
|
13
13
|
klass.should_receive(:sham!).with(options)
|
14
14
|
described_class.new(klass, options).sham!
|
15
15
|
end
|
@@ -6,11 +6,11 @@ describe Sham::Config::Assign do
|
|
6
6
|
class AssignTester; end
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:id){
|
9
|
+
let(:id){ double }
|
10
10
|
let(:options){ { :id => id } }
|
11
11
|
let(:subject){ described_class.new(lambda{ options }) }
|
12
12
|
let(:config){ subject.object(AssignTester) }
|
13
|
-
let(:instance){
|
13
|
+
let(:instance){ double.as_null_object }
|
14
14
|
|
15
15
|
before{ AssignTester.stub(:new){ instance } }
|
16
16
|
|
@@ -13,8 +13,8 @@ describe Sham::Config::Parameters do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:first){
|
17
|
-
let(:last){
|
16
|
+
let(:first){ double }
|
17
|
+
let(:last){ double }
|
18
18
|
let(:params){ [first, last] }
|
19
19
|
let(:subject){ described_class.new(lambda{ params }) }
|
20
20
|
let(:config){ subject.object(ParamTester) }
|
@@ -144,7 +144,30 @@ describe Sham::Config do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'prefers passed options' do
|
147
|
-
other_child =
|
147
|
+
other_child = double
|
148
|
+
parent.should_receive(:create).with({ :child => other_child })
|
149
|
+
parent.sham!(:child => other_child)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'lazy shams' do
|
154
|
+
before do
|
155
|
+
parent.stub(:create)
|
156
|
+
|
157
|
+
Sham.config(parent) do |c|
|
158
|
+
c.attributes do
|
159
|
+
{ :child => Sham::Lazy.new { child } }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'evaluates the block' do
|
165
|
+
parent.should_receive(:create).with({ :child => child })
|
166
|
+
parent.sham!
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'prefers passed options' do
|
170
|
+
other_child = double
|
148
171
|
parent.should_receive(:create).with({ :child => other_child })
|
149
172
|
parent.sham!(:child => other_child)
|
150
173
|
end
|
@@ -156,7 +179,7 @@ describe Sham::Config do
|
|
156
179
|
c.assign{ { :first => 'first' } }
|
157
180
|
end
|
158
181
|
|
159
|
-
instance =
|
182
|
+
instance = double
|
160
183
|
parent.stub(:new){ instance }
|
161
184
|
instance.should_receive(:public_send).with('first=', 'first')
|
162
185
|
parent.sham!.should == instance
|
@@ -180,7 +203,7 @@ describe Sham::Config do
|
|
180
203
|
|
181
204
|
it 'configures no arg shams' do
|
182
205
|
Sham.config(parent){ |c| c.no_args }
|
183
|
-
parent.should_receive(:new).with()
|
206
|
+
parent.should_receive(:new).with(no_args)
|
184
207
|
parent.sham!
|
185
208
|
end
|
186
209
|
|
@@ -2,10 +2,10 @@ require 'sham/nested'
|
|
2
2
|
|
3
3
|
describe Sham::Nested do
|
4
4
|
it 'is a sham base' do
|
5
|
-
Sham::Nested.new(
|
5
|
+
expect(Sham::Nested.new(double).is_a?(Sham::Base)).to be(true)
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'makes a sham base a sham nested' do
|
9
|
-
Sham::Base.new(
|
9
|
+
expect(Sham::Base.new(double).is_a?(Sham::Nested)).to be(true)
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Pan Thomakos
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
description: Lightweight flexible factories for Ruby and Rails testing.
|
@@ -36,9 +47,9 @@ extra_rdoc_files:
|
|
36
47
|
- README.markdown
|
37
48
|
- License.txt
|
38
49
|
files:
|
39
|
-
- .document
|
40
|
-
- .gitignore
|
41
|
-
- .travis.yml
|
50
|
+
- ".document"
|
51
|
+
- ".gitignore"
|
52
|
+
- ".travis.yml"
|
42
53
|
- CHANGES.markdown
|
43
54
|
- Gemfile
|
44
55
|
- License.txt
|
@@ -51,9 +62,11 @@ files:
|
|
51
62
|
- lib/sham/config/attributes.rb
|
52
63
|
- lib/sham/config/base.rb
|
53
64
|
- lib/sham/config/empty.rb
|
65
|
+
- lib/sham/config/hash_options.rb
|
54
66
|
- lib/sham/config/no_args.rb
|
55
67
|
- lib/sham/config/parameters.rb
|
56
68
|
- lib/sham/data.rb
|
69
|
+
- lib/sham/lazy.rb
|
57
70
|
- lib/sham/nested.rb
|
58
71
|
- lib/sham/shammable.rb
|
59
72
|
- lib/sham/util.rb
|
@@ -67,34 +80,34 @@ files:
|
|
67
80
|
- spec/lib/sham/config/parameters_spec.rb
|
68
81
|
- spec/lib/sham/config_spec.rb
|
69
82
|
- spec/lib/sham/data_spec.rb
|
83
|
+
- spec/lib/sham/lazy_spec.rb
|
70
84
|
- spec/lib/sham/nested_spec.rb
|
71
85
|
- spec/lib/sham/util_spec.rb
|
72
86
|
- spec/root/sham/employee.rb
|
73
87
|
homepage: http://github.com/panthomakos/sham
|
74
88
|
licenses: []
|
89
|
+
metadata: {}
|
75
90
|
post_install_message:
|
76
91
|
rdoc_options:
|
77
|
-
- --charset=UTF-8
|
92
|
+
- "--charset=UTF-8"
|
78
93
|
require_paths:
|
79
94
|
- lib
|
80
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
96
|
requirements:
|
83
|
-
- -
|
97
|
+
- - ">="
|
84
98
|
- !ruby/object:Gem::Version
|
85
99
|
version: '0'
|
86
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
101
|
requirements:
|
89
|
-
- -
|
102
|
+
- - ">="
|
90
103
|
- !ruby/object:Gem::Version
|
91
104
|
version: '0'
|
92
105
|
requirements: []
|
93
106
|
rubyforge_project: sham
|
94
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.5.1
|
95
108
|
signing_key:
|
96
|
-
specification_version:
|
97
|
-
summary: sham-1.
|
109
|
+
specification_version: 4
|
110
|
+
summary: sham-1.2.0
|
98
111
|
test_files:
|
99
112
|
- spec/lib/sham/base_spec.rb
|
100
113
|
- spec/lib/sham/config/assign_spec.rb
|
@@ -104,7 +117,7 @@ test_files:
|
|
104
117
|
- spec/lib/sham/config/parameters_spec.rb
|
105
118
|
- spec/lib/sham/config_spec.rb
|
106
119
|
- spec/lib/sham/data_spec.rb
|
120
|
+
- spec/lib/sham/lazy_spec.rb
|
107
121
|
- spec/lib/sham/nested_spec.rb
|
108
122
|
- spec/lib/sham/util_spec.rb
|
109
123
|
- spec/root/sham/employee.rb
|
110
|
-
has_rdoc:
|