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.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +29 -7
  3. data/.yardopts +1 -1
  4. data/Appraisals +12 -8
  5. data/CONTRIBUTING.md +60 -0
  6. data/GETTING_STARTED.md +473 -191
  7. data/Gemfile +6 -3
  8. data/Gemfile.lock +93 -65
  9. data/LICENSE +1 -1
  10. data/NAME.md +11 -0
  11. data/NEWS +43 -1
  12. data/README.md +52 -28
  13. data/Rakefile +1 -3
  14. data/factory_girl.gemspec +9 -17
  15. data/gemfiles/3.2.gemfile +6 -3
  16. data/gemfiles/3.2.gemfile.lock +85 -62
  17. data/gemfiles/4.0.gemfile +6 -3
  18. data/gemfiles/4.0.gemfile.lock +84 -74
  19. data/gemfiles/4.1.gemfile +10 -0
  20. data/gemfiles/4.1.gemfile.lock +104 -0
  21. data/gemfiles/4.2.gemfile +10 -0
  22. data/gemfiles/4.2.gemfile.lock +104 -0
  23. data/gemfiles/5.0.gemfile +10 -0
  24. data/gemfiles/5.0.gemfile.lock +103 -0
  25. data/lib/factory_girl/attribute/dynamic.rb +4 -1
  26. data/lib/factory_girl/attribute_assigner.rb +4 -4
  27. data/lib/factory_girl/attribute_list.rb +1 -1
  28. data/lib/factory_girl/callback.rb +1 -1
  29. data/lib/factory_girl/callbacks_observer.rb +1 -1
  30. data/lib/factory_girl/configuration.rb +7 -2
  31. data/lib/factory_girl/declaration_list.rb +2 -2
  32. data/lib/factory_girl/decorator/attribute_hash.rb +1 -2
  33. data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
  34. data/lib/factory_girl/decorator.rb +2 -2
  35. data/lib/factory_girl/definition.rb +25 -15
  36. data/lib/factory_girl/definition_hierarchy.rb +1 -1
  37. data/lib/factory_girl/definition_proxy.rb +15 -17
  38. data/lib/factory_girl/errors.rb +6 -0
  39. data/lib/factory_girl/evaluator.rb +7 -1
  40. data/lib/factory_girl/factory.rb +3 -3
  41. data/lib/factory_girl/factory_runner.rb +7 -1
  42. data/lib/factory_girl/find_definitions.rb +3 -3
  43. data/lib/factory_girl/linter.rb +97 -0
  44. data/lib/factory_girl/strategy/stub.rb +58 -20
  45. data/lib/factory_girl/strategy_syntax_method_registrar.rb +17 -0
  46. data/lib/factory_girl/syntax/default.rb +8 -0
  47. data/lib/factory_girl/syntax/methods.rb +18 -2
  48. data/lib/factory_girl/version.rb +1 -1
  49. data/lib/factory_girl.rb +30 -3
  50. metadata +65 -249
  51. data/CONTRIBUTION_GUIDELINES.md +0 -10
  52. data/features/find_definitions.feature +0 -75
  53. data/features/step_definitions/database_steps.rb +0 -9
  54. data/features/step_definitions/factory_girl_steps.rb +0 -36
  55. data/features/support/env.rb +0 -10
  56. data/features/support/factories.rb +0 -16
  57. data/gemfiles/3.0.gemfile +0 -7
  58. data/gemfiles/3.0.gemfile.lock +0 -81
  59. data/gemfiles/3.1.gemfile +0 -7
  60. data/gemfiles/3.1.gemfile.lock +0 -82
  61. data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
  62. data/spec/acceptance/aliases_spec.rb +0 -19
  63. data/spec/acceptance/attribute_aliases_spec.rb +0 -45
  64. data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
  65. data/spec/acceptance/attributes_for_spec.rb +0 -97
  66. data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
  67. data/spec/acceptance/attributes_ordered_spec.rb +0 -51
  68. data/spec/acceptance/build_list_spec.rb +0 -56
  69. data/spec/acceptance/build_spec.rb +0 -86
  70. data/spec/acceptance/build_stubbed_spec.rb +0 -161
  71. data/spec/acceptance/callbacks_spec.rb +0 -177
  72. data/spec/acceptance/create_list_spec.rb +0 -97
  73. data/spec/acceptance/create_spec.rb +0 -116
  74. data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
  75. data/spec/acceptance/definition_spec.rb +0 -21
  76. data/spec/acceptance/definition_without_block_spec.rb +0 -15
  77. data/spec/acceptance/global_initialize_with_spec.rb +0 -82
  78. data/spec/acceptance/global_to_create_spec.rb +0 -122
  79. data/spec/acceptance/initialize_with_spec.rb +0 -217
  80. data/spec/acceptance/keyed_by_class_spec.rb +0 -22
  81. data/spec/acceptance/modify_factories_spec.rb +0 -184
  82. data/spec/acceptance/modify_inherited_spec.rb +0 -52
  83. data/spec/acceptance/nested_attributes_spec.rb +0 -32
  84. data/spec/acceptance/overrides_spec.rb +0 -61
  85. data/spec/acceptance/parent_spec.rb +0 -90
  86. data/spec/acceptance/register_strategies_spec.rb +0 -128
  87. data/spec/acceptance/sequence_context_spec.rb +0 -52
  88. data/spec/acceptance/sequence_spec.rb +0 -61
  89. data/spec/acceptance/skip_create_spec.rb +0 -19
  90. data/spec/acceptance/stub_spec.rb +0 -62
  91. data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -41
  92. data/spec/acceptance/traits_spec.rb +0 -727
  93. data/spec/acceptance/transient_attributes_spec.rb +0 -124
  94. data/spec/factory_girl/aliases_spec.rb +0 -31
  95. data/spec/factory_girl/attribute/association_spec.rb +0 -28
  96. data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
  97. data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
  98. data/spec/factory_girl/attribute/static_spec.rb +0 -19
  99. data/spec/factory_girl/attribute_list_spec.rb +0 -143
  100. data/spec/factory_girl/attribute_spec.rb +0 -16
  101. data/spec/factory_girl/callback_spec.rb +0 -41
  102. data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
  103. data/spec/factory_girl/declaration_list_spec.rb +0 -67
  104. data/spec/factory_girl/definition_proxy_spec.rb +0 -215
  105. data/spec/factory_girl/definition_spec.rb +0 -58
  106. data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
  107. data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
  108. data/spec/factory_girl/factory_spec.rb +0 -259
  109. data/spec/factory_girl/find_definitions_spec.rb +0 -110
  110. data/spec/factory_girl/null_factory_spec.rb +0 -13
  111. data/spec/factory_girl/null_object_spec.rb +0 -22
  112. data/spec/factory_girl/registry_spec.rb +0 -68
  113. data/spec/factory_girl/sequence_spec.rb +0 -95
  114. data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
  115. data/spec/factory_girl/strategy/build_spec.rb +0 -7
  116. data/spec/factory_girl/strategy/create_spec.rb +0 -25
  117. data/spec/factory_girl/strategy/stub_spec.rb +0 -38
  118. data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
  119. data/spec/factory_girl_spec.rb +0 -22
  120. data/spec/spec_helper.rb +0 -26
  121. data/spec/support/macros/define_constant.rb +0 -86
  122. data/spec/support/matchers/callback.rb +0 -9
  123. data/spec/support/matchers/declaration.rb +0 -83
  124. data/spec/support/matchers/delegate.rb +0 -44
  125. data/spec/support/matchers/trait.rb +0 -9
  126. 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,9 +0,0 @@
1
- RSpec::Matchers.define :have_trait do |trait_name|
2
- match do |instance|
3
- instance.defined_traits.include?(FactoryGirl::Trait.new(trait_name, &@block))
4
- end
5
-
6
- chain :with_block do |block|
7
- @block = block
8
- end
9
- 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