factory_girl 4.5.0 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +25 -5
- data/Appraisals +11 -7
- data/CONTRIBUTING.md +44 -6
- data/GETTING_STARTED.md +175 -59
- data/Gemfile +5 -0
- data/Gemfile.lock +86 -63
- data/LICENSE +1 -1
- data/NEWS +12 -1
- data/README.md +21 -10
- data/Rakefile +1 -3
- data/factory_girl.gemspec +6 -14
- data/gemfiles/3.2.gemfile +4 -1
- data/gemfiles/3.2.gemfile.lock +84 -52
- data/gemfiles/4.0.gemfile +4 -1
- data/gemfiles/4.0.gemfile.lock +75 -49
- data/gemfiles/4.1.gemfile +4 -1
- data/gemfiles/4.1.gemfile.lock +78 -48
- data/gemfiles/4.2.gemfile +10 -0
- data/gemfiles/4.2.gemfile.lock +123 -0
- data/gemfiles/5.0.gemfile +10 -0
- data/gemfiles/5.0.gemfile.lock +126 -0
- data/lib/factory_girl.rb +13 -4
- data/lib/factory_girl/attribute/dynamic.rb +4 -1
- data/lib/factory_girl/attribute_assigner.rb +2 -2
- data/lib/factory_girl/configuration.rb +4 -0
- data/lib/factory_girl/decorator.rb +2 -2
- data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
- data/lib/factory_girl/definition_proxy.rb +2 -2
- data/lib/factory_girl/evaluator.rb +4 -0
- data/lib/factory_girl/factory_runner.rb +7 -1
- data/lib/factory_girl/find_definitions.rb +1 -1
- data/lib/factory_girl/linter.rb +65 -14
- data/lib/factory_girl/strategy/stub.rb +25 -1
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +4 -0
- data/lib/factory_girl/version.rb +1 -1
- metadata +26 -185
- data/features/find_definitions.feature +0 -75
- data/features/step_definitions/database_steps.rb +0 -9
- data/features/step_definitions/factory_girl_steps.rb +0 -36
- data/features/support/env.rb +0 -10
- data/features/support/factories.rb +0 -16
- data/gemfiles/3.1.gemfile +0 -7
- data/gemfiles/3.1.gemfile.lock +0 -91
- data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
- data/spec/acceptance/aliases_spec.rb +0 -19
- data/spec/acceptance/attribute_aliases_spec.rb +0 -45
- data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
- data/spec/acceptance/attributes_for_spec.rb +0 -97
- data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
- data/spec/acceptance/attributes_ordered_spec.rb +0 -51
- data/spec/acceptance/build_list_spec.rb +0 -56
- data/spec/acceptance/build_spec.rb +0 -86
- data/spec/acceptance/build_stubbed_spec.rb +0 -161
- data/spec/acceptance/callbacks_spec.rb +0 -253
- data/spec/acceptance/create_list_spec.rb +0 -97
- data/spec/acceptance/create_pair_spec.rb +0 -32
- data/spec/acceptance/create_spec.rb +0 -116
- data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
- data/spec/acceptance/defining_methods_inside_a_factory_spec.rb +0 -17
- data/spec/acceptance/definition_camel_string_spec.rb +0 -15
- data/spec/acceptance/definition_spec.rb +0 -21
- data/spec/acceptance/definition_without_block_spec.rb +0 -15
- data/spec/acceptance/global_initialize_with_spec.rb +0 -82
- data/spec/acceptance/global_to_create_spec.rb +0 -122
- data/spec/acceptance/initialize_with_spec.rb +0 -217
- data/spec/acceptance/keyed_by_class_spec.rb +0 -22
- data/spec/acceptance/lint_spec.rb +0 -65
- data/spec/acceptance/modify_factories_spec.rb +0 -184
- data/spec/acceptance/modify_inherited_spec.rb +0 -52
- data/spec/acceptance/nested_attributes_spec.rb +0 -32
- data/spec/acceptance/overrides_spec.rb +0 -61
- data/spec/acceptance/parent_spec.rb +0 -90
- data/spec/acceptance/private_attributes_spec.rb +0 -20
- data/spec/acceptance/register_strategies_spec.rb +0 -136
- data/spec/acceptance/sequence_context_spec.rb +0 -52
- data/spec/acceptance/sequence_spec.rb +0 -61
- data/spec/acceptance/skip_create_spec.rb +0 -19
- data/spec/acceptance/stub_spec.rb +0 -62
- data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -51
- data/spec/acceptance/traits_spec.rb +0 -727
- data/spec/acceptance/transient_attributes_spec.rb +0 -151
- data/spec/factory_girl/aliases_spec.rb +0 -31
- data/spec/factory_girl/attribute/association_spec.rb +0 -28
- data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
- data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
- data/spec/factory_girl/attribute/static_spec.rb +0 -19
- data/spec/factory_girl/attribute_list_spec.rb +0 -143
- data/spec/factory_girl/attribute_spec.rb +0 -16
- data/spec/factory_girl/callback_spec.rb +0 -41
- data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
- data/spec/factory_girl/declaration_list_spec.rb +0 -67
- data/spec/factory_girl/definition_proxy_spec.rb +0 -215
- data/spec/factory_girl/definition_spec.rb +0 -64
- data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
- data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
- data/spec/factory_girl/factory_spec.rb +0 -259
- data/spec/factory_girl/find_definitions_spec.rb +0 -110
- data/spec/factory_girl/null_factory_spec.rb +0 -13
- data/spec/factory_girl/null_object_spec.rb +0 -22
- data/spec/factory_girl/registry_spec.rb +0 -68
- data/spec/factory_girl/sequence_spec.rb +0 -95
- data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
- data/spec/factory_girl/strategy/build_spec.rb +0 -7
- data/spec/factory_girl/strategy/create_spec.rb +0 -25
- data/spec/factory_girl/strategy/stub_spec.rb +0 -38
- data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
- data/spec/factory_girl_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -26
- data/spec/support/macros/define_constant.rb +0 -86
- data/spec/support/matchers/callback.rb +0 -9
- data/spec/support/matchers/declaration.rb +0 -83
- data/spec/support/matchers/delegate.rb +0 -44
- data/spec/support/matchers/trait.rb +0 -11
- data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,217 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "initialize_with with non-FG attributes" do
|
4
|
-
include FactoryGirl::Syntax::Methods
|
5
|
-
|
6
|
-
before do
|
7
|
-
define_model("User", name: :string, age: :integer) do
|
8
|
-
def self.construct(name, age)
|
9
|
-
new(name: name, age: age)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
FactoryGirl.define do
|
14
|
-
factory :user do
|
15
|
-
initialize_with { User.construct("John Doe", 21) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
subject { build(:user) }
|
21
|
-
its(:name) { should eq "John Doe" }
|
22
|
-
its(:age) { should eq 21 }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "initialize_with with FG attributes that are transient" do
|
26
|
-
include FactoryGirl::Syntax::Methods
|
27
|
-
|
28
|
-
before do
|
29
|
-
define_model("User", name: :string) do
|
30
|
-
def self.construct(name)
|
31
|
-
new(name: "#{name} from .construct")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
FactoryGirl.define do
|
36
|
-
factory :user do
|
37
|
-
transient do
|
38
|
-
name { "Handsome Chap" }
|
39
|
-
end
|
40
|
-
|
41
|
-
initialize_with { User.construct(name) }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
subject { build(:user) }
|
47
|
-
its(:name) { should eq "Handsome Chap from .construct" }
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "initialize_with non-ORM-backed objects" do
|
51
|
-
include FactoryGirl::Syntax::Methods
|
52
|
-
|
53
|
-
before do
|
54
|
-
define_class("ReportGenerator") do
|
55
|
-
attr_reader :name, :data
|
56
|
-
|
57
|
-
def initialize(name, data)
|
58
|
-
@name = name
|
59
|
-
@data = data
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
FactoryGirl.define do
|
64
|
-
sequence(:random_data) { 5.times.map { Kernel.rand(200) } }
|
65
|
-
|
66
|
-
factory :report_generator do
|
67
|
-
transient do
|
68
|
-
name "My Awesome Report"
|
69
|
-
end
|
70
|
-
|
71
|
-
initialize_with { ReportGenerator.new(name, FactoryGirl.generate(:random_data)) }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it "allows for overrides" do
|
77
|
-
expect(build(:report_generator, name: "Overridden").name).to eq "Overridden"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "generates random data" do
|
81
|
-
expect(build(:report_generator).data.length).to eq 5
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "initialize_with parent and child factories" do
|
86
|
-
before do
|
87
|
-
define_class("Awesome") do
|
88
|
-
attr_reader :name
|
89
|
-
|
90
|
-
def initialize(name)
|
91
|
-
@name = name
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
FactoryGirl.define do
|
96
|
-
factory :awesome do
|
97
|
-
transient do
|
98
|
-
name "Great"
|
99
|
-
end
|
100
|
-
|
101
|
-
initialize_with { Awesome.new(name) }
|
102
|
-
|
103
|
-
factory :sub_awesome do
|
104
|
-
transient do
|
105
|
-
name "Sub"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
factory :super_awesome do
|
110
|
-
initialize_with { Awesome.new("Super") }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
it "uses the parent's constructor when the child factory doesn't assign it" do
|
117
|
-
expect(FactoryGirl.build(:sub_awesome).name).to eq "Sub"
|
118
|
-
end
|
119
|
-
|
120
|
-
it "allows child factories to override initialize_with" do
|
121
|
-
expect(FactoryGirl.build(:super_awesome).name).to eq "Super"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "initialize_with implicit constructor" do
|
126
|
-
before do
|
127
|
-
define_class("Awesome") do
|
128
|
-
attr_reader :name
|
129
|
-
|
130
|
-
def initialize(name)
|
131
|
-
@name = name
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
FactoryGirl.define do
|
136
|
-
factory :awesome do
|
137
|
-
transient do
|
138
|
-
name "Great"
|
139
|
-
end
|
140
|
-
|
141
|
-
initialize_with { new(name) }
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it "instantiates the correct object" do
|
147
|
-
expect(FactoryGirl.build(:awesome, name: "Awesome name").name).to eq "Awesome name"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "initialize_with doesn't duplicate assignment on attributes accessed from initialize_with" do
|
152
|
-
before do
|
153
|
-
define_class("User") do
|
154
|
-
attr_reader :name
|
155
|
-
attr_accessor :email
|
156
|
-
|
157
|
-
def initialize(name)
|
158
|
-
@name = name
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
FactoryGirl.define do
|
163
|
-
sequence(:email) { |n| "person#{n}@example.com" }
|
164
|
-
|
165
|
-
factory :user do
|
166
|
-
email
|
167
|
-
|
168
|
-
name { email.gsub(/\@.+/, "") }
|
169
|
-
|
170
|
-
initialize_with { new(name) }
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
it "instantiates the correct object" do
|
176
|
-
built_user = FactoryGirl.build(:user)
|
177
|
-
expect(built_user.name).to eq "person1"
|
178
|
-
expect(built_user.email).to eq "person1@example.com"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "initialize_with has access to all attributes for construction" do
|
183
|
-
before do
|
184
|
-
define_class("User") do
|
185
|
-
attr_reader :name, :email, :ignored
|
186
|
-
|
187
|
-
def initialize(attributes = {})
|
188
|
-
@name = attributes[:name]
|
189
|
-
@email = attributes[:email]
|
190
|
-
@ignored = attributes[:ignored]
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
FactoryGirl.define do
|
195
|
-
sequence(:email) { |n| "person#{n}@example.com" }
|
196
|
-
|
197
|
-
factory :user do
|
198
|
-
transient do
|
199
|
-
ignored "of course!"
|
200
|
-
end
|
201
|
-
|
202
|
-
email
|
203
|
-
|
204
|
-
name { email.gsub(/\@.+/, "") }
|
205
|
-
|
206
|
-
initialize_with { new(attributes) }
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
it "assigns attributes correctly" do
|
212
|
-
user_with_attributes = FactoryGirl.build(:user)
|
213
|
-
expect(user_with_attributes.email).to eq "person1@example.com"
|
214
|
-
expect(user_with_attributes.name).to eq "person1"
|
215
|
-
expect(user_with_attributes.ignored).to be_nil
|
216
|
-
end
|
217
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'finding factories keyed by class instead of symbol' do
|
4
|
-
before do
|
5
|
-
define_model("User") do
|
6
|
-
attr_accessor :name, :email
|
7
|
-
end
|
8
|
-
|
9
|
-
FactoryGirl.define do
|
10
|
-
factory :user do
|
11
|
-
name 'John Doe'
|
12
|
-
sequence(:email) { |n| "person#{n}@example.com" }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'allows interaction based on class name' do
|
18
|
-
user = FactoryGirl.create User, email: 'person@example.com'
|
19
|
-
expect(user.email).to eq 'person@example.com'
|
20
|
-
expect(user.name).to eq 'John Doe'
|
21
|
-
end
|
22
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'FactoryGirl.lint' do
|
4
|
-
it 'raises when a factory is invalid' do
|
5
|
-
define_model 'User', name: :string do
|
6
|
-
validates :name, presence: true
|
7
|
-
end
|
8
|
-
|
9
|
-
define_model 'AlwaysValid'
|
10
|
-
|
11
|
-
FactoryGirl.define do
|
12
|
-
factory :user do
|
13
|
-
factory :admin_user
|
14
|
-
end
|
15
|
-
|
16
|
-
factory :always_valid
|
17
|
-
end
|
18
|
-
|
19
|
-
error_message = <<-ERROR_MESSAGE.strip
|
20
|
-
The following factories are invalid:
|
21
|
-
|
22
|
-
* user - Validation failed: Name can't be blank (ActiveRecord::RecordInvalid)
|
23
|
-
* admin_user - Validation failed: Name can't be blank (ActiveRecord::RecordInvalid)
|
24
|
-
ERROR_MESSAGE
|
25
|
-
|
26
|
-
expect do
|
27
|
-
FactoryGirl.lint
|
28
|
-
end.to raise_error FactoryGirl::InvalidFactoryError, error_message
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'does not raise when all factories are valid' do
|
32
|
-
define_model 'User', name: :string do
|
33
|
-
validates :name, presence: true
|
34
|
-
end
|
35
|
-
|
36
|
-
FactoryGirl.define do
|
37
|
-
factory :user do
|
38
|
-
name 'assigned'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
expect { FactoryGirl.lint }.not_to raise_error
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'allows for selective linting' do
|
46
|
-
define_model 'InvalidThing', name: :string do
|
47
|
-
validates :name, presence: true
|
48
|
-
end
|
49
|
-
|
50
|
-
define_model 'ValidThing', name: :string
|
51
|
-
|
52
|
-
FactoryGirl.define do
|
53
|
-
factory :valid_thing
|
54
|
-
factory :invalid_thing
|
55
|
-
end
|
56
|
-
|
57
|
-
expect do
|
58
|
-
only_valid_factories = FactoryGirl.factories.reject do |factory|
|
59
|
-
factory.name =~ /invalid/
|
60
|
-
end
|
61
|
-
|
62
|
-
FactoryGirl.lint only_valid_factories
|
63
|
-
end.not_to raise_error
|
64
|
-
end
|
65
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "modifying factories" do
|
4
|
-
include FactoryGirl::Syntax::Methods
|
5
|
-
|
6
|
-
before do
|
7
|
-
define_model('User', name: :string, admin: :boolean, email: :string, login: :string)
|
8
|
-
|
9
|
-
FactoryGirl.define do
|
10
|
-
sequence(:email) { |n| "user#{n}@example.com" }
|
11
|
-
|
12
|
-
factory :user do
|
13
|
-
email
|
14
|
-
|
15
|
-
after(:create) do |user|
|
16
|
-
user.login = user.name.upcase if user.name
|
17
|
-
end
|
18
|
-
|
19
|
-
factory :admin do
|
20
|
-
admin true
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "simple modification" do
|
27
|
-
before do
|
28
|
-
FactoryGirl.modify do
|
29
|
-
factory :user do
|
30
|
-
name "Great User"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
subject { create(:user) }
|
36
|
-
its(:name) { should eq "Great User" }
|
37
|
-
its(:login) { should eq "GREAT USER" }
|
38
|
-
|
39
|
-
it "doesn't allow the factory to be subsequently defined" do
|
40
|
-
expect do
|
41
|
-
FactoryGirl.define { factory :user }
|
42
|
-
end.to raise_error(FactoryGirl::DuplicateDefinitionError, "Factory already registered: user")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "does allow the factory to be subsequently modified" do
|
46
|
-
FactoryGirl.modify do
|
47
|
-
factory :user do
|
48
|
-
name "Overridden again!"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
expect(create(:user).name).to eq "Overridden again!"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "adding callbacks" do
|
57
|
-
before do
|
58
|
-
FactoryGirl.modify do
|
59
|
-
factory :user do
|
60
|
-
name "Great User"
|
61
|
-
after(:create) do |user|
|
62
|
-
user.name = user.name.downcase
|
63
|
-
user.login = nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
subject { create(:user) }
|
70
|
-
|
71
|
-
its(:name) { should eq "great user" }
|
72
|
-
its(:login) { should be_nil }
|
73
|
-
end
|
74
|
-
|
75
|
-
context "reusing traits" do
|
76
|
-
before do
|
77
|
-
FactoryGirl.define do
|
78
|
-
trait :rockstar do
|
79
|
-
name "Johnny Rockstar!!!"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
FactoryGirl.modify do
|
84
|
-
factory :user do
|
85
|
-
rockstar
|
86
|
-
email { "#{name}@example.com" }
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
subject { create(:user) }
|
92
|
-
|
93
|
-
its(:name) { should eq "Johnny Rockstar!!!" }
|
94
|
-
its(:email) { should eq "Johnny Rockstar!!!@example.com" }
|
95
|
-
its(:login) { should eq "JOHNNY ROCKSTAR!!!" }
|
96
|
-
end
|
97
|
-
|
98
|
-
context "redefining attributes" do
|
99
|
-
before do
|
100
|
-
FactoryGirl.modify do
|
101
|
-
factory :user do
|
102
|
-
email { "#{name}-modified@example.com" }
|
103
|
-
name "Great User"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "creating user" do
|
109
|
-
context "without overrides" do
|
110
|
-
subject { create(:user) }
|
111
|
-
|
112
|
-
its(:name) { should eq "Great User" }
|
113
|
-
its(:email) { should eq "Great User-modified@example.com" }
|
114
|
-
end
|
115
|
-
|
116
|
-
context "overriding dynamic attributes" do
|
117
|
-
subject { create(:user, email: "perfect@example.com") }
|
118
|
-
|
119
|
-
its(:name) { should eq "Great User" }
|
120
|
-
its(:email) { should eq "perfect@example.com" }
|
121
|
-
end
|
122
|
-
|
123
|
-
context "overriding static attributes" do
|
124
|
-
subject { create(:user, name: "wonderful") }
|
125
|
-
|
126
|
-
its(:name) { should eq "wonderful" }
|
127
|
-
its(:email) { should eq "wonderful-modified@example.com" }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context "creating admin" do
|
132
|
-
context "without overrides" do
|
133
|
-
subject { create(:admin) }
|
134
|
-
|
135
|
-
its(:name) { should eq "Great User" }
|
136
|
-
its(:email) { should eq "Great User-modified@example.com" }
|
137
|
-
its(:admin) { should be_true }
|
138
|
-
end
|
139
|
-
|
140
|
-
context "overriding dynamic attributes" do
|
141
|
-
subject { create(:admin, email: "perfect@example.com") }
|
142
|
-
|
143
|
-
its(:name) { should eq "Great User" }
|
144
|
-
its(:email) { should eq "perfect@example.com" }
|
145
|
-
its(:admin) { should be_true }
|
146
|
-
end
|
147
|
-
|
148
|
-
context "overriding static attributes" do
|
149
|
-
subject { create(:admin, name: "wonderful") }
|
150
|
-
|
151
|
-
its(:name) { should eq "wonderful" }
|
152
|
-
its(:email) { should eq "wonderful-modified@example.com" }
|
153
|
-
its(:admin) { should be_true }
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
it "doesn't overwrite already defined child's attributes" do
|
159
|
-
FactoryGirl.modify do
|
160
|
-
factory :user do
|
161
|
-
admin false
|
162
|
-
end
|
163
|
-
end
|
164
|
-
expect(create(:admin)).to be_admin
|
165
|
-
end
|
166
|
-
|
167
|
-
it "allows for overriding child classes" do
|
168
|
-
FactoryGirl.modify do
|
169
|
-
factory :admin do
|
170
|
-
admin false
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
expect(create(:admin)).not_to be_admin
|
175
|
-
end
|
176
|
-
|
177
|
-
it "raises an exception if the factory was not defined before" do
|
178
|
-
expect {
|
179
|
-
FactoryGirl.modify do
|
180
|
-
factory :unknown_factory
|
181
|
-
end
|
182
|
-
}.to raise_error(ArgumentError)
|
183
|
-
end
|
184
|
-
end
|