cucumber_factory 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,490 +1,502 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'steps provided by cucumber_factory' do
3
+ TRANSFORMS_SUPPORTED = Cucumber::VERSION < '3'
4
4
 
5
+ describe 'steps provided by cucumber_factory' do
5
6
  before(:each) do
6
7
  prepare_cucumber_example
7
8
  end
8
9
 
9
- TRANSFORMS_SUPPORTED = Cucumber::VERSION < '3'
10
-
11
- it "should create ActiveRecord models by calling #new and #save!" do
12
- movie = Movie.new
13
- Movie.should_receive(:new).with(no_args).and_return(movie)
14
- movie.should_receive(:save!)
15
- invoke_cucumber_step("there is a movie")
16
- end
17
-
18
- it "should create models that have a machinist blueprint by calling #make" do
19
- MachinistModel.should_receive(:make).with({ :attribute => "foo"})
20
- invoke_cucumber_step('there is a machinist model with the attribute "foo"')
21
- end
22
-
23
- it "should be able to step_match machinist blueprint variants" do
24
- MachinistModel.should_receive(:make).with(:variant, { :attribute => "foo"})
25
- invoke_cucumber_step('there is a machinist model (variant) with the attribute "foo"')
26
- end
27
-
28
- it "should be able to step_match machinist blueprint variants containing spaces or uppercase characters in prose" do
29
- MachinistModel.should_receive(:make).with(:variant_mark_two, { :attribute => "foo"})
30
- invoke_cucumber_step('there is a machinist model (Variant Mark Two) with the attribute "foo"')
31
- end
32
-
33
- it "should create models that have a factory_bot factory by calling #FactoryBot.create(:model_name)" do
34
- FactoryBot.stub_factories :job_offer => JobOffer
35
- FactoryBot.should_receive(:create).with(:job_offer, { :title => "Awesome job" })
36
- invoke_cucumber_step('there is a job offer with the title "Awesome job"')
37
- end
38
-
39
- it "should create model variants that have a factory_bot factory by calling #FactoryBot.create(:variant)" do
40
- FactoryBot.stub_factories :tempting_job_offer => JobOffer
41
- FactoryBot.should_receive(:create).with(:tempting_job_offer, { :title => "Awesomafiablyfantasmic job" })
42
- invoke_cucumber_step('there is a job offer (tempting job offer) with the title "Awesomafiablyfantasmic job"')
43
- end
44
-
45
- it "should create model variants that have a factory_bot trait by calling #FactoryBot.create(:factory, :trait1, :trait2)" do
46
- FactoryBot.stub_factories :tempting_job_offer => JobOffer
47
- FactoryBot.should_receive(:create).with(:tempting_job_offer, :risky, :lucrative, { :title => "Awesomafiablyfantasmic job" })
48
- invoke_cucumber_step('there is a tempting job offer (risky, lucrative) with the title "Awesomafiablyfantasmic job"')
49
- end
10
+ context 'FactoryBot' do
11
+ it "should create ActiveRecord models by calling #new and #save!" do
12
+ movie = Movie.new
13
+ Movie.should_receive(:new).with(no_args).and_return(movie)
14
+ movie.should_receive(:save!)
15
+ invoke_cucumber_step("there is a movie")
16
+ end
50
17
 
51
- it "should create model variants that have a factory_bot factory by using the model name as a factory name" do
52
- FactoryBot.stub_factories :tempting_job_offer => JobOffer
53
- FactoryBot.should_receive(:create).with(:tempting_job_offer, { :title => "Awesomafiablyfantasmic job" })
54
- invoke_cucumber_step('there is a tempting job offer with the title "Awesomafiablyfantasmic job"')
55
- end
18
+ it "should create models that have a factory_bot factory by calling #FactoryBot.create(:model_name)" do
19
+ FactoryBot.should_receive(:create).with(:job_offer, { :title => "Awesome job" })
20
+ invoke_cucumber_step('there is a job offer with the title "Awesome job"')
21
+ end
56
22
 
57
- it "should instantiate plain ruby classes by calling #new" do
58
- PlainRubyClass.should_receive(:new).with({})
59
- invoke_cucumber_step("there is a plain ruby class")
60
- end
23
+ it "should create model variants that have a factory_bot factory by calling #FactoryBot.create(:variant)" do
24
+ FactoryBot.should_receive(:create).with(:job_offer, :tempting_job_offer, { :title => "Awesomafiablyfantasmic job" })
25
+ invoke_cucumber_step('there is a job offer (tempting job offer) with the title "Awesomafiablyfantasmic job"')
26
+ end
61
27
 
62
- it "should instantiate classes with multiple words in their name" do
63
- JobOffer.should_receive(:new).with({})
64
- invoke_cucumber_step("there is a job offer")
65
- end
28
+ it "should create model variants that have a factory_bot trait by calling #FactoryBot.create(:factory, :trait1, :trait2)" do
29
+ FactoryBot.should_receive(:create).with(:job_offer, :risky, :lucrative, { :title => "Awesomafiablyfantasmic job" })
30
+ invoke_cucumber_step('there is a job offer (risky, lucrative) with the title "Awesomafiablyfantasmic job"')
31
+ end
66
32
 
67
- it "should instantiate classes with uppercase characters in their name" do
68
- user = User.new
69
- User.should_receive(:new).and_return(user)
70
- invoke_cucumber_step("there is a User")
71
- end
33
+ it "should create model variants that have a factory_bot factory by using the model name as a factory name" do
34
+ FactoryBot.should_receive(:create).with(:job_offer, { :title => "Awesomafiablyfantasmic job" })
35
+ invoke_cucumber_step('there is a job offer with the title "Awesomafiablyfantasmic job"')
36
+ end
72
37
 
