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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +25 -5
  3. data/Appraisals +11 -7
  4. data/CONTRIBUTING.md +44 -6
  5. data/GETTING_STARTED.md +175 -59
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +86 -63
  8. data/LICENSE +1 -1
  9. data/NEWS +12 -1
  10. data/README.md +21 -10
  11. data/Rakefile +1 -3
  12. data/factory_girl.gemspec +6 -14
  13. data/gemfiles/3.2.gemfile +4 -1
  14. data/gemfiles/3.2.gemfile.lock +84 -52
  15. data/gemfiles/4.0.gemfile +4 -1
  16. data/gemfiles/4.0.gemfile.lock +75 -49
  17. data/gemfiles/4.1.gemfile +4 -1
  18. data/gemfiles/4.1.gemfile.lock +78 -48
  19. data/gemfiles/4.2.gemfile +10 -0
  20. data/gemfiles/4.2.gemfile.lock +123 -0
  21. data/gemfiles/5.0.gemfile +10 -0
  22. data/gemfiles/5.0.gemfile.lock +126 -0
  23. data/lib/factory_girl.rb +13 -4
  24. data/lib/factory_girl/attribute/dynamic.rb +4 -1
  25. data/lib/factory_girl/attribute_assigner.rb +2 -2
  26. data/lib/factory_girl/configuration.rb +4 -0
  27. data/lib/factory_girl/decorator.rb +2 -2
  28. data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
  29. data/lib/factory_girl/definition_proxy.rb +2 -2
  30. data/lib/factory_girl/evaluator.rb +4 -0
  31. data/lib/factory_girl/factory_runner.rb +7 -1
  32. data/lib/factory_girl/find_definitions.rb +1 -1
  33. data/lib/factory_girl/linter.rb +65 -14
  34. data/lib/factory_girl/strategy/stub.rb +25 -1
  35. data/lib/factory_girl/strategy_syntax_method_registrar.rb +4 -0
  36. data/lib/factory_girl/version.rb +1 -1
  37. metadata +26 -185
  38. data/features/find_definitions.feature +0 -75
  39. data/features/step_definitions/database_steps.rb +0 -9
  40. data/features/step_definitions/factory_girl_steps.rb +0 -36
  41. data/features/support/env.rb +0 -10
  42. data/features/support/factories.rb +0 -16
  43. data/gemfiles/3.1.gemfile +0 -7
  44. data/gemfiles/3.1.gemfile.lock +0 -91
  45. data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
  46. data/spec/acceptance/aliases_spec.rb +0 -19
  47. data/spec/acceptance/attribute_aliases_spec.rb +0 -45
  48. data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
  49. data/spec/acceptance/attributes_for_spec.rb +0 -97
  50. data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
  51. data/spec/acceptance/attributes_ordered_spec.rb +0 -51
  52. data/spec/acceptance/build_list_spec.rb +0 -56
  53. data/spec/acceptance/build_spec.rb +0 -86
  54. data/spec/acceptance/build_stubbed_spec.rb +0 -161
  55. data/spec/acceptance/callbacks_spec.rb +0 -253
  56. data/spec/acceptance/create_list_spec.rb +0 -97
  57. data/spec/acceptance/create_pair_spec.rb +0 -32
  58. data/spec/acceptance/create_spec.rb +0 -116
  59. data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
  60. data/spec/acceptance/defining_methods_inside_a_factory_spec.rb +0 -17
  61. data/spec/acceptance/definition_camel_string_spec.rb +0 -15
  62. data/spec/acceptance/definition_spec.rb +0 -21
  63. data/spec/acceptance/definition_without_block_spec.rb +0 -15
  64. data/spec/acceptance/global_initialize_with_spec.rb +0 -82
  65. data/spec/acceptance/global_to_create_spec.rb +0 -122
  66. data/spec/acceptance/initialize_with_spec.rb +0 -217
  67. data/spec/acceptance/keyed_by_class_spec.rb +0 -22
  68. data/spec/acceptance/lint_spec.rb +0 -65
  69. data/spec/acceptance/modify_factories_spec.rb +0 -184
  70. data/spec/acceptance/modify_inherited_spec.rb +0 -52
  71. data/spec/acceptance/nested_attributes_spec.rb +0 -32
  72. data/spec/acceptance/overrides_spec.rb +0 -61
  73. data/spec/acceptance/parent_spec.rb +0 -90
  74. data/spec/acceptance/private_attributes_spec.rb +0 -20
  75. data/spec/acceptance/register_strategies_spec.rb +0 -136
  76. data/spec/acceptance/sequence_context_spec.rb +0 -52
  77. data/spec/acceptance/sequence_spec.rb +0 -61
  78. data/spec/acceptance/skip_create_spec.rb +0 -19
  79. data/spec/acceptance/stub_spec.rb +0 -62
  80. data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -51
  81. data/spec/acceptance/traits_spec.rb +0 -727
  82. data/spec/acceptance/transient_attributes_spec.rb +0 -151
  83. data/spec/factory_girl/aliases_spec.rb +0 -31
  84. data/spec/factory_girl/attribute/association_spec.rb +0 -28
  85. data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
  86. data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
  87. data/spec/factory_girl/attribute/static_spec.rb +0 -19
  88. data/spec/factory_girl/attribute_list_spec.rb +0 -143
  89. data/spec/factory_girl/attribute_spec.rb +0 -16
  90. data/spec/factory_girl/callback_spec.rb +0 -41
  91. data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
  92. data/spec/factory_girl/declaration_list_spec.rb +0 -67
  93. data/spec/factory_girl/definition_proxy_spec.rb +0 -215
  94. data/spec/factory_girl/definition_spec.rb +0 -64
  95. data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
  96. data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
  97. data/spec/factory_girl/factory_spec.rb +0 -259
  98. data/spec/factory_girl/find_definitions_spec.rb +0 -110
  99. data/spec/factory_girl/null_factory_spec.rb +0 -13
  100. data/spec/factory_girl/null_object_spec.rb +0 -22
  101. data/spec/factory_girl/registry_spec.rb +0 -68
  102. data/spec/factory_girl/sequence_spec.rb +0 -95
  103. data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
  104. data/spec/factory_girl/strategy/build_spec.rb +0 -7
  105. data/spec/factory_girl/strategy/create_spec.rb +0 -25
  106. data/spec/factory_girl/strategy/stub_spec.rb +0 -38
  107. data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
  108. data/spec/factory_girl_spec.rb +0 -22
  109. data/spec/spec_helper.rb +0 -26
  110. data/spec/support/macros/define_constant.rb +0 -86
  111. data/spec/support/matchers/callback.rb +0 -9
  112. data/spec/support/matchers/declaration.rb +0 -83
  113. data/spec/support/matchers/delegate.rb +0 -44
  114. data/spec/support/matchers/trait.rb +0 -11
  115. data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,9 +0,0 @@
