pickle-has_many_support 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +5 -0
  2. data/History.txt +331 -0
  3. data/License.txt +20 -0
  4. data/README.rdoc +299 -0
  5. data/Rakefile +20 -0
  6. data/Rakefile.d/cucumber.rake +24 -0
  7. data/Rakefile.d/jeweller.rake +19 -0
  8. data/Rakefile.d/rcov.rake +18 -0
  9. data/Rakefile.d/rspec.rake +7 -0
  10. data/Rakefile.d/yard.rake +5 -0
  11. data/Todo.txt +3 -0
  12. data/VERSION +1 -0
  13. data/features/app/app.rb +122 -0
  14. data/features/app/blueprints.rb +11 -0
  15. data/features/app/factories.rb +23 -0
  16. data/features/app/views/notifier/email.erb +1 -0
  17. data/features/app/views/notifier/user_email.erb +6 -0
  18. data/features/email/email.feature +64 -0
  19. data/features/generator/generators.feature +59 -0
  20. data/features/path/models_page.feature +44 -0
  21. data/features/path/named_route_page.feature +10 -0
  22. data/features/pickle/create_from_active_record.feature +76 -0
  23. data/features/pickle/create_from_factory_girl.feature +59 -0
  24. data/features/pickle/create_from_machinist.feature +39 -0
  25. data/features/step_definitions/email_steps.rb +63 -0
  26. data/features/step_definitions/extra_email_steps.rb +7 -0
  27. data/features/step_definitions/fork_steps.rb +4 -0
  28. data/features/step_definitions/generator_steps.rb +46 -0
  29. data/features/step_definitions/path_steps.rb +14 -0
  30. data/features/step_definitions/pickle_steps.rb +100 -0
  31. data/features/support/email.rb +21 -0
  32. data/features/support/env.rb +52 -0
  33. data/features/support/paths.rb +47 -0
  34. data/features/support/pickle.rb +26 -0
  35. data/features/support/pickle_app.rb +4 -0
  36. data/init.rb +0 -0
  37. data/lib/pickle/adapter.rb +127 -0
  38. data/lib/pickle/adapters/active_record.rb +46 -0
  39. data/lib/pickle/adapters/data_mapper.rb +37 -0
  40. data/lib/pickle/config.rb +48 -0
  41. data/lib/pickle/email/parser.rb +18 -0
  42. data/lib/pickle/email/world.rb +13 -0
  43. data/lib/pickle/email.rb +79 -0
  44. data/lib/pickle/parser/matchers.rb +95 -0
  45. data/lib/pickle/parser.rb +71 -0
  46. data/lib/pickle/path/world.rb +5 -0
  47. data/lib/pickle/path.rb +45 -0
  48. data/lib/pickle/session/parser.rb +34 -0
  49. data/lib/pickle/session.rb +195 -0
  50. data/lib/pickle/version.rb +9 -0
  51. data/lib/pickle/world.rb +13 -0
  52. data/lib/pickle.rb +26 -0
  53. data/pickle.gemspec +117 -0
  54. data/rails_generators/pickle/pickle_generator.rb +33 -0
  55. data/rails_generators/pickle/templates/email.rb +21 -0
  56. data/rails_generators/pickle/templates/email_steps.rb +63 -0
  57. data/rails_generators/pickle/templates/paths.rb +47 -0
  58. data/rails_generators/pickle/templates/pickle.rb +28 -0
  59. data/rails_generators/pickle/templates/pickle_steps.rb +100 -0
  60. data/spec/pickle/adapter_spec.rb +163 -0
  61. data/spec/pickle/config_spec.rb +105 -0
  62. data/spec/pickle/email/parser_spec.rb +51 -0
  63. data/spec/pickle/email_spec.rb +160 -0
  64. data/spec/pickle/parser/matchers_spec.rb +74 -0
  65. data/spec/pickle/parser_spec.rb +165 -0
  66. data/spec/pickle/path_spec.rb +101 -0
  67. data/spec/pickle/session_spec.rb +451 -0
  68. data/spec/pickle_spec.rb +24 -0
  69. data/spec/spec_helper.rb +8 -0
  70. metadata +144 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ doc/*
3
+ .yardoc
4
+ pickle-email*
5
+ cucumber_test_app
data/History.txt ADDED
@@ -0,0 +1,331 @@
1
+ == 0.3.0
2
+
3
+ * 2 major improvements
4
+ * Mechanism for registering ORM adapters for pickle [Daniel Neighman]
5
+ * Adapters for ActiveRecord and DataMapper [Josh Bassett, Daniel Neighman]
6
+
7
+
8
+ == 0.2.12
9
+
10
+ * 1 bugfix
11
+ * script/generate pickle paths now works correctly with cucumber-rails 0.3.2
12
+
13
+
14
+ == 0.2.11
15
+
16
+ * 1 improvement
17
+ * use correct type when converting STI pickle model to attributes
18
+
19
+
20
+ == 0.2.10
21
+
22
+ * 2 improvements
23
+ * pickle backend is rails 3 compatible (but generators are not yet)
24
+ * modular Rakefile, devs can run only what they're interested in without having to install all gems
25
+
26
+
27
+ == 0.2.9 - 27 Apr 2010 (the #railscamp7 release)
28
+
29
+ * 5 improvements
30
+ * Fixed problem with verifying model attribute using strings with escaped quotes [Michael MacDonald]
31
+ * Added handling for positive and negative floats [Michael MacDonald, #railscamp7]
32
+ * Added handling of ruby integer syntax (e.g. 1_000_000) [Ian White]
33
+ * Modified the way pickle handles predicates to match rspec [Michael MacDonald, #railscamp7]
34
+ * Added step to assert size of an association (e.g. Then the user should have 4 friends) [Ian White]
35
+
36
+
37
+ == 0.2.8 - 5 Apr 2010
38
+
39
+ * 1 minor improvement
40
+ * 'Then show me the email' works as expected now [#18]
41
+
42
+
43
+ == 0.2.7 - 5 Apr 2010
44
+
45
+ * 1 minor improvement
46
+ * just rake 'rake cucumber' and a rails app will be setup for you if required (rails 2.3 only ATM)
47
+
48
+
49
+ == 0.2.6 - 5 Apr 2010
50
+
51
+ * 2 improvements
52
+ * running specs is now doable without being in a rails app - just do 'rake spec'
53
+ * running features is more straightforward, 'rake cucumber' then follow the instructions
54
+
55
+
56
+ == 0.2.5 - 17 Mar 2010
57
+
58
+ * 2 improvements
59
+ * Bugfix for find_models_via_table (failing to find models was not causing an error) [Chris Flipse]
60
+ * find_models_via_table & create_models_via_table return the found/created models [Chris Flipse, Ian White]
61
+
62
+
63
+ == 0.2.4 - 9 Mar 2010
64
+
65
+ * 1 major improvement
66
+ * Finding models via a table now works in the same way as creating models via a table (0.2.3), you
67
+ can create pickle refs
68
+
69
+
70
+ == 0.2.3 - 9 Mar 2010
71
+
72
+ * 1 major improvement
73
+ * You can now use pickle refs in tables. If you add a column which is the single factory name, the
74
+ contents of the column will be used as the pickle ref. [Stephan Hagemann]
75
+ e.g.
76
+ Given the following users exist:
77
+ | user | name | status |
78
+ | jack | Jack Spratt | alone |
79
+ | pete | Pete Sprong | dead |
80
+
81
+ * 1 minor improvement
82
+ * Fix bug in error message for when pickle ref can't be found [Myron Marston]
83
+
84
+
85
+ == 0.2.2 - 25 Feb 2010
86
+
87
+ * 3 improvements
88
+ * Added ability to follow links in emails (see email_steps.rb) [Michael Moen]
89
+ * Added a step definition for doing stuff like: Then the user's name should be "Tobi" [Tobi Knaup]
90
+ * Docfixes, mostly about testing [Nicholas Rutherford]
91
+
92
+
93
+ == 0.2.1 - 1 Dec 2009
94
+
95
+ * 2 minor improvements
96
+ * Allow nil as field value [#14]
97
+ * Added negative email step for delivered to
98
+
99
+
100
+ == 0.2.0 - 24 Nov 2009
101
+
102
+ * 4 major improvements
103
+ * Added support for finding models using tables
104
+ Example:
105
+ Then the following users should exist:
106
+ | name |
107
+ | Fred |
108
+ | Ethel |
109
+ And the 1st user should be male
110
+ And the 2nd user should be female
111
+
112
+ * tables now support pickle refs in cells (see features/pickle/create_from_factory_girl.rb#37)
113
+
114
+ * features/support/email.rb adds an email helper for mapping names to email addresses (similar to NavigationHelper in paths.rb)
115
+
116
+ * Added ability for path_to_pickle to handle arbitrary segments
117
+ Example:
118
+ path_to_pickle('account', 'the enquiry') => account_enquiry_path(<enquiry>)
119
+
120
+ * 2 minor improvements
121
+ * fail faster in pickle steps when a pickle ref can't be found, by using model! in most places
122
+
123
+ * generated pickle steps are less picky about possessives so that pickle mappings accepted in more places
124
+ e.g. when you have
125
+ config.map 'my', 'I', 'myself', :to => 'user: "me"'
126
+ you can now do
127
+ Given I exist
128
+ ...
129
+ Then the project should be one of my assigned projects
130
+
131
+
132
+ == 0.1.23 - 22 Nov 2009
133
+
134
+ * 1 major improvement
135
+ * script/generate pickle now adds its own pickle.rb support file, making it easier to regenerate cucumber
136
+ when a new release of cucumber appears [schlick, ianwhite]
137
+
138
+ * 1 minor improvement
139
+ * docs: more links
140
+
141
+
142
+ == 0.1.22 - 7 Nov 2009
143
+
144
+ * 2 minor enhancements
145
+ * Improved docs to include instructions for FactoryGirl users, and links/resources for pickle users
146
+ * Ruby 1.9.1 compatibility changes
147
+
148
+
149
+ == 0.1.21
150
+
151
+ * 1 minor enhancement
152
+ * Added 'should not' steps corresponding to model existence, and association exitsence [schlick]
153
+
154
+
155
+ == 0.1.20
156
+
157
+ * 1 minor enhancement
158
+ * Pickle now matches numeric field values preceded with a positive and negative sign eg +1.5 and -1 [schlick]
159
+
160
+
161
+ == 0.1.19
162
+
163
+ * 1 minor enhancement
164
+ * Add support for Cucumber tables [Tobi Knaup]
165
+
166
+
167
+ == 0.1.16, 0.1.17, 0.1.18 - 13 Oct 2009
168
+
169
+ * 1 minor enhancement
170
+ * release gem on gemcutter and code on github
171
+
172
+
173
+ == 0.1.15 - 28 Aug 2009
174
+
175
+ * 1 minor enhancement
176
+ * avoid namespace collision on replace by renaming mapping#replace -> mapping#replacement [nruth]
177
+
178
+
179
+ == 0.1.14 - 9 July 2009
180
+
181
+ * 1 minor enhancement
182
+ * update specs and features for latest cucumber and machinist changes
183
+
184
+
185
+ == 0.1.13 - 16 June 2009
186
+
187
+ * 2 minor enhancements
188
+ * model! and created_model! raise an error if pickle name can't be found
189
+ * path_to_pickle uses the above to give back a better error message
190
+
191
+
192
+ == 0.1.12 - 7 Apr 2009
193
+
194
+ * 2 minor enhancements
195
+ * rationalised Rakefile
196
+ * update World extensions for latest cucumber changes
197
+
198
+
199
+ == 0.1.11 - 22 Feb 2009
200
+
201
+ * 2 minor enhancements
202
+ * Pickle now supports multiple machinist blueprints
203
+ * Fix confusing adapter/adaptor comment generator comment
204
+
205
+
206
+ == 0.1.10 - 13 Feb 2009
207
+
208
+ * 2 minor enhancements
209
+ * Made pickle paths generator compatible with latest cucumber
210
+ * Simplified and Rakefile, including auto push api docs to gh-pages on ci build
211
+
212
+
213
+ == 0.1.9 - 29 Jan 2009
214
+
215
+ * 1 minor enhancement
216
+ * Pickle::Adapter.model_classes excludes those without tables
217
+
218
+
219
+ == 0.1.8 - 29 Jan 2009
220
+
221
+ * API change
222
+ * pickle_path becomes path_to_pickle, to avoid named route clashes
223
+
224
+ * 2 minor enhancements
225
+ * Updated features for cucumber 0.2 compat
226
+ * Made paths allow for optional possesives
227
+
228
+
229
+ == 0,1,7
230
+
231
+ * 2 API changes
232
+ * script/generate pickle path[s] now amends the features/support/paths.rb file
233
+ instead of creating pge_to_path and path_steps.
234
+
235
+ * pickle_email_steps is renamed email_steps
236
+
237
+
238
+ == 0.1.6
239
+
240
+ * 1 API change
241
+ * to use pickle env.rb should contain "require 'pickle/world'". You should remove all trace of
242
+ pickle from features/support/env.rb and re run script/generate pickle
243
+
244
+ * 2 major enhancements
245
+
246
+ * generate email steps with `script/generate pickle email`
247
+ email steps allow you to do things like this:
248
+
249
+ Then 2 emails should be delivered
250
+ And the first email should be delivered to fred@gmail.com
251
+ And the 2nd email should be delivered to the user: "ethel"
252
+
253
+ Then 1 email should be delivered with subject: "Activate your account"
254
+ And the email should link to the user's page
255
+
256
+ take a look at features/step_definitions/pickle_email_steps.rb
257
+
258
+ * generate path steps with `script/generate pickle path`
259
+ path steps allow you to do things like this
260
+
261
+ When I go to the comment's page
262
+ Then I should be at the user's new comment page
263
+
264
+ take a look at features/step_definitions/pickle_path_steps.rb, and modify page_to_path to suit your needs
265
+
266
+ * 4 minor enhancements
267
+ * Improved documentation
268
+ * abstract models no longer kill pickle
269
+ * Actually test that the generators work
270
+ * Made Pickle::Session a plain ole mixin, as a separate class was unnecessary
271
+ * Pickle uses the cucumber World API
272
+
273
+
274
+ == 0.1.5
275
+
276
+ * API change
277
+ * CaptureModel, etc are now 'capture_model' methods
278
+
279
+ * 3 major enhancements
280
+ * Steps for asserting that <n> models exist, matching certain criteria
281
+ * Steps for asserting associations added to generated pickle steps
282
+ 'Then the user should be in the post's commenters'
283
+ 'Then the forum: "awesome" should be the 2nd post's forum'
284
+ * configuration can now occur any time before a step is defined, which makes
285
+ for much more intuitive env.rb
286
+
287
+ * 2 minor enhancement
288
+ * predicate matching is less prone to step conflicts because we preload a
289
+ big list of all the predicate and column methods
290
+ * field values now handle booleans and numerics
291
+
292
+
293
+ == 0.1.4
294
+
295
+ * 1 major enhancement
296
+ * You can create multiple models with ease, for eg.
297
+ 'Given 10 users exist with role: "admin"'
298
+
299
+ * 1 minor enhancement
300
+ * You can do Pickle.configure (just like Webrat.configure)
301
+
302
+
303
+ == 0.1.3 - Bugfix release
304
+
305
+ * 1 minor enhancement
306
+ * make generated steps compatible with Rails 2.1
307
+
308
+
309
+ == 0.1.2
310
+
311
+ * 2 major enhancements
312
+ * create your pickle steps with script/generate pickle
313
+ * Adapter based architecture, supports Machinist, FactoryGirl, and vanilla ActiveRecord
314
+
315
+ * 1 minor enhancement
316
+ * model_names now defaults to subclasses of AR::Base
317
+ * #original_model => #created_model
318
+
319
+
320
+ == 0.1.1
321
+
322
+ * 1 major enhancement:
323
+ * made pickle a github gem
324
+
325
+ * 1 minor enhancement:
326
+ * Added intentions for pickle in README.textile
327
+
328
+
329
+ == Prior to gems
330
+
331
+ * Initial release: everything is subject to sweeping change
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2010 Ian White - ian.w.white@gmail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,299 @@
1
+ = pickle
2
+
3
+ Pickle gives you cucumber steps that create your models easily from factory-girl or
4
+ machinist factories/blueprints. You can also just use ActiveRecord as a factory but it's not as cool.
5
+
6
+ Pickle can make use of different ORMs for finding records. Currently ActiveRecord and DataMapper adapters are
7
+ provided. More adapters welcome!
8
+
9
+ References to the models are stored in the current world, not necessarily for the purpose of checking the db
10
+ (although you could use it for that), but for enabling easy reference to urls, and for
11
+ building complex givens which require a bunch of models collaborating
12
+
13
+ == Resources
14
+
15
+ <b>Github</b> for code: http://github.com/ianwhite/pickle
16
+
17
+ <b>Gemcutter</b> for the gem: http://gemcutter.org/gems/pickle
18
+
19
+ <b>Rdoc.info</b> for docs: http://rdoc.info/projects/ianwhite/pickle
20
+
21
+ <b>Google group</b> for questions: http://groups.google.com/group/pickle-cucumber
22
+
23
+ <b>Lighthouse</b> for bugs: http://ianwhite.lighthouseapp.com/projects/25941-pickle
24
+
25
+ <b>Railscast</b> presentation: http://railscasts.com/episodes/186-pickle-with-cucumber
26
+
27
+ <b>Blog articles</b>: {dynamic50: Integration testing with cucumber and pickle}[http://blog.dynamic50.com/index.php/2009/04/integration-testing-with-cucumber-and-pickle/], {rubyflare: pickle my cucumber}[http://rubyflare.com/2009/10/28/pickle-my-cucumber/]
28
+
29
+ == Install
30
+
31
+ Install pickle either as a rails plugin, or a gem
32
+
33
+ # gem from gemcutter
34
+ sudo gem install pickle
35
+
36
+ # gem dependency (in config/environments/cucumber.rb)
37
+ config.gem 'pickle'
38
+
39
+ # plugin
40
+ script/plugin install git://github.com/ianwhite/pickle.git
41
+
42
+ # or, plugin as submodule
43
+ git submodule add git://github.com/ianwhite/pickle.git vendor/plugins/pickle
44
+
45
+ == CI
46
+
47
+ It's tested against all stable branches of 2.x rails, and edge, with the latest versions of rspec, cucumber, factory_girl, machinist.
48
+
49
+ == Run the tests
50
+
51
+ To run the specs do:
52
+
53
+ rake spec
54
+
55
+ To run the features (rails 2.3 only ATM):
56
+
57
+ rake cucumber
58
+
59
+ == Contributors
60
+
61
+ The following people have made Pickle better:
62
+
63
+ * {Daniel Neighman}[http://github.com/hassox]
64
+ * {Josh Bassett}[http://github.com/nullobject]
65
+ * {Nick Rutherford}[http://github.com/nruth]
66
+ * {Tobi Knaup}[http://github.com/guenter]
67
+ * {Michael MacDonald}[http://github.com/schlick]
68
+ * {Michael Moen}[http://github.com/UnderpantsGnome]
69
+ * {Myron Marston}[http://github.com/myronmarston]
70
+ * {Stephan Hagemann}[http://github.com/xing]
71
+ * {Chris Flipse}[http://github.com/cflipse]
72
+
73
+ == Get Started
74
+
75
+ (you'd better install cucumber)
76
+
77
+ script/generate pickle [paths] [email]
78
+
79
+ Now have a look at <tt>features/step_definitions/pickle_steps.rb</tt>
80
+
81
+ If you want path steps and email steps then just add 'paths' and/or 'email'. The code/steps will be
82
+ written to <tt>features/env/paths.rb</tt> and
83
+ <tt>features/step_definitions/email_steps.rb</tt> respectively.
84
+
85
+ === Using with plain ole Active Record or DataMapper
86
+
87
+ Pickle comes with adapters for Active Record and DataMapper.
88
+
89
+ If you have an AR/DM called 'Post', with required fields 'title', and 'body', then you can now write
90
+ steps like this
91
+
92
+ Given a post exists with title: "My Post", body: "My body"
93
+
94
+ === Using with factory-girl or machinist
95
+
96
+ But you're using Machinist or FactoryGirl right?! To leverage all of the factories/blueprints
97
+ you've written, you can just do stuff like
98
+
99
+ Given a user exists
100
+ And another user exists with role: "admin"
101
+
102
+ # later
103
+ Then a user should exist with name: "Fred"
104
+ And that user should be activated # this uses rspec predicate matchers
105
+
106
+ ==== Machinst: require your blueprints and reset Shams
107
+
108
+ (The latest version of pickle supports {multiple blueprints}[http://github.com/notahat/machinist/commit/d6492e6927a8aa1819926e48b22377171fd20496], for
109
+ earlier versions of machinist use pickle <= 0.1.10)
110
+
111
+ In your <tt>features/support/env.rb</tt> add the following lines at the bottom
112
+
113
+ require "#{Rails.root}/spec/blueprints" # or wherever they live
114
+ Before { Sham.reset } # reset Shams in between scenarios
115
+
116
+ ==== FactoryGirl: make sure factories are loaded
117
+
118
+ In your config/environments/cucumber.rb file, make sure the factory-girl gem is included (unless it's installed as a plugin).
119
+
120
+ If that doesn't solve loading issues then require your factories.rb file directly in a file called 'features/support/factory_girl.rb'
121
+
122
+ # example features/support/factory_girl.rb
123
+ require File.dirname(__FILE__) + '/../../spec/factories'
124
+
125
+ === Using with an ORM other than ActiveRecord or DataMapper
126
+
127
+ Pickle can be used with any Modeling library provided there is an adapter written for it.
128
+
129
+ Adapters are very simple and exist a module or class with the name "PickleAdapter" available to the class. For example
130
+
131
+ User.const_get(:PickleAdapter) #=> should return a pickle adapter
132
+
133
+ The Active Record and DataMapper ones can be found at
134
+ ActiveRecord::Base::PickleAdapter and DataMapper::Resource::PickleAdapter respectively.
135
+
136
+ See how to implement one by looking at the ones provided in the pickle source in lib/pickle/adapters/*
137
+
138
+ === Configuring Pickle
139
+
140
+ You can tell pickle to use another factory adapter (see Pickle::Adapter), or
141
+ create mappings from english expressions to pickle model names. You can also
142
+ override many of the options on the Pickle::Config object if you so choose.
143
+
144
+ In: <tt>features/support/pickle.rb</tt>
145
+
146
+ require 'pickle/world'
147
+
148
+ Pickle.configure do |config|
149
+ config.adapters = [:machinist, YourOwnAdapterClass]
150
+ config.map 'me', 'myself', 'my', 'I', :to => 'user: "me"'
151
+ end
152
+
153
+ Out of the box pickle looks for machinist, then factory-girl, then finally active-record 'factories'.
154
+ If you find that your steps aren't working with your factories, it's probably the case that your factory
155
+ setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).
156
+
157
+ == API
158
+
159
+ === Steps
160
+
161
+ When you run <tt>script/generate pickle</tt> you get the following steps
162
+
163
+ ==== Given steps
164
+
165
+ "Given <b>a model</b> exists", e.g.
166
+
167
+ Given a user exists
168
+ Given a user: "fred" exists
169
+ Given the user exists
170
+
171
+ "Given <b>a model</b> exists with <b>fields</b>", e.g.
172
+
173
+ Given a user exists with name: "Fred"
174
+ Given a user exists with name: "Fred", activated: false
175
+
176
+ You can refer to other models in the fields
177
+
178
+ Given a user exists
179
+ And a post exists with author: the user
180
+
181
+ Given a person: "fred" exists
182
+ And a person: "ethel" exists
183
+ And a fatherhood exists with parent: user "fred", child: user "ethel"
184
+
185
+ "Given <b>n models</b> exist", e.g.
186
+
187
+ Given 10 users exist
188
+
189
+ "Given <b>n models</b> exist with <b>fields</b>", examples:
190
+
191
+ Given 10 users exist with activated: false
192
+
193
+ "Given the following <b>models</b> exist:", examples:
194
+
195
+ Given the following users exist
196
+ | name | activated |
197
+ | Fred | false |
198
+ | Ethel | true |
199
+
200
+ ==== Then steps
201
+
202
+ ===== Asserting existence of models
203
+
204
+ "Then <b>a model</b> should exist", e.g.
205
+
206
+ Then a user should exist
207
+
208
+ "Then <b>a model</b> should exist with <b>fields</b>", e.g.
209
+
210
+ Then a user: "fred" should exist with name: "Fred" # we can label the found user for later use
211
+
212
+ You can use other models, booleans, numerics, and strings as fields
213
+
214
+ Then a person should exist with child: person "ethel"
215
+ Then a user should exist with activated: false
216
+ Then a user should exist with activated: true, email: "fred@gmail.com"
217
+
218
+ "Then <b>n models</b> should exist", e.g.
219
+
220
+ Then 10 events should exist
221
+
222
+ "Then <b>n models</b> should exist with <b>fields</b>", e.g.
223
+
224
+ Then 2 people should exist with father: person "fred"
225
+
226
+ "Then the following <b>models</b> exist". This allows the creation of multiple models
227
+ using a table syntax. Using a column with the singularized name of the model creates a referenceable model. E.g.
228
+
229
+ Then the following users exist:
230
+ | name | activated |
231
+ | Freddy | false |
232
+
233
+ Then the following users exist:
234
+ | user | name | activated |
235
+ | Fred | Freddy | false |
236
+
237
+ ===== Asserting associations
238
+
239
+ One-to-one assocs: "Then <b>a model</b> should be <b>other model</b>'s <b>association</b>", e.g.
240
+
241
+ Then the person: "fred" should be person: "ethel"'s father
242
+
243
+ Many-to-one assocs: "Then <b>a model</b> should be [in|one of] <b>other model</b>'s <b>association</b>", e.g.
244
+
245
+ Then the person: "ethel" should be one of person: "fred"'s children
246
+ Then the comment should be in the post's comments
247
+
248
+ ===== Asserting predicate methods
249
+
250
+ "Then <b>a model</b> should [be|have] [a|an] <b>predicate</b>", e.g.
251
+
252
+ Then the user should have a status # => user.status.should be_present
253
+ Then the user should have a stale password # => user.should have_stale_password
254
+ Then the car: "batmobile" should be fast # => car.should be_fast
255
+
256
+ "Then <b>a model</b> should not [be|have] [a|an] <b>predicate</b>", e.g.
257
+
258
+ Then person: "fred" should not be childless # => fred.should_not be_childless
259
+
260
+ === Regexps for use in your own steps
261
+
262
+ By default you get some regexps available in the main namespace for use
263
+ in creating your own steps: `capture_model`, `capture_fields`, and others (see lib/pickle.rb)
264
+
265
+ (You can use any of the regexps that Pickle uses by using the Pickle.parser namespace, see
266
+ Pickle::Parser::Matchers for the methods available)
267
+
268
+ *capture_model*
269
+
270
+ Given /^#{capture_model} exists$/ do |model_name|
271
+ model(model_name).should_not == nil
272
+ end
273
+
274
+ Then /^I should be at the (.*?) page$/ |page|
275
+ if page =~ /#{capture_model}'s/
276
+ url_for(model($1))
277
+ else
278
+ # ...
279
+ end
280
+ end
281
+
282
+ Then /^#{capture_model} should be one of #{capture_model}'s posts$/ do |post, forum|
283
+ post = model!(post)
284
+ forum = model!(forum)
285
+ forum.posts.should include(post)
286
+ end
287
+
288
+ *capture_fields*
289
+
290
+ This is useful for setting attributes, and knows about pickle model names so that you
291
+ can build up composite objects with ease
292
+
293
+ Given /^#{capture_model} exists with #{capture_fields}$/ do |model_name, fields|
294
+ create_model(model_name, fields)
295
+ end
296
+
297
+ # example of use
298
+ Given a user exists
299
+ And a post exists with author: the user # this step will assign the above user as :author on the post
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('lib')
2
+
3
+ # load given tasks file, reporting errors without failing
4
+ def load_tasks(tasks)
5
+ load tasks
6
+ rescue Exception => exception
7
+ $stderr << "** loading #{tasks.sub(File.expand_path('.'),'')} failed: "
8
+ case exception
9
+ when LoadError
10
+ $stderr << "to use, install the gems it requires\n"
11
+ else
12
+ $stderr << ([exception.message] + exception.backtrace[0..2]).join("\n ") << "\n\n"
13
+ end
14
+ end
15
+
16
+ Dir["Rakefile.d/*.rake"].sort.each {|t| load_tasks t}
17
+
18
+ task :default => :spec
19
+
20
+ task :ci => ['rcov:verify', 'cucumber']
@@ -0,0 +1,24 @@
1
+ require 'cucumber/rake/task'
2
+
3
+ desc "Run features"
4
+ Cucumber::Rake::Task.new(:cucumber => [:cucumber_test_app]) do |t|
5
+ t.cucumber_opts = ['--format', 'pretty', '--require', 'features']
6
+ end
7
+
8
+ desc "setup a rails app for running cucumber"
9
+ file "cucumber_test_app" do
10
+ puts "** setting up cucumber test app ** (rails 2.3 only at present)"
11
+ Rake::Task['cucumber:setup'].invoke
12
+ end
13
+
14
+ namespace :cucumber do
15
+ task :setup do
16
+ rm_rf "cucumber_test_app"
17
+ sh "rails cucumber_test_app"
18
+ cd "cucumber_test_app" do
19
+ sh "script/generate rspec"
20
+ sh "script/generate cucumber"
21
+ end
22
+ sh "ln -s #{File.expand_path('.')} cucumber_test_app/vendor/plugins/pickle"
23
+ end
24
+ end