73
- it "should instantiate namespaced classes" do
74
- actor = People::Actor.new
75
- People::Actor.should_receive(:new).and_return(actor)
76
- invoke_cucumber_step("there is a people/actor")
77
- end
38
+ it "should instantiate classes with multiple words in their name" do
39
+ job_offer = JobOffer.new
40
+ JobOffer.should_receive(:new).with(no_args).and_return(job_offer)
41
+ invoke_cucumber_step("there is a job offer")
42
+ end
78
43
 
79
- it "should allow either 'a' or 'an' for the article" do
80
- Opera.should_receive(:new).with({})
81
- invoke_cucumber_step("there is an opera")
82
- end
44
+ it "should instantiate classes with uppercase characters in their name" do
45
+ user = User.new
46
+ User.should_receive(:new).and_return(user)
47
+ invoke_cucumber_step("there is a User")
48
+ end
83
49
 
84
- it "should create records with attributes" do
85
- movie = Movie.new
86
- Movie.stub(:new => movie)
87
- invoke_cucumber_step('there is a movie with the title "Sunshine" and the year "2007"')
88
- movie.title.should == "Sunshine"
89
- movie.year.should == 2007
90
- end
50
+ it "should allow either 'a' or 'an' for the article" do
51
+ opera = Opera.new
52
+ Opera.should_receive(:new).with(no_args).and_return(opera)
53
+ invoke_cucumber_step("there is an opera")
54
+ end
91
55
 
92
- it "should allow to join attribute lists with 'and's, commas and 'but's" do
93
- movie = Movie.new
94
- Movie.stub(:new => movie)
95
- invoke_cucumber_step('there is a movie with the title "Sunshine", the year "2007" but with the box office result "32000000"')
96
- movie.title.should == "Sunshine"
97
- movie.year.should == 2007
98
- movie.box_office_result.should == 32000000
99
- end
56
+ it "should create records with attributes" do
57
+ movie = Movie.new
58
+ Movie.stub(:new => movie)
59
+ invoke_cucumber_step('there is a movie with the title "Sunshine" and the year "2007"')
60
+ movie.title.should == "Sunshine"
61
+ movie.year.should == 2007
62
+ end
100
63
 
101
- if TRANSFORMS_SUPPORTED
102
- it "should apply Cucumber transforms to attribute values" do
64
+ it "should allow to join attribute lists with 'and's, commas and 'but's" do
103
65
  movie = Movie.new
104
66
  Movie.stub(:new => movie)
105
- @main.instance_eval do
106
- Transform /^(value)$/ do |value|
107
- 'transformed value'
67
+ invoke_cucumber_step('there is a movie with the title "Sunshine", the year "2007" but with the box office result "32000000"')
68
+ movie.title.should == "Sunshine"
69
+ movie.year.should == 2007
70
+ movie.box_office_result.should == 32000000
71
+ end
72
+
73
+ if TRANSFORMS_SUPPORTED
74
+ it "should apply Cucumber transforms to attribute values" do
75
+ movie = Movie.new
76
+ Movie.stub(:new => movie)
77
+ @main.instance_eval do
78
+ Transform /^(value)$/ do |value|
79
+ 'transformed value'
80
+ end
108
81
  end
82
+ invoke_cucumber_step('there is a movie with the title "value"')
83
+ movie.title.should == "transformed value"
109
84
  end
110
- invoke_cucumber_step('there is a movie with the title "value"')
111
- movie.title.should == "transformed value"
112
85
  end
113
- end
114
86
 
115
- it "should create records with attributes containing spaces" do
116
- movie = Movie.new
117
- Movie.stub(:new => movie)
118
- invoke_cucumber_step('there is a movie with the box office result "99999999"')
119
- movie.box_office_result.should == 99999999
120
- end
87
+ it "should create records with attributes containing spaces" do
88
+ movie = Movie.new
89
+ Movie.stub(:new => movie)
90
+ invoke_cucumber_step('there is a movie with the box office result "99999999"')
91
+ movie.box_office_result.should == 99999999
92
+ end
121
93
 
122
- it "should create records with attributes containing uppercase characters" do
123
- user = User.new
124
- User.stub(:new => user)
125
- invoke_cucumber_step('there is a User with the Name "Susanne"')
126
- user.name.should == "Susanne"
127
- end
94
+ it "should create records with attributes containing uppercase characters" do
95
+ user = User.new
96
+ User.stub(:new => user)
97
+ invoke_cucumber_step('there is a User with the Name "Susanne"')
98
+ user.name.should == "Susanne"
99
+ end
128
100
 
129
- it "should override attr_accessible protection" do
130
- invoke_cucumber_step('there is a payment with the amount "120" and the comment "Thanks for lending"')
131
- payment = Payment.last
132
- payment.amount.should == 120
133
- payment.comment.should == 'Thanks for lending'
134
- end
101
+ it "should override attr_accessible protection" do
102
+ invoke_cucumber_step('there is a payment with the amount "120" and the comment "Thanks for lending"')
103
+ payment = Payment.last
104
+ payment.amount.should == 120
105
+ payment.comment.should == 'Thanks for lending'
106
+ end
135
107
 
136
- it "should allow to set an explicit primary key" do
137
- invoke_cucumber_step('there is a payment with the ID 2')
138
- payment = Payment.last
139
- payment.id.should == 2
140
- end
108
+ it "should allow to set an explicit primary key" do
109
+ invoke_cucumber_step('there is a payment with the ID 2')
110
+ payment = Payment.last
111
+ payment.id.should == 2
112
+ end
141
113
 