1
- RSpec::Matchers.define :have_callback do |callback_name|
2
- match do |instance|
3
- instance.callbacks.include?(FactoryGirl::Callback.new(callback_name, @block))
4
- end
5
-
6
- chain :with_block do |block|
7
- @block = block
8
- end
9
- end
@@ -1,83 +0,0 @@
1
- module DeclarationMatchers
2
- def have_static_declaration(name)
3
- DeclarationMatcher.new(:static).named(name)
4
- end
5
-
6
- def have_dynamic_declaration(name)
7
- DeclarationMatcher.new(:dynamic).named(name)
8
- end
9
-
10
- def have_association_declaration(name)
11
- DeclarationMatcher.new(:association).named(name)
12
- end
13
-
14
- def have_implicit_declaration(name)
15
- DeclarationMatcher.new(:implicit).named(name)
16
- end
17
-
18
- class DeclarationMatcher
19
- def initialize(declaration_type)
20
- @declaration_type = declaration_type
21
- end
22
-
23
- def matches?(subject)
24
- subject.declarations.include?(expected_declaration)
25
- end
26
-
27
- def named(name)
28
- @name = name
29
- self
30
- end
31
-
32
- def ignored
33
- @ignored = true
34
- self
35
- end
36
-
37
- def with_value(value)
38
- @value = value
39
- self
40
- end
41
-
42
- def with_factory(factory)
43
- @factory = factory
44
- self
45
- end
46
-
47
- def with_options(options)
48
- @options = options
49
- self
50
- end
51
-
52
- def failure_message
53
- [
54
- "expected declarations to include declaration of type #{@declaration_type}",
55
- @options ? "with options #{options}" : nil
56
- ].compact.join ' '
57
- end
58
-
59
- private
60
-
61
- def expected_declaration
62
- case @declaration_type
63
- when :static then FactoryGirl::Declaration::Static.new(@name, @value, ignored?)
64
- when :dynamic then FactoryGirl::Declaration::Dynamic.new(@name, ignored?, @value)
65
- when :implicit then FactoryGirl::Declaration::Implicit.new(@name, @factory, ignored?)
66
- when :association
67
- if @options
68
- FactoryGirl::Declaration::Association.new(@name, options)
69
- else
70
- FactoryGirl::Declaration::Association.new(@name)
71
- end
72
- end
73
- end
74
-
75
- def ignored?
76
- !!@ignored
77
- end
78
-
79
- def options
80
- @options || {}
81
- end
82
- end
83
- end
@@ -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,11 +0,0 @@
1
- RSpec::Matchers.define :have_trait do |trait_name|
2
- match do |instance|
3
- instance.defined_traits.any? do |trait|
4
- trait.name == trait_name && trait.send(:block) == @block
5
- end
6
- end
7
-
8
- chain :with_block do |block|
9
- @block = block
10
- end
11
- 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