factory_girl_kibiz0r 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/Appraisals +12 -0
  2. data/CONTRIBUTION_GUIDELINES.md +9 -0
  3. data/Changelog +29 -0
  4. data/GETTING_STARTED.md +246 -0
  5. data/Gemfile +12 -0
  6. data/Gemfile.lock +62 -0
  7. data/LICENSE +19 -0
  8. data/README.md +64 -0
  9. data/Rakefile +54 -0
  10. data/features/factory_girl_steps.feature +151 -0
  11. data/features/step_definitions/database_steps.rb +20 -0
  12. data/features/support/env.rb +6 -0
  13. data/features/support/factories.rb +84 -0
  14. data/lib/factory_girl/aliases.rb +21 -0
  15. data/lib/factory_girl/attribute/association.rb +24 -0
  16. data/lib/factory_girl/attribute/callback.rb +16 -0
  17. data/lib/factory_girl/attribute/dynamic.rb +21 -0
  18. data/lib/factory_girl/attribute/implicit.rb +36 -0
  19. data/lib/factory_girl/attribute/list.rb +19 -0
  20. data/lib/factory_girl/attribute/sequence.rb +16 -0
  21. data/lib/factory_girl/attribute/static.rb +18 -0
  22. data/lib/factory_girl/attribute.rb +42 -0
  23. data/lib/factory_girl/definition_proxy.rb +147 -0
  24. data/lib/factory_girl/deprecated.rb +18 -0
  25. data/lib/factory_girl/factory.rb +196 -0
  26. data/lib/factory_girl/find_definitions.rb +23 -0
  27. data/lib/factory_girl/proxy/attributes_for.rb +21 -0
  28. data/lib/factory_girl/proxy/build.rb +36 -0
  29. data/lib/factory_girl/proxy/create.rb +16 -0
  30. data/lib/factory_girl/proxy/stub.rb +64 -0
  31. data/lib/factory_girl/proxy.rb +87 -0
  32. data/lib/factory_girl/rails2.rb +1 -0
  33. data/lib/factory_girl/registry.rb +45 -0
  34. data/lib/factory_girl/sequence.rb +31 -0
  35. data/lib/factory_girl/step_definitions.rb +60 -0
  36. data/lib/factory_girl/syntax/blueprint.rb +42 -0
  37. data/lib/factory_girl/syntax/default.rb +33 -0
  38. data/lib/factory_girl/syntax/generate.rb +73 -0
  39. data/lib/factory_girl/syntax/make.rb +41 -0
  40. data/lib/factory_girl/syntax/methods.rb +86 -0
  41. data/lib/factory_girl/syntax/sham.rb +45 -0
  42. data/lib/factory_girl/syntax/vintage.rb +152 -0
  43. data/lib/factory_girl/syntax.rb +12 -0
  44. data/lib/factory_girl/version.rb +4 -0
  45. data/lib/factory_girl.rb +54 -0
  46. data/spec/acceptance/acceptance_helper.rb +11 -0
  47. data/spec/acceptance/attribute_aliases_spec.rb +26 -0
  48. data/spec/acceptance/attributes_for_spec.rb +48 -0
  49. data/spec/acceptance/build_spec.rb +35 -0
  50. data/spec/acceptance/build_stubbed_spec.rb +79 -0
  51. data/spec/acceptance/callbacks_spec.rb +53 -0
  52. data/spec/acceptance/create_spec.rb +67 -0
  53. data/spec/acceptance/default_strategy_spec.rb +27 -0
  54. data/spec/acceptance/definition_spec.rb +28 -0
  55. data/spec/acceptance/parent_spec.rb +39 -0
  56. data/spec/acceptance/sequence_spec.rb +34 -0
  57. data/spec/acceptance/syntax/blueprint_spec.rb +32 -0
  58. data/spec/acceptance/syntax/generate_spec.rb +60 -0
  59. data/spec/acceptance/syntax/make_spec.rb +35 -0
  60. data/spec/acceptance/syntax/sham_spec.rb +44 -0
  61. data/spec/acceptance/syntax/vintage_spec.rb +224 -0
  62. data/spec/factory_girl/aliases_spec.rb +33 -0
  63. data/spec/factory_girl/attribute/association_spec.rb +33 -0
  64. data/spec/factory_girl/attribute/callback_spec.rb +23 -0
  65. data/spec/factory_girl/attribute/dynamic_spec.rb +60 -0
  66. data/spec/factory_girl/attribute/implicit_spec.rb +50 -0
  67. data/spec/factory_girl/attribute/sequence_spec.rb +21 -0
  68. data/spec/factory_girl/attribute/static_spec.rb +29 -0
  69. data/spec/factory_girl/attribute_spec.rb +39 -0
  70. data/spec/factory_girl/definition_proxy_spec.rb +129 -0
  71. data/spec/factory_girl/deprecated_spec.rb +66 -0
  72. data/spec/factory_girl/factory_spec.rb +374 -0
  73. data/spec/factory_girl/find_definitions_spec.rb +100 -0
  74. data/spec/factory_girl/proxy/attributes_for_spec.rb +52 -0
  75. data/spec/factory_girl/proxy/build_spec.rb +86 -0
  76. data/spec/factory_girl/proxy/create_spec.rb +107 -0
  77. data/spec/factory_girl/proxy/stub_spec.rb +80 -0
  78. data/spec/factory_girl/proxy_spec.rb +102 -0
  79. data/spec/factory_girl/registry_spec.rb +83 -0
  80. data/spec/factory_girl/sequence_spec.rb +96 -0
  81. data/spec/factory_girl_spec.rb +17 -0
  82. data/spec/spec_helper.rb +93 -0
  83. metadata +294 -0