142
- it "should allow to name records and set a belongs_to association to that record by refering to that name" do
143
- invoke_cucumber_step('"Some Prequel" is a movie with the title "Before Sunrise"')
144
- invoke_cucumber_step('there is a movie with the title "Limitless"')
145
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
146
- movie = Movie.find_by_title!('Before Sunset')
147
- prequel = Movie.find_by_title!('Before Sunrise')
148
- movie.prequel.should == prequel
149
- end
114
+ it "should allow to name records and set a belongs_to association to that record by refering to that name" do
115
+ invoke_cucumber_step('"Some Prequel" is a movie with the title "Before Sunrise"')
116
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
117
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
118
+ movie = Movie.find_by_title!('Before Sunset')
119
+ prequel = Movie.find_by_title!('Before Sunrise')
120
+ movie.prequel.should == prequel
121
+ end
150
122
 
151
- it "should allow to set a belongs_to association to a previously created record by refering to any string attribute of that record" do
152
- invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
153
- invoke_cucumber_step('there is a movie with the title "Limitless"')
154
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Before Sunrise"')
155
- movie = Movie.find_by_title!('Before Sunset')
156
- prequel = Movie.find_by_title!('Before Sunrise')
157
- movie.prequel.should == prequel
158
- end
123
+ it "should allow to set a belongs_to association to a previously created record by refering to any string attribute of that record" do
124
+ invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
125
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
126
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Before Sunrise"')
127
+ movie = Movie.find_by_title!('Before Sunset')
128
+ prequel = Movie.find_by_title!('Before Sunrise')
129
+ movie.prequel.should == prequel
130
+ end
159
131
 
160
- it "should allow to set a belongs_to association to a previously created record by refering to their explicitely set primary keys" do
161
- invoke_cucumber_step('there is a movie with the ID 123')
162
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel 123')
163
- movie = Movie.find_by_title!('Before Sunset')
164
- prequel = Movie.find(123)
165
- movie.prequel.should == prequel
166
- end
132
+ it "should allow to set a belongs_to association to a previously created record by refering to their explicitely set primary keys" do
133
+ invoke_cucumber_step('there is a movie with the ID 123')
134
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel 123')
135
+ movie = Movie.find_by_title!('Before Sunset')
136
+ prequel = Movie.find(123)
137
+ movie.prequel.should == prequel
138
+ end
167
139
 
168
- it "should allow to set a belongs_to association to a previously created record by saying 'above'" do
169
- invoke_cucumber_step('there is a user with the name "Jane"')
170
- invoke_cucumber_step('there is a user with the name "John"')
171
- invoke_cucumber_step('there is a movie with the title "Limitless"')
172
- invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
173
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
174
- before_sunset = Movie.find_by_title!("Before Sunset")
175
- before_sunset.prequel.title.should == "Before Sunrise"
176
- before_sunset.reviewer.name.should == "John"
177
- end
140
+ it "should allow to set a belongs_to association to a previously created record by saying 'above'" do
141
+ invoke_cucumber_step('there is a user with the name "Jane"')
142
+ invoke_cucumber_step('there is a user with the name "John"')
143
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
144
+ invoke_cucumber_step('there is a movie with the title "Before Sunrise"')
145
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
146
+ before_sunset = Movie.find_by_title!("Before Sunset")
147
+ before_sunset.prequel.title.should == "Before Sunrise"
148
+ before_sunset.reviewer.name.should == "John"
149
+ end
178
150
 
179
- if TRANSFORMS_SUPPORTED
180
- it "should fallback to using transforms when no named record is found" do
181
- user = User.create!(:name => 'Me')
182
- @main.instance_eval do
183
- Transform(/^(me)$/) do |value|
184
- user
151
+ if TRANSFORMS_SUPPORTED
152
+ it "should fallback to using transforms when no named record is found" do
153
+ user = User.create!(:name => 'Me')
154
+ @main.instance_eval do
155
+ Transform(/^(me)$/) do |value|
156
+ user
157
+ end
185
158
  end
159
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer "me"')
160
+ before_sunset = Movie.find_by_title!("Before Sunset")
161
+ before_sunset.reviewer.should == user
186
162
  end
187
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer "me"')
163
+ end
164
+
165
+ it "should give created_at precedence over id when saying 'above' if the primary key is not numeric" do
166
+ invoke_cucumber_step('there is a uuid user with the name "Jane" and the id "jane"')
167
+ invoke_cucumber_step('there is a uuid user with the name "John" and the id "john"')
168
+ UuidUser.find_by_name("John").update_attributes!(:created_at => 1.day.ago)
169
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the uuid reviewer above')
188
170
  before_sunset = Movie.find_by_title!("Before Sunset")
189
- before_sunset.reviewer.should == user
171
+ before_sunset.uuid_reviewer.name.should == "Jane"
190
172
  end
191
- end
192
173
 
193
- it "should give created_at precedence over id when saying 'above' if the primary key is not numeric" do
194
- invoke_cucumber_step('there is a uuid user with the name "Jane" and the id "jane"')
195
- invoke_cucumber_step('there is a uuid user with the name "John" and the id "john"')
196
- UuidUser.find_by_name("John").update_attributes!(:created_at => 1.day.ago)
197
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the uuid reviewer above')
198
- before_sunset = Movie.find_by_title!("Before Sunset")
199
- before_sunset.uuid_reviewer.name.should == "Jane"
200
- end
174
+ it "should ignore created_at if the primary key is numeric" do
175
+ invoke_cucumber_step('there is a user with the name "Jane"')
176
+ invoke_cucumber_step('there is a user with the name "John"')
177
+ User.find_by_name("John").update_attributes!(:created_at => 1.day.ago)
178
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above')
179
+ before_sunset = Movie.find_by_title!("Before Sunset")
180
+ before_sunset.reviewer.name.should == "John"
181
+ end
201
182
 
