factory_girl 4.2.0 → 4.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +29 -7
- data/.yardopts +1 -1
- data/Appraisals +12 -8
- data/CONTRIBUTING.md +60 -0
- data/GETTING_STARTED.md +473 -191
- data/Gemfile +6 -3
- data/Gemfile.lock +93 -65
- data/LICENSE +1 -1
- data/NAME.md +11 -0
- data/NEWS +43 -1
- data/README.md +52 -28
- data/Rakefile +1 -3
- data/factory_girl.gemspec +9 -17
- data/gemfiles/3.2.gemfile +6 -3
- data/gemfiles/3.2.gemfile.lock +85 -62
- data/gemfiles/4.0.gemfile +6 -3
- data/gemfiles/4.0.gemfile.lock +84 -74
- data/gemfiles/4.1.gemfile +10 -0
- data/gemfiles/4.1.gemfile.lock +104 -0
- data/gemfiles/4.2.gemfile +10 -0
- data/gemfiles/4.2.gemfile.lock +104 -0
- data/gemfiles/5.0.gemfile +10 -0
- data/gemfiles/5.0.gemfile.lock +103 -0
- data/lib/factory_girl/attribute/dynamic.rb +4 -1
- data/lib/factory_girl/attribute_assigner.rb +4 -4
- data/lib/factory_girl/attribute_list.rb +1 -1
- data/lib/factory_girl/callback.rb +1 -1
- data/lib/factory_girl/callbacks_observer.rb +1 -1
- data/lib/factory_girl/configuration.rb +7 -2
- data/lib/factory_girl/declaration_list.rb +2 -2
- data/lib/factory_girl/decorator/attribute_hash.rb +1 -2
- data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
- data/lib/factory_girl/decorator.rb +2 -2
- data/lib/factory_girl/definition.rb +25 -15
- data/lib/factory_girl/definition_hierarchy.rb +1 -1
- data/lib/factory_girl/definition_proxy.rb +15 -17
- data/lib/factory_girl/errors.rb +6 -0
- data/lib/factory_girl/evaluator.rb +7 -1
- data/lib/factory_girl/factory.rb +3 -3
- data/lib/factory_girl/factory_runner.rb +7 -1
- data/lib/factory_girl/find_definitions.rb +3 -3
- data/lib/factory_girl/linter.rb +97 -0
- data/lib/factory_girl/strategy/stub.rb +58 -20
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +17 -0
- data/lib/factory_girl/syntax/default.rb +8 -0
- data/lib/factory_girl/syntax/methods.rb +18 -2
- data/lib/factory_girl/version.rb +1 -1
- data/lib/factory_girl.rb +30 -3
- metadata +65 -249
- data/CONTRIBUTION_GUIDELINES.md +0 -10
- 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.0.gemfile +0 -7
- data/gemfiles/3.0.gemfile.lock +0 -81
- data/gemfiles/3.1.gemfile +0 -7
- data/gemfiles/3.1.gemfile.lock +0 -82
- 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 -177
- data/spec/acceptance/create_list_spec.rb +0 -97
- data/spec/acceptance/create_spec.rb +0 -116
- data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
- 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/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/register_strategies_spec.rb +0 -128
- 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 -41
- data/spec/acceptance/traits_spec.rb +0 -727
- data/spec/acceptance/transient_attributes_spec.rb +0 -124
- 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 -58
- 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 -9
- data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,44 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :delegate do |delegated_method|
|
2
|
-
chain :to do |target_method|
|
3
|
-
@target_method = target_method
|
4
|
-
end
|
5
|
-
|
6
|
-
chain :as do |method_on_target|
|
7
|
-
@method_on_target = method_on_target
|
8
|
-
end
|
9
|
-
|
10
|
-
chain :with_arguments do |args|
|
11
|
-
@args = args
|
12
|
-
end
|
13
|
-
|
14
|
-
match do |instance|
|
15
|
-
extend Mocha::API
|
16
|
-
|
17
|
-
@instance = instance
|
18
|
-
@args ||= []
|
19
|
-
return_value = 'stubbed return value'
|
20
|
-
method_on_target = @method_on_target || delegated_method
|
21
|
-
stubbed_target = stub('stubbed_target', method_on_target => return_value)
|
22
|
-
@instance.stubs(@target_method => stubbed_target)
|
23
|
-
begin
|
24
|
-
@instance.send(delegated_method, *@args) == return_value
|
25
|
-
rescue NoMethodError
|
26
|
-
false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
failure_message_for_should do
|
31
|
-
if Class === @instance
|
32
|
-
message = "expected #{@instance.name} "
|
33
|
-
prefix = '.'
|
34
|
-
else
|
35
|
-
message = "expected #{@instance.class.name} "
|
36
|
-
prefix = '#'
|
37
|
-
end
|
38
|
-
message << "to delegate #{prefix}#{delegated_method} to #{prefix}#{@target_method}"
|
39
|
-
if @method_on_target
|
40
|
-
message << ".#{@method_on_target}"
|
41
|
-
end
|
42
|
-
message
|
43
|
-
end
|
44
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
shared_examples_for "strategy without association support" do
|
2
|
-
let(:factory) { stub("associate_factory") }
|
3
|
-
let(:attribute) { FactoryGirl::Attribute::Association.new(:user, :user, {}) }
|
4
|
-
|
5
|
-
def association_named(name, overrides)
|
6
|
-
runner = FactoryGirl::FactoryRunner.new(name, :build, [overrides])
|
7
|
-
subject.association(runner)
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
FactoryGirl.stubs(factory_by_name: factory)
|
12
|
-
factory.stubs(:compile)
|
13
|
-
factory.stubs(:run)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns nil when accessing an association" do
|
17
|
-
expect(association_named(:user, {})).to be_nil
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
shared_examples_for "strategy with association support" do |factory_girl_strategy_name|
|
22
|
-
let(:factory) { stub("associate_factory") }
|
23
|
-
|
24
|
-
def association_named(name, strategy, overrides)
|
25
|
-
runner = FactoryGirl::FactoryRunner.new(name, strategy, [overrides])
|
26
|
-
subject.association(runner)
|
27
|
-
end
|
28
|
-
|
29
|
-
before do
|
30
|
-
FactoryGirl.stubs(factory_by_name: factory)
|
31
|
-
factory.stubs(:compile)
|
32
|
-
factory.stubs(:run)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "runs the factory with the correct overrides" do
|
36
|
-
association_named(:author, factory_girl_strategy_name, great: "value")
|
37
|
-
expect(factory).to have_received(:run).with(factory_girl_strategy_name, great: "value")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "finds the factory with the correct factory name" do
|
41
|
-
association_named(:author, factory_girl_strategy_name, great: "value")
|
42
|
-
expect(FactoryGirl).to have_received(:factory_by_name).with(:author)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_name|
|
47
|
-
let(:factory) { stub("associate_factory") }
|
48
|
-
|
49
|
-
def association_named(name, overrides)
|
50
|
-
runner = FactoryGirl::FactoryRunner.new(name, overrides[:strategy], [overrides.except(:strategy)])
|
51
|
-
subject.association(runner)
|
52
|
-
end
|
53
|
-
|
54
|
-
before do
|
55
|
-
FactoryGirl.stubs(factory_by_name: factory)
|
56
|
-
factory.stubs(:compile)
|
57
|
-
factory.stubs(:run)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "runs the factory with the correct overrides" do
|
61
|
-
association_named(:author, strategy: :build, great: "value")
|
62
|
-
expect(factory).to have_received(:run).with(factory_girl_strategy_name, { great: "value" })
|
63
|
-
end
|
64
|
-
|
65
|
-
it "finds the factory with the correct factory name" do
|
66
|
-
association_named(:author, strategy: :build, great: "value")
|
67
|
-
expect(FactoryGirl).to have_received(:factory_by_name).with(:author)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
shared_examples_for "strategy with callbacks" do |*callback_names|
|
72
|
-
let(:result_instance) do
|
73
|
-
define_class("ResultInstance") do
|
74
|
-
attr_accessor :id
|
75
|
-
end.new
|
76
|
-
end
|
77
|
-
|
78
|
-
let(:evaluation) { stub("evaluation", object: result_instance, notify: true, create: nil) }
|
79
|
-
|
80
|
-
it "runs the callbacks #{callback_names} with the evaluation's object" do
|
81
|
-
subject.result(evaluation)
|
82
|
-
callback_names.each do |name|
|
83
|
-
expect(evaluation).to have_received(:notify).with(name, evaluation.object)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it "returns the object from the evaluation" do
|
88
|
-
expect(subject.result(evaluation)).to eq evaluation.object
|
89
|
-
end
|
90
|
-
end
|