data/Appraisals ADDED
@@ -0,0 +1,12 @@
1
+ appraise "2.1" do
2
+ gem "activerecord", "~> 2.1"
3
+ end
4
+
5
+ appraise "2.3" do
6
+ gem "activerecord", "~> 2.3"
7
+ end
8
+
9
+ appraise "3.0" do
10
+ gem "activerecord", "~> 3.0"
11
+ end
12
+
@@ -0,0 +1,9 @@
1
+ We're using [GitHub](http://github.com/thoughtbot/factory_girl/tree/master), and we've been getting any combination of github pull requests, patches, emails, etc. We need to normalize this workflow to make sure we don't miss any fixes.
2
+
3
+ * Make sure you're accessing the source from the [official repository](http://github.com/thoughtbot/factory_girl/tree/master).
4
+ * Please make a branch for each separate contribution. We can cherry pick your commits, but pulling from a branch is easier.
5
+ * If you're submitting patches, please cut each fix or feature into a separate patch.
6
+ * There should be an [issue](http://github.com/thoughtbot/factory_girl/issues) for any submission. If you've found a bug and want to fix it, open a new ticket at the same time.
7
+ * Please <b>don't send pull requests</b> Just update the issue with the url for your fix when it's ready. The github pull requests pretty much get dropped on the floor until someone with commit rights notices them in the mailbox.
8
+ * Contributions without tests won't be accepted.
9
+ * Please don't submit patches or branches that update the Gem version.
data/Changelog ADDED
@@ -0,0 +1,29 @@
1
+ 1.1.4 (November 28, 2008)
2
+ Factory.build now uses Factory.create for associations of the built object
3
+ Factory definitions are now detected in subdirectories, such as
4
+ factories/person_factory.rb (thanks to Josh Nichols)
5
+ Factory definitions are now loaded after the environment in a Rails project
6
+ (fixes some issues with dependencies being loaded too early) (thanks to
7
+ Josh Nichols)
8
+ Factory names ending in 's' no longer cause problems (thanks to Alex Sharp
9
+ and Josh Owens)
10
+
11
+ 1.1.3 (September 12, 2008)
12
+ Automatically pull in definitions from factories.rb, test/factories.rb, or
13
+ spec/factories.rb
14
+ 1.1.2 (July 30, 2008)
15
+ Improved error handling for invalid and undefined factories/attributes
16
+ Improved handling of strings vs symbols vs classes
17
+ Added a prettier syntax for handling associations
18
+ Updated documentation and fixed compatibility with Rails 2.1
19
+
20
+ 1.1.1 (June 23, 2008)
21
+ The attribute "name" no longer requires using #add_attribute
22
+
23
+ 1.1.0 (June 3, 2008)
24
+ Added support for dependent attributes
25
+ Fixed the attributes_for build strategy to not build associations
26
+ Added support for sequences
27
+
28
+ 1.0.0 (May 31, 208)
29
+ First version
@@ -0,0 +1,246 @@
1
+ Getting Started
2
+ ===============
3
+
4
+ Defining factories
5
+ ------------------
6
+
7
+ Each factory has a name and a set of attributes. The name is used to guess the class of the object by default, but it's possible to explicitly specify it:
8
+
9
+ # This will guess the User class
10
+ FactoryGirl.define do
11
+ factory :user do
12
+ first_name 'John'
13
+ last_name 'Doe'
14
+ admin false
15
+ end
16
+
17
+ # This will use the User class (Admin would have been guessed)
18
+ factory :admin, :class => User do
19
+ first_name 'Admin'
20
+ last_name 'User'
21
+ admin true
22
+ end
23
+
24
+ # The same, but using a string instead of class constant
25
+ factory :admin, :class => 'user' do
26
+ first_name 'Admin'
27
+ last_name 'User'
28
+ admin true
29
+ end
30
+ end
31
+
32
+ It is highly recommended that you have one factory for each class that provides the simplest set of attributes necessary to create an instance of that class. If you're creating ActiveRecord objects, that means that you should only provide attributes that are required through validations and that do not have defaults. Other factories can be created through inheritance to cover common scenarios for each class.
33
+
34
+ Attempting to define multiple factories with the same name will raise an error.
35
+
36
+ Factories can be defined anywhere, but will be automatically loaded if they
37
+ are defined in files at the following locations:
38
+
39
+ test/factories.rb
40
+ spec/factories.rb
41
+ test/factories/*.rb
42
+ spec/factories/*.rb
43
+
44
+ Using factories
45
+ ---------------
46
+
47
+ factory_girl supports several different build strategies: build, create, attributes_for and stub:
48
+
49
+ # Returns a User instance that's not saved
50
+ user = FactoryGirl.build(:user)
51
+
52
+ # Returns a saved User instance
53
+ user = FactoryGirl.create(:user)
54
+
55
+ # Returns a hash of attributes that can be used to build a User instance:
56
+ attrs = FactoryGirl.attributes_for(:user)
57
+
58
+ # Returns an object with all defined attributes stubbed out:
59
+ stub = FactoryGirl.stub(:user)
60
+
61
+ No matter which strategy is used, it's possible to override the defined attributes by passing a hash:
62
+
63
+ # Build a User instance and override the first_name property
64
+ user = FactoryGirl.build(:user, :first_name => 'Joe')
65
+ user.first_name
66
+ # => "Joe"
67
+
68
+ If repeating "FactoryGirl" is too verbose for you, you can mix the syntax methods in:
69
+
70
+ # rspec
71
+ RSpec.configure do |config|
72
+ config.include Factory::Syntax::Methods
73
+ end
74
+
75
+ # Test::Unit
76
+ class Test::Unit::TestCase
77
+ include Factory::Syntax::Methods
78
+ end
79
+
80
+ Lazy Attributes
81
+ ---------------
82
+
83
+ Most factory attributes can be added using static values that are evaluated when the factory is defined, but some attributes (such as associations and other attributes that must be dynamically generated) will need values assigned each time an instance is generated. These "lazy" attributes can be added by passing a block instead of a parameter:
84
+
85
+ factory :user do
86
+ # ...
87
+ activation_code { User.generate_activation_code }
88
+ end
89
+
90
+ Dependent Attributes
91
+ --------------------
92
+
93
+ Attributes can be based on the values of other attributes using the proxy that is yielded to lazy attribute blocks:
94
+
95
+ factory :user do
96
+ first_name 'Joe'
97
+ last_name 'Blow'
98
+ email { "#{first_name}.#{last_name}@example.com".downcase }
99
+ end
100
+
101
+ FactoryGirl.create(:user, :last_name => 'Doe').email
102
+ # => "joe.doe@example.com"
103
+
104
+ Associations
105
+ ------------
106
+
107
+ Associated instances can be generated by using the association method when
108
+ defining a lazy attribute:
109
+
110
+ factory :post do
111
+ # ...
112
+ author
113
+ end
114
+
115
+ You can also specify a different factory or override attributes:
116
+
117
+ factory :post do
118
+ # ...
119
+ association :author, :factory => :user, :last_name => 'Writely'
120
+ end
121
+
122
+ The behavior of the association method varies depending on the build strategy used for the parent object.
123
+
124
+ # Builds and saves a User and a Post
125
+ post = FactoryGirl.create(:post)
126
+ post.new_record? # => false
127
+ post.author.new_record # => false
128
+
129
+ # Builds and saves a User, and then builds but does not save a Post
130
+ post = FactoryGirl.build(:post)
131
+ post.new_record? # => true
132
+ post.author.new_record # => false
133
+
134
+ If the factory name is the same as the association name, the factory name can
135
+ be left out.
136
+
137
+ Inheritance
138
+ -----------
139
+
140
+ You can easily create multiple factories for the same class without repeating common attributes by using inheritance:
141
+
142
+ factory :post do
143
+ # the 'title' attribute is required for all posts
144
+ title 'A title'
145
+ end
146
+
147
+ factory :approved_post, :parent => :post do
148
+ approved true
149
+ # the 'approver' association is required for an approved post
150
+ association :approver, :factory => :user
151
+ end
152
+
153
+ Sequences
154
+ ---------
155
+
156
+ Unique values in a specific format (for example, e-mail addresses) can be
157
+ generated using sequences. Sequences are defined by calling sequence in a
158
+ definition block, and values in a sequence are generated by calling
159
+ Factory.next:
160
+
161
+ # Defines a new sequence
162
+ FactoryGirl.define do
163
+ sequence :email do |n|
164
+ "person#{n}@example.com"
165
+ end
166
+ end
167
+
168
+ Factory.next :email
169
+ # => "person1@example.com"
170
+
171
+ Factory.next :email
172
+ # => "person2@example.com"
173
+
174
+ Sequences can be used as attributes:
175
+
176
+ factory :user do
177
+ email
178
+ end
179
+
180
+ Or in lazy attributes:
181
+
182
+ factory :invite do
183
+ invitee { Factory.next(:email) }
184
+ end
185
+
186
+ And it's also possible to define an in-line sequence that is only used in
187
+ a particular factory:
188
+
189
+ factory :user do
190
+ sequence(:email) {|n| "person#{n}@example.com" }
191
+ end
192
+
193
+ Callbacks
194
+ ---------
195
+
196
+ Factory_girl makes available three callbacks for injecting some code:
197
+
198
+ * after_build - called after a factory is built (via FactoryGirl.build)
199
+ * after_create - called after a factory is saved (via FactoryGirl.create)
200
+ * after_stub - called after a factory is stubbed (via FactoryGirl.stub)
201
+
202
+ Examples:
203
+
204
+ # Define a factory that calls the generate_hashed_password method after it is built
205
+ factory :user do
206
+ after_build { |user| generate_hashed_password(user) }
207
+ end
208
+
209
+ Note that you'll have an instance of the user in the block. This can be useful.
210
+
211
+ You can also define multiple types of callbacks on the same factory:
212
+
213
+ factory :user do
214
+ after_build { |user| do_something_to(user) }
215
+ after_create { |user| do_something_else_to(user) }
216
+ end
217
+
218
+ Factories can also define any number of the same kind of callback. These callbacks will be executed in the order they are specified:
219
+
220
+ factory :user do
221
+ after_create { this_runs_first }
222
+ after_create { then_this }
223
+ end
224
+
225
+ Calling FactoryGirl.create will invoke both after_build and after_create callbacks.
226
+
227
+ Also, like standard attributes, child factories will inherit (and can also define) callbacks from their parent factory.
228
+
229
+ Alternate Syntaxes
230
+ ------------------
231
+
232
+ Users' tastes for syntax vary dramatically, but most users are looking for a common feature set. Because of this factory_girl supports "syntax layers" which provide alternate interfaces. See Factory::Syntax for information about the various layers available. For example, the Machinist-style syntax is popular:
233
+
234
+ require 'factory_girl/syntax/blueprint'
235
+ require 'factory_girl/syntax/make'
236
+ require 'factory_girl/syntax/sham'
237
+
238
+ Sham.email {|n| "#{n}@example.com" }
239
+
240
+ User.blueprint do
241
+ name { 'Billy Bob' }
242
+ email { Sham.email }
243
+ end
244
+
245
+ User.make(:name => 'Johnny')
246
+
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ gem "cucumber"
3
+ gem "rake"
4
+ gem "rspec", "~> 2.0"
5
+ gem "rcov"
6
+ gem "activerecord", :require => false
7
+ gem "rr"
8
+ gem "sqlite3-ruby", :require => false
9
+ gem "appraisal"
10
+ gem "yard"
11
+ gem "bluecloth"
12
+
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.1)
5
+ activesupport (= 3.0.1)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4.1)
8
+ activerecord (3.0.1)
9
+ activemodel (= 3.0.1)
10
+ activesupport (= 3.0.1)
11
+ arel (~> 1.0.0)
12
+ tzinfo (~> 0.3.23)
13
+ activesupport (3.0.1)
14
+ appraisal (0.1)
15
+ bundler
16
+ rake
17
+ arel (1.0.1)
18
+ activesupport (~> 3.0.0)
19
+ bluecloth (2.0.9)
20
+ builder (2.1.2)
21
+ cucumber (0.9.4)
22
+ builder (~> 2.1.2)
23
+ diff-lcs (~> 1.1.2)
24
+ gherkin (~> 2.2.9)
25
+ json (~> 1.4.6)
26
+ term-ansicolor (~> 1.0.5)
27
+ diff-lcs (1.1.2)
28
+ gherkin (2.2.9)
29
+ json (~> 1.4.6)
30
+ term-ansicolor (~> 1.0.5)
31
+ i18n (0.4.2)
32
+ json (1.4.6)
33
+ rake (0.8.7)
34
+ rcov (0.9.9)
35
+ rr (1.0.2)
36
+ rspec (2.1.0)
37
+ rspec-core (~> 2.1.0)
38
+ rspec-expectations (~> 2.1.0)
39
+ rspec-mocks (~> 2.1.0)
40
+ rspec-core (2.1.0)
41
+ rspec-expectations (2.1.0)
42
+ diff-lcs (~> 1.1.2)
43
+ rspec-mocks (2.1.0)
44
+ sqlite3-ruby (1.3.2)
45
+ term-ansicolor (1.0.5)
46
+ tzinfo (0.3.23)
47
+ yard (0.6.4)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ activerecord
54
+ appraisal
55
+ bluecloth
56
+ cucumber
57
+ rake
58
+ rcov
59
+ rr
60
+ rspec (~> 2.0)
61
+ sqlite3-ruby
62
+ yard
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008 Joe Ferris and thoughtbot, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ factory_girl
2
+ ============
3
+
4
+ factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
5
+
6
+ If you want to use factory_girl with Rails 3, see
7
+ [factory_girl_rails](http://github.com/thoughtbot/factory_girl_rails).
8
+
9
+ Documentation
10
+ -------------
11
+
12
+ You should find the documentation for your version of factory_girl on [Rubygems](http://rubygems.org/gems/factory_girl).
13
+
14
+ See {file:GETTING_STARTED.md} for information on defining and using factories.
15
+
16
+ Download
17
+ --------
18
+
19
+ [Github](http://github.com/thoughtbot/factory_girl/tree/master) or
20
+
21
+ Rubygems:
22
+ gem install factory_girl
23
+
24
+ More Information
25
+ ----------------
26
+
27
+ * [Rubygems](http://rubygems.org/gems/factory_girl)
28
+ * [Mailing list](http://groups.google.com/group/factory_girl)
29
+ * [Issues](http://github.com/thoughtbot/factory_girl/issues)
30
+ * [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](http://giantrobots.thoughtbot.com)
31
+
32
+ Contributing
33
+ ------------
34
+
35
+ Please read the contribution guidelines before submitting patches or pull requests.
36
+
37
+ Credits
38
+ -------
39
+
40
+ factory_girl was written by Joe Ferris with contributions from several authors, including:
41
+
42
+ * Alex Sharp
43
+ * Eugene Bolshakov
44
+ * Jon Yurek
45
+ * Josh Nichols
46
+ * Josh Owens
47
+ * Nate Sutton
48
+
49
+ The syntax layers are derived from software written by the following authors:
50
+
51
+ * Pete Yandell
52
+ * Rick Bradley
53
+ * Yossef Mendelssohn
54
+
55
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
56
+
57
+ factory_girl is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
58
+
59
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
60
+
61
+ License
62
+ -------
63
+
64
+ factory_girl is Copyright © 2008-2011 Joe Ferris and thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rake'
4
+ require 'rcov/rcovtask'
5
+ require 'date'
6
+ require 'rake/gempackagetask'
7
+ require 'rspec/core/rake_task'
8
+ require 'cucumber/rake/task'
9
+ require 'appraisal'
10
+ require 'yard'
11
+
12
+ desc 'Default: run the specs and features.'
13
+ task :default => 'spec:unit' do
14
+ system("rake -s appraisal spec:acceptance features;")
15
+ end
16
+
17
+ namespace :spec do
18
+ desc "Run unit specs"
19
+ RSpec::Core::RakeTask.new('unit') do |t|
20
+ t.pattern = 'spec/{*_spec.rb,factory_girl/**/*_spec.rb}'
21
+ end
22
+
23
+ desc "Run acceptance specs"
24
+ RSpec::Core::RakeTask.new('acceptance') do |t|
25
+ t.pattern = 'spec/acceptance/**/*_spec.rb'
26
+ end
27
+ end
28
+
29
+ desc "Run the unit and acceptance specs"
30
+ task :spec => ['spec:unit', 'spec:acceptance']
31
+
32
+ desc 'Performs code coverage on the factory_girl plugin.'
33
+ Rcov::RcovTask.new do |t|
34
+ t.test_files = FileList['spec/*_spec.rb']
35
+ t.verbose = true
36
+ end
37
+
38
+ desc "Clean files generated by rake tasks"
39
+ task :clobber => [:clobber_rcov]
40
+
41
+ Cucumber::Rake::Task.new(:features) do |t|
42
+ t.fork = true
43
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
44
+ end
45
+
46
+ eval("$specification = begin; #{IO.read('factory_girl.gemspec')}; end")
47
+ Rake::GemPackageTask.new($specification) do |package|
48
+ package.need_zip = true
49
+ package.need_tar = true
50
+ end
51
+
52
+ YARD::Rake::YardocTask.new do |t|
53
+ end
54
+
@@ -0,0 +1,151 @@
1
+ Feature: Use step definitions generated by factories
2
+
3
+ Scenario: create a post and verify its attributes
4
+ Given the following post exists:
5
+ | Title | Body |
6
+ | a fun title | here is the content |
7
+ Then I should find the following for the last post:
8
+ | title | body |
9
+ | a fun title | here is the content |
10
+
11
+ Scenario: create a post without a table and verify its attributes
12
+ Given a post exists with a title of "a fun title"
13
+ Then I should find the following for the last post:
14
+ | title |
15
+ | a fun title |
16
+
17
+ Scenario: flexible English when creating posts
18
+ Given an post exists with an title of "a fun title"
19
+ Then I should find the following for the last post:
20
+ | title |
21
+ | a fun title |
22
+
23
+ Scenario: create a post with an underscore in an attribute name
24
+ Given a post exists with an author ID of "5"
25
+ Then I should find the following for the last post:
26
+ | author_id |
27
+ | 5 |
28
+
29
+ Scenario: create several posts
30
+ Given the following posts exist:
31
+ | Title | Body |
32
+ | one | first |
33
+ | two | second |
34
+ | three | third |
35
+ Then I should find the following for the last post:
36
+ | title | body |
37
+ | three | third |
38
+ And there should be 3 posts
39
+
40
+ Scenario: create a post with a new author
41
+ Given the following post exists:
42
+ | Title | Author |
43
+ | a title | ID: 123 |
44
+ Then I should find the following for the last post:
45
+ | title | author_id |
46
+ | a title | 123 |
47
+ And I should find the following for the last user:
48
+ | id |
49
+ | 123 |
50
+
51
+ Scenario: create a post with an existing author
52
+ Given the following user exists:
53
+ | ID | Name |
54
+ | 123 | Joe |
55
+ And the following post exists:
56
+ | Title | Author |
57
+ | a title | Name: Joe |
58
+ Then I should find the following for the last post:
59
+ | title | author_id |
60
+ | a title | 123 |
61
+ And there should be 1 user
62
+
63
+ Scenario: create post with and without a category association
64
+ Given the following users exist:
65
+ | ID | Name |
66
+ | 123 | Joe |
67
+ And the following posts exist:
68
+ | Title | Author | Category |
69
+ | a title | Name: Joe | Name: programming |
70
+ | a title without a category | Name: Joe | |
71
+ Then I should find the following for the last post:
72
+ | title | category_id |
73
+ | a title without a category | |
74
+
75
+ Scenario: create a user without attributes
76
+ Given a user exists
77
+ Then there should be 1 user
78
+
79
+ Scenario: create several users without attributes
80
+ Given 3 users exist
81
+ Then there should be 3 users
82
+
83
+ Scenario: create several users with one attribute
84
+ Given 3 users exist with a name of "John"
85
+ Then there should be 3 users
86
+ And I should find the following for the last user:
87
+ | name |
88
+ | John |
89
+
90
+ Scenario: create instances of a factory with an underscore in its name
91
+ Given an admin user exists with a name of "John"
92
+ Then I should find the following for the last user:
93
+ | name | admin |
94
+ | John | true |
95
+
96
+ Scenario: create a several instances of a factory with an underscore in its name
97
+ Given 3 admin users exist
98
+ Then I should find the following for the last user:
99
+ | admin |
100
+ | true |
101
+
102
+ Scenario: use true values when creating instances
103
+ Given the following user exists:
104
+ | name | admin |
105
+ | Bill | true |
106
+ Then I should find the following for the last user:
107
+ | name | admin |
108
+ | Bill | true |
109
+
110
+ Scenario: use false values when creating instances
111
+ Given the following user exists:
112
+ | name | admin |
113
+ | Mike | false |
114
+ Then I should find the following for the last user:
115
+ | name | admin |
116
+ | Mike | false |
117
+
118
+ Scenario: Properly pluralize words
119
+ Given the following categories exist:
120
+ | name |
121
+ | Bed |
122
+ | Test Drive |
123
+ And 2 categories exist
124
+ And 2 categories exist with a name of "Future"
125
+ Then there should be 6 categories
126
+
127
+ Scenario: create a post with an existing category group
128
+ Given the following category exists:
129
+ | ID | name | category group |
130
+ | 123 | fiction | Name: books |
131
+ And the following post exists:
132
+ | Title | Author | Category |
133
+ | a title | Name: Joe | Category Group: Name: books |
134
+ Then I should find the following for the last post:
135
+ | title | category_id |
136
+ | a title | 123 |
137
+
138
+ Scenario: create a post with an existing category group and a new category
139
+ Given the following category group exists:
140
+ | ID | name |
141
+ | 456 | books |
142
+ And the following post exists:
143
+ | Title | Author | Category |
144
+ | a title | Name: Joe | Category Group: Name: books |
145
+ Then I should find the following for the last post:
146
+ | title |
147
+ | a title |
148
+ And I should find the following for the last category:
149
+ | category_group_id |
150
+ | 456 |
151
+
@@ -0,0 +1,20 @@
1
+ Then /^I should find the following for the last (.*):$/ do |model, table|
2
+ model_class = model.camelize.constantize
3
+ last_instance = model_class.last or raise "No #{model.pluralize} exist"
4
+ table.hashes.first.each do |key, value|
5
+ last_instance.attributes[key].to_s.should == value
6
+ end
7
+ end
8
+
9
+ Then /^there should be (\d+) (.*)$/ do |count, model|
10
+ model_class = model.singularize.camelize.constantize
11
+ model_class.count.should == count.to_i
12
+ end
13
+
14
+ Before do
15
+ Post.delete_all
16
+ User.delete_all
17
+ Category.delete_all
18
+ CategoryGroup.delete_all
19
+ end
20
+
@@ -0,0 +1,6 @@
1
+ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
2
+
3
+ $: << File.join(PROJECT_ROOT, 'lib')
4
+
5
+ require 'active_record'
6
+ require 'factory_girl'