202
- it "should ignore created_at if the primary key is numeric" do
203
- invoke_cucumber_step('there is a user with the name "Jane"')
204
- invoke_cucumber_step('there is a user with the name "John"')
205
- User.find_by_name("John").update_attributes!(:created_at => 1.day.ago)
206
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above')
207
- before_sunset = Movie.find_by_title!("Before Sunset")
208
- before_sunset.reviewer.name.should == "John"
209
- end
183
+ it "should raise a proper error if there is no previous record when saying 'above'" do
184
+ lambda do
185
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
186
+ end.should raise_error(/There is no last reviewer/i)
187
+ end
210
188
 
211
- it "should raise a proper error if there is no previous record when saying 'above'" do
212
- lambda do
213
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer above and the prequel above')
214
- end.should raise_error(/There is no last reviewer/i)
215
- end
189
+ it "should reload an object assigned to a belongs_to before assigning" do
190
+ invoke_cucumber_step('"Jane" is a user who is deleted')
191
+ User.last.update_attributes(:deleted => false)
192
+ proc { invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer "Jane"') }.should_not raise_error
193
+ end
216
194
 
217
- it "should reload an object assigned to a belongs_to before assigning" do
218
- invoke_cucumber_step('"Jane" is a user who is deleted')
219
- User.last.update_attributes(:deleted => false)
220
- proc { invoke_cucumber_step('there is a movie with the title "Before Sunset" and the reviewer "Jane"') }.should_not raise_error
221
- end
195
+ it "should allow to set positive boolean attributes with 'who' after the attribute list" do
196
+ user = User.new
197
+ User.stub(:new => user)
198
+ invoke_cucumber_step('there is a user with the name "Jane" who is deleted')
199
+ user.name.should == "Jane"
200
+ user.deleted.should == true
201
+ end
222
202
 
223
- it "should allow to set positive boolean attributes with 'who' after the attribute list" do
224
- user = User.new
225
- User.stub(:new => user)
226
- invoke_cucumber_step('there is a user with the name "Jane" who is deleted')
227
- user.name.should == "Jane"
228
- user.deleted.should == true
229
- end
203
+ it "should allow to set positive boolean attributes with 'which' after the attribute list" do
204
+ user = User.new
205
+ User.stub(:new => user)
206
+ invoke_cucumber_step('there is a user with the name "Jane" which is deleted')
207
+ user.name.should == "Jane"
208
+ user.deleted.should == true
209
+ end
230
210
 
231
- it "should allow to set positive boolean attributes with 'which' after the attribute list" do
232
- user = User.new
233
- User.stub(:new => user)
234
- invoke_cucumber_step('there is a user with the name "Jane" which is deleted')
235
- user.name.should == "Jane"
236
- user.deleted.should == true
237
- end
211
+ it "should allow to set positive boolean attributes with 'that' after the attribute list" do
212
+ user = User.new
213
+ User.stub(:new => user)
214
+ invoke_cucumber_step('there is a user with the name "Jane" that is deleted')
215
+ user.name.should == "Jane"
216
+ user.deleted.should == true
217
+ end
238
218
 
239
- it "should allow to set positive boolean attributes with 'that' after the attribute list" do
240
- user = User.new
241
- User.stub(:new => user)
242
- invoke_cucumber_step('there is a user with the name "Jane" that is deleted')
243
- user.name.should == "Jane"
244
- user.deleted.should == true
245
- end
219
+ it "should allow to set boolean attributes without regular attributes preceding them" do
220
+ user = User.new
221
+ User.stub(:new => user)
222
+ invoke_cucumber_step('there is a user who is deleted')
223
+ user.deleted.should == true
224
+ end
246
225
 
247
- it "should allow to set boolean attributes without regular attributes preceding them" do
248
- user = User.new
249
- User.stub(:new => user)
250
- invoke_cucumber_step('there is a user who is deleted')
251
- user.deleted.should == true
252
- end
226
+ it "should allow to set negative boolean attribute" do
227
+ user = User.new
228
+ User.stub(:new => user)
229
+ invoke_cucumber_step('there is a user who is not deleted')
230
+ user.deleted.should == false
231
+ end
253
232
 
254
- it "should allow to set negative boolean attribute" do
255
- user = User.new
256
- User.stub(:new => user)
257
- invoke_cucumber_step('there is a user who is not deleted')
258
- user.deleted.should == false
259
- end
233
+ it "should allow to set multiple boolean attributes" do
234
+ user = User.new
235
+ User.stub(:new => user)
236
+ invoke_cucumber_step('there is a user who is locked and not deleted and subscribed')
237
+ user.locked.should == true
238
+ user.deleted.should == false
239
+ user.subscribed.should == true
240
+ end
260
241
 
261
- it "should allow to set multiple boolean attributes" do
262
- user = User.new
263
- User.stub(:new => user)
264
- invoke_cucumber_step('there is a user who is locked and not deleted and subscribed')
265
- user.locked.should == true
266
- user.deleted.should == false
267
- user.subscribed.should == true
268
- end
242
+ it "should allow to set boolean attributes that are named from multiple words" do
243
+ user = User.new
244
+ User.stub(:new => user)
245
+ invoke_cucumber_step('there is a user who is locked and not scared and scared by spiders and deleted')
246
+ user.locked.should == true
247
+ user.scared.should == false
248
+ user.scared_by_spiders.should == true
249
+ user.deleted.should == true
250
+ end
269
251
 
270
- it "should allow to set boolean attributes that are named from multiple words" do
271
- user = User.new
272
- User.stub(:new => user)
273
- invoke_cucumber_step('there is a user who is locked and not scared and scared by spiders and deleted')
274
- user.locked.should == true
275
- user.scared.should == false
276
- user.scared_by_spiders.should == true
277
- user.deleted.should == true
278
- end
252
+ it "should allow to join boolean attribute lists with 'and's, commas and 'but's" do
253
+ user = User.new
254
+ User.stub(:new => user)
255
+ invoke_cucumber_step('there is a user who is locked, scared, but scared by spiders and deleted')
256
+ user.locked.should == true
257
+ user.scared.should == true
258
+ user.scared_by_spiders.should == true
259
+ user.deleted.should == true
260
+ end
279
261
 
280
- it "should allow to join boolean attribute lists with 'and's, commas and 'but's" do
281
- user = User.new
282
- User.stub(:new => user)
283
- invoke_cucumber_step('there is a user who is locked, scared, but scared by spiders and deleted')
284
- user.locked.should == true
285
- user.scared.should == true
286
- user.scared_by_spiders.should == true
287
- user.deleted.should == true
288
- end
262
+ it "should allow to set a has_many association by refering to multiple named records in square brackets" do
263
+ invoke_cucumber_step('there is a movie with the title "Sunshine"')
264
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
265
+ invoke_cucumber_step('there is a user with the reviewed movies ["Sunshine" and "Limitless"]')
266
+ user = User.last
267
+ reviewed_movie_titles = user.reviewed_movies.map(&:title)
268
+ reviewed_movie_titles.should =~ ['Sunshine', 'Limitless']
269
+ end
289
270
 
290
- it "should allow to set integer attributes without surrounding quotes" do
291
- invoke_cucumber_step('there is a plain Ruby class with the amount 123 and the total 456')
292
- obj = PlainRubyClass.last
293
- obj.attributes[:amount].should == 123
294
- obj.attributes[:total].should == 456
295
- end
271
+ it 'allow associations for transient attributes if they are named after the associated model' do
272
+ invoke_cucumber_step('there is a movie with the title "Sunshine"')
273
+ invoke_cucumber_step('there is a user with the movie "Sunshine"')
274
+ user = User.last
275
+ user.reviewed_movies.count.should == 1
276
+ user.reviewed_movies.first.title.should == 'Sunshine'
277
+ end
296
278
 
297
- it "should allow to set decimal attributes without surrounding quotes" do
298
- invoke_cucumber_step('there is a plain Ruby class with the amount 1.23 and the total 45.6')
299
- obj = PlainRubyClass.last
300
- obj.attributes[:amount].should be_a(BigDecimal)
301
- obj.attributes[:amount].to_s.should == "1.23"
302
- obj.attributes[:total].should be_a(BigDecimal)
303
- obj.attributes[:total].to_s.should == "45.6"
304
- end
279
+ it "should allow to set attributes via doc string" do
280
+ user = User.new
281
+ User.stub(:new => user)
305
282
 
306
- it "should allow set an array of strings with square brackets" do
307
- invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar"] and the list ["bam", "baz"]')
308
- obj = PlainRubyClass.last
309
- obj.attributes[:tags].should == ['foo', 'bar']
310
- obj.attributes[:list].should == ['bam', 'baz']
311
- end
283
+ invoke_cucumber_step('there is a user with these attributes:', <<-DOC_STRING)
284
+ name: Jane
285
+ locked: true
286
+ DOC_STRING
312
287
 
313
- it "should allow set an array of numbers with square brackets" do
314
- invoke_cucumber_step('there is a plain Ruby class with the integers [1, 2] and the decimals [3.4, 4.5]')
315
- obj = PlainRubyClass.last
316
- obj.attributes[:integers].should == [1, 2]
317
- obj.attributes[:decimals].should == [BigDecimal('3.4'), BigDecimal('4.5')]
318
- end
288
+ user.name.should == "Jane"
289
+ user.locked.should == true
290
+ end
319
291
 
320
- it 'should allow to set an empty array' do
321
- invoke_cucumber_step('there is a plain Ruby class with the tags []')
322
- obj = PlainRubyClass.last
323
- obj.attributes[:tags].should == []
324
- end
292
+ it "should allow to set attributes via additional doc string" do
293
+ user = User.new
294
+ User.stub(:new => user)
325
295
 
326
- it 'should allow to separate array values with either a comma or "and"' do
327
- invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar" and "baz"] and the list ["bam", "baz" and "qux"]')
328
- obj = PlainRubyClass.last
329
- obj.attributes[:tags].should == ['foo', 'bar', 'baz']
330
- obj.attributes[:list].should == ['bam', 'baz', 'qux']
331
- end
296
+ invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', <<-DOC_STRING)
297
+ name: Jane
298
+ DOC_STRING
332
299
 
333
- it 'should allow to separate array values with an Oxford comma' do
334
- invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar", and "baz"] and the list ["bam", "baz", and "qux"]')
335
- obj = PlainRubyClass.last
336
- obj.attributes[:tags].should == ['foo', 'bar', 'baz']
337
- obj.attributes[:list].should == ['bam', 'baz', 'qux']
338
- end
300
+ user.name.should == "Jane"
301
+ user.email.should == "test@invalid.com"
302
+ end
339
303
 
340
- it "should allow to set a has_many association by refering to multiple named records in square brackets" do
341
- invoke_cucumber_step('there is a movie with the title "Sunshine"')
342
- invoke_cucumber_step('there is a movie with the title "Limitless"')
343
- invoke_cucumber_step('there is a user with the reviewed movies ["Sunshine" and "Limitless"]')
344
- user = User.last
345
- reviewed_movie_titles = user.reviewed_movies.map(&:title)
346
- reviewed_movie_titles.should =~ ['Sunshine', 'Limitless']
347
- end
304
+ it 'should allow named records when setting attributes via doc string' do
305
+ invoke_cucumber_step('"Some Prequel" is a movie with these attributes:', <<-DOC_STRING)
306
+ title: Before Sunrise
307
+ DOC_STRING
308
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
309
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
310
+ movie = Movie.find_by_title!('Before Sunset')
311
+ prequel = Movie.find_by_title!('Before Sunrise')
312
+ movie.prequel.should == prequel
313
+ end
348
314
 
349
- it "should allow attribute names starting with 'the'" do
350
- PlainRubyClass.should_receive(:new).with({:theme => 'Sci-fi'})
351
- invoke_cucumber_step('there is a plain ruby class with the theme "Sci-fi"')
352
- end
315
+ it "should allow to set attributes via data table" do
316
+ user = User.new
317
+ User.stub(:new => user)
353
318
 
354
- it "should allow attribute names starting with 'and'" do
355
- PlainRubyClass.should_receive(:new).with({:android => 'Paranoid'})
356
- invoke_cucumber_step('there is a plain ruby class with the android "Paranoid"')
357
- end
319
+ invoke_cucumber_step('there is a user with these attributes:', nil, <<-DATA_TABLE)
320
+ | name | Jane |
321
+ | locked | true |
322
+ DATA_TABLE
358
323
 
359
- it "should allow attribute names starting with 'with'" do
360
- PlainRubyClass.should_receive(:new).with({:withdrawal => 'bank_account'})
361
- invoke_cucumber_step('there is a plain ruby class with the withdrawal "bank_account"')
362
- end
324
+ user.name.should == "Jane"
325
+ user.locked.should == true
326
+ end
363
327
 
364
- it "should allow attribute names starting with 'but'" do
365
- PlainRubyClass.should_receive(:new).with({:butt => 'pear-shaped'})
366
- invoke_cucumber_step('there is a plain ruby class with the butt "pear-shaped"')
367
- end
328
+ it "should allow to set attributes via additional data table" do
329
+ user = User.new
330
+ User.stub(:new => user)
368
331
 
369
- it "should allow to set attributes via doc string" do
370
- user = User.new
371
- User.stub(:new => user)
332
+ invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', nil, <<-DATA_TABLE)
333
+ | name | Jane |
334
+ DATA_TABLE
372
335
 
373
- invoke_cucumber_step('there is a user with these attributes:', <<-DOC_STRING)
374
- name: Jane
375
- locked: true
376
- DOC_STRING
336
+ user.name.should == "Jane"
337
+ user.email.should == "test@invalid.com"
338
+ end
377
339
 
378
- user.name.should == "Jane"
379
- user.locked.should == true
340
+ it 'should allow named records when setting attributes via data table' do
341
+ invoke_cucumber_step('"Some Prequel" is a movie with these attributes:', nil, <<-DATA_TABLE)
342
+ | title | Before Sunrise |
343
+ DATA_TABLE
344
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
345
+ invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
346
+ movie = Movie.find_by_title!('Before Sunset')
347
+ prequel = Movie.find_by_title!('Before Sunrise')
348
+ movie.prequel.should == prequel
349
+ end
350
+
351
+ it "should allow mixed single quotes for model names" do
352
+ invoke_cucumber_step("'Some Prequel' is a movie with the title \"Before Sunrise\"")
353
+ invoke_cucumber_step('there is a movie with the title "Limitless"')
354
+ invoke_cucumber_step('there is a movie with the title \'Before Sunset\' and the prequel "Some Prequel"')
355
+ movie = Movie.find_by_title!('Before Sunset')
356
+ prequel = Movie.find_by_title!('Before Sunrise')
357
+ movie.prequel.should == prequel
358
+ end
380
359
  end
381
360
 
382
- it "should allow to set attributes via additional doc string" do
383
- user = User.new
384
- User.stub(:new => user)
361
+ context 'without FactoryBot' do
362
+ before do
363
+ hide_const("FactoryBot")
364
+ end
385
365
 
386
- invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', <<-DOC_STRING)
387
- name: Jane
388
- DOC_STRING
366
+ it "should instantiate plain ruby classes by calling #new" do
367
+ PlainRubyClass.should_receive(:new).with({})
368
+ invoke_cucumber_step("there is a plain ruby class")
369
+ end
389
370
 
390
- user.name.should == "Jane"
391
- user.email.should == "test@invalid.com"
392
- end
371
+ it "should instantiate namespaced classes" do
372
+ actor = People::Actor.new
373
+ People::Actor.should_receive(:new).and_return(actor)
374
+ invoke_cucumber_step("there is a people/actor")
375
+ end
393
376
 
394
- it "should allow to set array attributes via doc string" do
395
- invoke_cucumber_step('there is a plain Ruby class with these attributes:', <<-DOC_STRING)
396
- tags: ["foo", "bar"]
397
- DOC_STRING
377
+ it "should allow to set integer attributes without surrounding quotes" do
378
+ invoke_cucumber_step('there is a plain Ruby class with the amount 123 and the total 456')
379
+ obj = PlainRubyClass.last
380
+ obj.attributes[:amount].should == 123
381
+ obj.attributes[:total].should == 456
382
+ end
398
383
 
399
- obj = PlainRubyClass.last
400
- obj.attributes[:tags].should == ['foo', 'bar']
401
- end
384
+ it "should allow to set decimal attributes without surrounding quotes" do
385
+ invoke_cucumber_step('there is a plain Ruby class with the amount 1.23 and the total 45.6')
386
+ obj = PlainRubyClass.last
387
+ obj.attributes[:amount].should be_a(BigDecimal)
388
+ obj.attributes[:amount].to_s.should == "1.23"
389
+ obj.attributes[:total].should be_a(BigDecimal)
390
+ obj.attributes[:total].to_s.should == "45.6"
391
+ end
402
392
 
403
- it 'should allow named records when setting attributes via doc string' do
404
- invoke_cucumber_step('"Some Prequel" is a movie with these attributes:', <<-DOC_STRING)
405
- title: Before Sunrise
406
- DOC_STRING
407
- invoke_cucumber_step('there is a movie with the title "Limitless"')
408
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
409
- movie = Movie.find_by_title!('Before Sunset')
410
- prequel = Movie.find_by_title!('Before Sunrise')
411
- movie.prequel.should == prequel
412
- end
393
+ it "should allow set an array of strings with square brackets" do
394
+ invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar"] and the list ["bam", "baz"]')
395
+ obj = PlainRubyClass.last
396
+ obj.attributes[:tags].should == ['foo', 'bar']
397
+ obj.attributes[:list].should == ['bam', 'baz']
398
+ end
413
399
 
414
- it "should allow to set attributes via data table" do
415
- user = User.new
416
- User.stub(:new => user)
400
+ it "should allow set an array of numbers with square brackets" do
401
+ invoke_cucumber_step('there is a plain Ruby class with the integers [1, 2] and the decimals [3.4, 4.5]')
402
+ obj = PlainRubyClass.last
403
+ obj.attributes[:integers].should == [1, 2]
404
+ obj.attributes[:decimals].should == [BigDecimal('3.4'), BigDecimal('4.5')]
405
+ end
417
406
 
418
- invoke_cucumber_step('there is a user with these attributes:', nil, <<-DATA_TABLE)
419
- | name | Jane |
420
- | locked | true |
421
- DATA_TABLE
407
+ it 'should allow to set an empty array' do
408
+ invoke_cucumber_step('there is a plain Ruby class with the tags []')
409
+ obj = PlainRubyClass.last
410
+ obj.attributes[:tags].should == []
411
+ end
422
412
 
423
- user.name.should == "Jane"
424
- user.locked.should == true
425
- end
413
+ it 'should allow to separate array values with either a comma or "and"' do
414
+ invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar" and "baz"] and the list ["bam", "baz" and "qux"]')
415
+ obj = PlainRubyClass.last
416
+ obj.attributes[:tags].should == ['foo', 'bar', 'baz']
417
+ obj.attributes[:list].should == ['bam', 'baz', 'qux']
418
+ end
426
419
 
427
- it "should allow to set attributes via additional data table" do
428
- user = User.new
429
- User.stub(:new => user)
420
+ it 'should allow to separate array values with an Oxford comma' do
421
+ invoke_cucumber_step('there is a plain Ruby class with the tags ["foo", "bar", and "baz"] and the list ["bam", "baz", and "qux"]')
422
+ obj = PlainRubyClass.last
423
+ obj.attributes[:tags].should == ['foo', 'bar', 'baz']
424
+ obj.attributes[:list].should == ['bam', 'baz', 'qux']
425
+ end
430
426
 
431
- invoke_cucumber_step('there is a user with the email "test@invalid.com" and these attributes:', nil, <<-DATA_TABLE)
432
- | name | Jane |
433
- DATA_TABLE
427
+ it "should allow attribute names starting with 'the'" do
428
+ PlainRubyClass.should_receive(:new).with({:theme => 'Sci-fi'})
429
+ invoke_cucumber_step('there is a plain ruby class with the theme "Sci-fi"')
430
+ end
434
431
 
435
- user.name.should == "Jane"
436
- user.email.should == "test@invalid.com"
437
- end
432
+ it "should allow attribute names starting with 'and'" do
433
+ PlainRubyClass.should_receive(:new).with({:android => 'Paranoid'})
434
+ invoke_cucumber_step('there is a plain ruby class with the android "Paranoid"')
435
+ end
438
436
 
439
- it "should allow to set array attributes via data table" do
440
- invoke_cucumber_step('there is a plain Ruby class with these attributes:', nil, <<-DATA_TABLE)
437
+ it "should allow attribute names starting with 'with'" do
438
+ PlainRubyClass.should_receive(:new).with({:withdrawal => 'bank_account'})
439
+ invoke_cucumber_step('there is a plain ruby class with the withdrawal "bank_account"')
440
+ end
441
+
442
+ it "should allow attribute names starting with 'but'" do
443
+ PlainRubyClass.should_receive(:new).with({:butt => 'pear-shaped'})
444
+ invoke_cucumber_step('there is a plain ruby class with the butt "pear-shaped"')
445
+ end
446
+
447
+ it "should allow to set array attributes via doc string" do
448
+ invoke_cucumber_step('there is a plain Ruby class with these attributes:', <<-DOC_STRING)
449
+ tags: ["foo", "bar"]
450
+ DOC_STRING
451
+
452
+ obj = PlainRubyClass.last
453
+ obj.attributes[:tags].should == ['foo', 'bar']
454
+ end
455
+
456
+ it "should allow to set array attributes via data table" do
457
+ invoke_cucumber_step('there is a plain Ruby class with these attributes:', nil, <<-DATA_TABLE)
441
458
  | tags | ["foo", "bar"] |
442
- DATA_TABLE
459
+ DATA_TABLE
443
460
 
444
- obj = PlainRubyClass.last
445
- obj.attributes[:tags].should == ['foo', 'bar']
446
- end
461
+ obj = PlainRubyClass.last
462
+ obj.attributes[:tags].should == ['foo', 'bar']
463
+ end
447
464
 
448
- it 'should allow named records when setting attributes via data table' do
449
- invoke_cucumber_step('"Some Prequel" is a movie with these attributes:', nil, <<-DATA_TABLE)
450
- | title | Before Sunrise |
451
- DATA_TABLE
452
- invoke_cucumber_step('there is a movie with the title "Limitless"')
453
- invoke_cucumber_step('there is a movie with the title "Before Sunset" and the prequel "Some Prequel"')
454
- movie = Movie.find_by_title!('Before Sunset')
455
- prequel = Movie.find_by_title!('Before Sunrise')
456
- movie.prequel.should == prequel
457
- end
465
+ it "should create models that have a machinist blueprint by calling #make" do
466
+ MachinistModel.should_receive(:make).with({ :attribute => "foo"})
467
+ invoke_cucumber_step('there is a machinist model with the attribute "foo"')
468
+ end
458
469
 
459
- it "should allow single quote for attribute values" do
460
- MachinistModel.should_receive(:make).with({ :attribute => "foo"})
461
- invoke_cucumber_step("there is a machinist model with the attribute 'foo'")
462
- end
470
+ it "should be able to step_match machinist blueprint variants" do
471
+ MachinistModel.should_receive(:make).with(:variant, { :attribute => "foo"})
472
+ invoke_cucumber_step('there is a machinist model (variant) with the attribute "foo"')
473
+ end
463
474
 
464
- it "should allow mixed single and double quotes for different attribute values" do
465
- MachinistModel.should_receive(:make).with({ :attribute => "foo", :other_attribute => "bar" })
466
- invoke_cucumber_step("there is a machinist model with the attribute 'foo' and the other attribute \"bar\"")
467
- end
475
+ it "should be able to step_match machinist blueprint variants containing spaces or uppercase characters in prose" do
476
+ MachinistModel.should_receive(:make).with(:variant_mark_two, { :attribute => "foo"})
477
+ invoke_cucumber_step('there is a machinist model (Variant Mark Two) with the attribute "foo"')
478
+ end
468
479
 
469
- it "should allow mixed single quotes for model names" do
470
- invoke_cucumber_step("'Some Prequel' is a movie with the title \"Before Sunrise\"")
471
- invoke_cucumber_step('there is a movie with the title "Limitless"')
472
- invoke_cucumber_step('there is a movie with the title \'Before Sunset\' and the prequel "Some Prequel"')
473
- movie = Movie.find_by_title!('Before Sunset')
474
- prequel = Movie.find_by_title!('Before Sunrise')
475
- movie.prequel.should == prequel
476
- end
480
+ it "should allow single quote for attribute values" do
481
+ MachinistModel.should_receive(:make).with({ :attribute => "foo"})
482
+ invoke_cucumber_step("there is a machinist model with the attribute 'foo'")
483
+ end
477
484
 
478
- it 'should not raise an error for a blank instance name' do
479
- MachinistModel.should_receive(:make).with({ :attribute => 'foo' })
480
- invoke_cucumber_step("'' is a machinist model with the attribute 'foo'")
481
- end
485
+ it "should allow mixed single and double quotes for different attribute values" do
486
+ MachinistModel.should_receive(:make).with({ :attribute => "foo", :other_attribute => "bar" })
487
+ invoke_cucumber_step("there is a machinist model with the attribute 'foo' and the other attribute \"bar\"")
488
+ end
482
489
 
483
- it 'should warn if there are unused fragments' do
484
- MachinistModel.should_not_receive(:make)
485
- lambda { invoke_cucumber_step("there is a machinist model with the attribute NOQUOTES") }.should raise_error(ArgumentError, 'Unable to parse attributes " with the attribute NOQUOTES".')
486
- lambda { invoke_cucumber_step("there is a machinist model with the attribute 'foo' and the ") }.should raise_error(ArgumentError, 'Unable to parse attributes " and the ".')
487
- lambda { invoke_cucumber_step("there is a machinist model with the attribute 'foo'. the other_attribute 'bar' and the third attribute 'baz'") }.should raise_error(ArgumentError, 'Unable to parse attributes ".".')
488
- end
490
+ it 'should not raise an error for a blank instance name' do
491
+ MachinistModel.should_receive(:make).with({ :attribute => 'foo' })
492
+ invoke_cucumber_step("'' is a machinist model with the attribute 'foo'")
493
+ end
489
494
 
495
+ it 'should warn if there are unused fragments' do
496
+ MachinistModel.should_not_receive(:make)
497
+ lambda { invoke_cucumber_step("there is a machinist model with the attribute NOQUOTES") }.should raise_error(ArgumentError, 'Unable to parse attributes " with the attribute NOQUOTES".')
498
+ lambda { invoke_cucumber_step("there is a machinist model with the attribute 'foo' and the ") }.should raise_error(ArgumentError, 'Unable to parse attributes " and the ".')
499
+ lambda { invoke_cucumber_step("there is a machinist model with the attribute 'foo'. the other_attribute 'bar' and the third attribute 'baz'") }.should raise_error(ArgumentError, 'Unable to parse attributes ".".')
500
+ end
501
+ end
490
502
  end