shoulda-matchers 4.0.0.rc1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +72 -40
  4. data/lib/shoulda/matchers/action_controller.rb +2 -0
  5. data/lib/shoulda/matchers/active_model.rb +2 -3
  6. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +1 -0
  7. data/lib/shoulda/matchers/active_record.rb +2 -0
  8. data/lib/shoulda/matchers/active_record/association_matcher.rb +34 -0
  9. data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +27 -4
  10. data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +27 -4
  11. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1 -1
  12. data/lib/shoulda/matchers/independent.rb +2 -1
  13. data/lib/shoulda/matchers/rails_shim.rb +5 -9
  14. data/lib/shoulda/matchers/version.rb +1 -1
  15. data/lib/shoulda/matchers/warn.rb +1 -0
  16. data/shoulda-matchers.gemspec +11 -3
  17. metadata +13 -340
  18. data/.gitignore +0 -12
  19. data/.hound.yml +0 -3
  20. data/.hound/ruby.yml +0 -1062
  21. data/.python-version +0 -1
  22. data/.rubocop.yml +0 -15
  23. data/.travis.yml +0 -21
  24. data/.yardopts +0 -10
  25. data/Appraisals +0 -105
  26. data/CONTRIBUTING.md +0 -172
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -59
  29. data/MAINTAINING.md +0 -250
  30. data/NEWS.md +0 -1235
  31. data/Rakefile +0 -46
  32. data/bin/setup +0 -190
  33. data/custom_plan.rb +0 -104
  34. data/doc_config/gh-pages/index.html.erb +0 -9
  35. data/doc_config/yard/setup.rb +0 -22
  36. data/doc_config/yard/templates/default/fulldoc/html/css/bootstrap.css +0 -5967
  37. data/doc_config/yard/templates/default/fulldoc/html/css/full_list.css +0 -12
  38. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +0 -66
  39. data/doc_config/yard/templates/default/fulldoc/html/css/solarized.css +0 -69
  40. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +0 -312
  41. data/doc_config/yard/templates/default/fulldoc/html/full_list.erb +0 -26
  42. data/doc_config/yard/templates/default/fulldoc/html/full_list_class.erb +0 -1
  43. data/doc_config/yard/templates/default/fulldoc/html/full_list_method.erb +0 -8
  44. data/doc_config/yard/templates/default/fulldoc/html/js/app.js +0 -281
  45. data/doc_config/yard/templates/default/fulldoc/html/js/full_list.js +0 -1
  46. data/doc_config/yard/templates/default/fulldoc/html/js/jquery.stickyheaders.js +0 -289
  47. data/doc_config/yard/templates/default/fulldoc/html/js/underscore.min.js +0 -6
  48. data/doc_config/yard/templates/default/fulldoc/html/setup.rb +0 -35
  49. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +0 -14
  50. data/doc_config/yard/templates/default/layout/html/fonts.erb +0 -1
  51. data/doc_config/yard/templates/default/layout/html/footer.erb +0 -6
  52. data/doc_config/yard/templates/default/layout/html/layout.erb +0 -23
  53. data/doc_config/yard/templates/default/layout/html/search.erb +0 -13
  54. data/doc_config/yard/templates/default/layout/html/setup.rb +0 -40
  55. data/doc_config/yard/templates/default/method_details/html/source.erb +0 -10
  56. data/doc_config/yard/templates/default/module/html/box_info.erb +0 -31
  57. data/gemfiles/4.2.gemfile +0 -39
  58. data/gemfiles/4.2.gemfile.lock +0 -246
  59. data/gemfiles/5.0.gemfile +0 -37
  60. data/gemfiles/5.0.gemfile.lock +0 -238
  61. data/gemfiles/5.1.gemfile +0 -38
  62. data/gemfiles/5.1.gemfile.lock +0 -254
  63. data/gemfiles/5.2.gemfile +0 -40
  64. data/gemfiles/5.2.gemfile.lock +0 -273
  65. data/script/install_gems_in_all_appraisals +0 -16
  66. data/script/run_all_tests +0 -16
  67. data/script/supported_ruby_versions +0 -7
  68. data/script/update_gem_in_all_appraisals +0 -17
  69. data/script/update_gems_in_all_appraisals +0 -16
  70. data/spec/acceptance/active_model_integration_spec.rb +0 -23
  71. data/spec/acceptance/independent_matchers_spec.rb +0 -125
  72. data/spec/acceptance/multiple_libraries_integration_spec.rb +0 -55
  73. data/spec/acceptance/rails_integration_spec.rb +0 -156
  74. data/spec/acceptance_spec_helper.rb +0 -23
  75. data/spec/doublespeak_spec_helper.rb +0 -2
  76. data/spec/report_warnings.rb +0 -7
  77. data/spec/spec_helper.rb +0 -20
  78. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +0 -133
  79. data/spec/support/acceptance/helpers.rb +0 -33
  80. data/spec/support/acceptance/helpers/active_model_helpers.rb +0 -11
  81. data/spec/support/acceptance/helpers/array_helpers.rb +0 -13
  82. data/spec/support/acceptance/helpers/base_helpers.rb +0 -19
  83. data/spec/support/acceptance/helpers/command_helpers.rb +0 -68
  84. data/spec/support/acceptance/helpers/file_helpers.rb +0 -19
  85. data/spec/support/acceptance/helpers/gem_helpers.rb +0 -31
  86. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -11
  87. data/spec/support/acceptance/helpers/n_unit_helpers.rb +0 -25
  88. data/spec/support/acceptance/helpers/pluralization_helpers.rb +0 -13
  89. data/spec/support/acceptance/helpers/rails_migration_helpers.rb +0 -21
  90. data/spec/support/acceptance/helpers/rails_version_helpers.rb +0 -11
  91. data/spec/support/acceptance/helpers/rspec_helpers.rb +0 -24
  92. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +0 -9
  93. data/spec/support/acceptance/helpers/step_helpers.rb +0 -127
  94. data/spec/support/acceptance/matchers/have_output.rb +0 -31
  95. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -55
  96. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -103
  97. data/spec/support/tests/bundle.rb +0 -94
  98. data/spec/support/tests/command_runner.rb +0 -230
  99. data/spec/support/tests/current_bundle.rb +0 -55
  100. data/spec/support/tests/database.rb +0 -28
  101. data/spec/support/tests/database_adapters/postgresql.rb +0 -25
  102. data/spec/support/tests/database_adapters/sqlite3.rb +0 -26
  103. data/spec/support/tests/database_configuration.rb +0 -33
  104. data/spec/support/tests/database_configuration_registry.rb +0 -28
  105. data/spec/support/tests/filesystem.rb +0 -100
  106. data/spec/support/tests/version.rb +0 -45
  107. data/spec/support/unit/active_record/create_table.rb +0 -54
  108. data/spec/support/unit/attribute.rb +0 -45
  109. data/spec/support/unit/capture.rb +0 -46
  110. data/spec/support/unit/change_value.rb +0 -111
  111. data/spec/support/unit/create_model_arguments/basic.rb +0 -135
  112. data/spec/support/unit/create_model_arguments/has_many.rb +0 -15
  113. data/spec/support/unit/create_model_arguments/uniqueness_matcher.rb +0 -74
  114. data/spec/support/unit/helpers/action_pack_versions.rb +0 -22
  115. data/spec/support/unit/helpers/active_model_helpers.rb +0 -27
  116. data/spec/support/unit/helpers/active_model_versions.rb +0 -32
  117. data/spec/support/unit/helpers/active_record_versions.rb +0 -44
  118. data/spec/support/unit/helpers/active_resource_builder.rb +0 -27
  119. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +0 -15
  120. data/spec/support/unit/helpers/class_builder.rb +0 -90
  121. data/spec/support/unit/helpers/column_type_helpers.rb +0 -26
  122. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +0 -17
  123. data/spec/support/unit/helpers/controller_builder.rb +0 -63
  124. data/spec/support/unit/helpers/database_helpers.rb +0 -20
  125. data/spec/support/unit/helpers/i18n_faker.rb +0 -15
  126. data/spec/support/unit/helpers/mailer_builder.rb +0 -12
  127. data/spec/support/unit/helpers/message_helpers.rb +0 -19
  128. data/spec/support/unit/helpers/model_builder.rb +0 -114
  129. data/spec/support/unit/helpers/rails_versions.rb +0 -42
  130. data/spec/support/unit/helpers/validation_matcher_scenario_helpers.rb +0 -44
  131. data/spec/support/unit/i18n.rb +0 -7
  132. data/spec/support/unit/load_environment.rb +0 -12
  133. data/spec/support/unit/matchers/deprecate.rb +0 -60
  134. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +0 -51
  135. data/spec/support/unit/matchers/fail_with_message_matcher.rb +0 -64
  136. data/spec/support/unit/matchers/print_warning_including.rb +0 -67
  137. data/spec/support/unit/model_creation_strategies/active_model.rb +0 -111
  138. data/spec/support/unit/model_creation_strategies/active_record.rb +0 -77
  139. data/spec/support/unit/model_creators.rb +0 -19
  140. data/spec/support/unit/model_creators/active_model.rb +0 -39
  141. data/spec/support/unit/model_creators/active_record.rb +0 -42
  142. data/spec/support/unit/model_creators/active_record/has_and_belongs_to_many.rb +0 -95
  143. data/spec/support/unit/model_creators/active_record/has_many.rb +0 -67
  144. data/spec/support/unit/model_creators/active_record/uniqueness_matcher.rb +0 -42
  145. data/spec/support/unit/model_creators/basic.rb +0 -102
  146. data/spec/support/unit/rails_application.rb +0 -151
  147. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +0 -69
  148. data/spec/support/unit/record_validating_confirmation_builder.rb +0 -54
  149. data/spec/support/unit/record_with_different_error_attribute_builder.rb +0 -92
  150. data/spec/support/unit/shared_examples/ignoring_interference_by_writer.rb +0 -79
  151. data/spec/support/unit/shared_examples/numerical_submatcher.rb +0 -17
  152. data/spec/support/unit/shared_examples/set_session_or_flash.rb +0 -360
  153. data/spec/support/unit/validation_matcher_scenario.rb +0 -60
  154. data/spec/unit/shoulda/matchers/action_controller/callback_matcher_spec.rb +0 -82
  155. data/spec/unit/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +0 -28
  156. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +0 -629
  157. data/spec/unit/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +0 -42
  158. data/spec/unit/shoulda/matchers/action_controller/render_template_matcher_spec.rb +0 -76
  159. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +0 -62
  160. data/spec/unit/shoulda/matchers/action_controller/rescue_from_matcher_spec.rb +0 -90
  161. data/spec/unit/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +0 -31
  162. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -330
  163. data/spec/unit/shoulda/matchers/action_controller/route_params_spec.rb +0 -30
  164. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +0 -67
  165. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -17
  166. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +0 -562
  167. data/spec/unit/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -117
  168. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +0 -829
  169. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +0 -86
  170. data/spec/unit/shoulda/matchers/active_model/have_secure_password_matcher_spec.rb +0 -20
  171. data/spec/unit/shoulda/matchers/active_model/helpers_spec.rb +0 -162
  172. data/spec/unit/shoulda/matchers/active_model/validate_absence_of_matcher_spec.rb +0 -290
  173. data/spec/unit/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +0 -109
  174. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -172
  175. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -264
  176. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -1049
  177. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -335
  178. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +0 -1865
  179. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -406
  180. data/spec/unit/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -107
  181. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +0 -1672
  182. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +0 -251
  183. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +0 -690
  184. data/spec/unit/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +0 -111
  185. data/spec/unit/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +0 -85
  186. data/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +0 -41
  187. data/spec/unit/shoulda/matchers/active_record/have_secure_token_matcher_spec.rb +0 -169
  188. data/spec/unit/shoulda/matchers/active_record/serialize_matcher_spec.rb +0 -86
  189. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +0 -1682
  190. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +0 -190
  191. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +0 -21
  192. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +0 -271
  193. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +0 -77
  194. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +0 -72
  195. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +0 -101
  196. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +0 -78
  197. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +0 -27
  198. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +0 -43
  199. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -650
  200. data/spec/unit/shoulda/matchers/routing/route_matcher_spec.rb +0 -406
  201. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +0 -252
  202. data/spec/unit_spec_helper.rb +0 -54
  203. data/spec/warnings_spy.rb +0 -64
  204. data/spec/warnings_spy/filesystem.rb +0 -45
  205. data/spec/warnings_spy/partitioner.rb +0 -36
  206. data/spec/warnings_spy/reader.rb +0 -53
  207. data/spec/warnings_spy/reporter.rb +0 -88
  208. data/tasks/documentation.rb +0 -199
  209. data/zeus.json +0 -11
@@ -1,77 +0,0 @@
1
- require 'doublespeak_spec_helper'
2
-
3
- module Shoulda::Matchers::Doublespeak
4
- describe ObjectDouble do
5
- it 'responds to any method' do
6
- double = described_class.new
7
-
8
- expect(double.respond_to?(:foo)).to be true
9
- expect(double.respond_to?(:bar)).to be true
10
- expect(double.respond_to?(:baz)).to be true
11
- end
12
-
13
- it 'returns nil from any method call' do
14
- double = described_class.new
15
-
16
- expect(double.foo).to be nil
17
- expect(double.bar).to be nil
18
- expect(double.baz).to be nil
19
- end
20
-
21
- it 'records every method call' do
22
- double = described_class.new
23
-
24
- block = -> { :some_return_value }
25
- double.foo
26
- double.bar(42)
27
- double.baz(:zing, :zang, &block)
28
-
29
- expect(double.calls.size).to eq 3
30
- double.calls[0].tap do |call|
31
- expect(call.args).to eq []
32
- expect(call.block).to eq nil
33
- end
34
- double.calls[1].tap do |call|
35
- expect(call.args).to eq [42]
36
- expect(call.block).to eq nil
37
- end
38
- double.calls[2].tap do |call|
39
- expect(call.args).to eq [:zing, :zang]
40
- expect(call.block).to eq block
41
- end
42
- end
43
-
44
- describe '#calls_to' do
45
- it 'returns all of the invocations of the given method and their arguments/block' do
46
- double = described_class.new
47
-
48
- block = -> { :some_return_value }
49
- double.foo
50
- double.foo(42)
51
- double.foo(:zing, :zang, &block)
52
- double.some_other_method(:doesnt_matter)
53
-
54
- calls = double.calls_to(:foo)
55
-
56
- expect(calls.size).to eq 3
57
- calls[0].tap do |call|
58
- expect(call.args).to eq []
59
- expect(call.block).to eq nil
60
- end
61
- calls[1].tap do |call|
62
- expect(call.args).to eq [42]
63
- expect(call.block).to eq nil
64
- end
65
- calls[2].tap do |call|
66
- expect(call.args).to eq [:zing, :zang]
67
- expect(call.block).to eq block
68
- end
69
- end
70
-
71
- it 'returns an empty array if the given method was never called' do
72
- double = described_class.new
73
- expect(double.calls_to(:unknown_method)).to eq []
74
- end
75
- end
76
- end
77
- end
@@ -1,72 +0,0 @@
1
- require 'doublespeak_spec_helper'
2
-
3
- module Shoulda::Matchers::Doublespeak
4
- describe ProxyImplementation do
5
- describe '#returns' do
6
- it 'delegates to its stub_implementation' do
7
- stub_implementation = build_stub_implementation
8
- implementation = described_class.new(stub_implementation)
9
- implementation.returns(:value)
10
-
11
- expect(stub_implementation).to have_received(:returns).with(:value)
12
- end
13
- end
14
-
15
- describe '#call' do
16
- it 'calls #call_original_method on the double' do
17
- stub_implementation = build_stub_implementation
18
- double = build_double
19
- call = build_call(double: double)
20
- allow(double).to receive(:call_original_method)
21
- implementation = described_class.new(stub_implementation)
22
-
23
- implementation.call(call)
24
-
25
- expect(double).
26
- to have_received(:call_original_method).
27
- with(call)
28
- end
29
-
30
- it 'delegates to its stub_implementation' do
31
- stub_implementation = build_stub_implementation
32
- double = build_double
33
- call2 = build_call
34
- call = build_call(double: double, with_return_value: call2)
35
- allow(double).to receive(:call_original_method)
36
- implementation = described_class.new(stub_implementation)
37
-
38
- implementation.call(call)
39
-
40
- expect(stub_implementation).
41
- to have_received(:call).
42
- with(call2)
43
- end
44
-
45
- it 'returns the return value of the original method' do
46
- return_value = :some_return_value
47
- stub_implementation = build_stub_implementation
48
- double = build_double(call_original_method: return_value)
49
- call = build_call(double: double)
50
- implementation = described_class.new(stub_implementation)
51
-
52
- return_value = implementation.call(call)
53
-
54
- expect(return_value).to be return_value
55
- end
56
- end
57
-
58
- def build_stub_implementation
59
- double('stub_implementation', returns: nil, call: nil)
60
- end
61
-
62
- def build_double(methods = {})
63
- defaults = { call_original_method: nil }
64
- double('double', defaults.merge(methods))
65
- end
66
-
67
- def build_call(methods = {})
68
- defaults = { double: build_double, with_return_value: nil }
69
- double('call', defaults.merge(methods))
70
- end
71
- end
72
- end
@@ -1,101 +0,0 @@
1
- require 'doublespeak_spec_helper'
2
-
3
- module Shoulda::Matchers::Doublespeak
4
- describe StubImplementation do
5
- describe '#call' do
6
- it 'calls #record_call on the double' do
7
- implementation = described_class.new
8
- double = build_double
9
- call = build_call(double: double)
10
-
11
- allow(double).to receive(:record_call).with(call)
12
-
13
- implementation.call(call)
14
- end
15
-
16
- context 'if no explicit implementation was set' do
17
- it 'returns nil' do
18
- implementation = described_class.new
19
- double = build_double
20
- call = build_call(double: double)
21
-
22
- return_value = implementation.call(call)
23
-
24
- expect(return_value).to eq nil
25
- end
26
- end
27
-
28
- context 'if the implementation was set as a value' do
29
- it 'returns the set return value' do
30
- implementation = described_class.new
31
- implementation.returns(42)
32
- double = build_double
33
- call = build_call(double: double)
34
-
35
- return_value = implementation.call(call)
36
-
37
- expect(return_value).to eq 42
38
- end
39
- end
40
-
41
- context 'if the implementation was set as a block' do
42
- it 'calls the block with the MethodCall object the implementation was called with' do
43
- double = build_double
44
- expected_object, expected_args, expected_block = :object, :args, :block
45
- call = build_call(
46
- double: double,
47
- object: expected_object,
48
- args: expected_args,
49
- block: expected_block
50
- )
51
- actual_object, actual_args, actual_block = []
52
- implementation = described_class.new
53
- implementation.returns do |actual_call|
54
- actual_object = actual_call.object
55
- actual_args = actual_call.args
56
- actual_block = actual_call.block
57
- end
58
-
59
- implementation.call(call)
60
-
61
- expect(actual_object).to eq expected_object
62
- expect(actual_args).to eq expected_args
63
- expect(actual_block).to eq expected_block
64
- end
65
-
66
- it 'returns the return value of the block' do
67
- implementation = described_class.new
68
- implementation.returns { 42 }
69
- double = build_double
70
- call = build_call(double: double)
71
-
72
- return_value = implementation.call(call)
73
-
74
- expect(return_value).to eq 42
75
- end
76
- end
77
-
78
- context 'if the implementation was set as both a value and a block' do
79
- it 'prefers the block over the value' do
80
- implementation = described_class.new
81
- implementation.returns(:something_else) { 42 }
82
- double = build_double
83
- call = build_call(double: double)
84
-
85
- return_value = implementation.call(call)
86
-
87
- expect(return_value).to eq 42
88
- end
89
- end
90
- end
91
-
92
- def build_double
93
- double('double', record_call: nil)
94
- end
95
-
96
- def build_call(options = {})
97
- defaults = { double: build_double }
98
- double('call', defaults.merge(options))
99
- end
100
- end
101
- end
@@ -1,78 +0,0 @@
1
- require 'doublespeak_spec_helper'
2
-
3
- module Shoulda::Matchers::Doublespeak
4
- describe World do
5
- describe '#double_collection_for' do
6
- it 'calls DoubleCollection.new once with the given class' do
7
- allow(DoubleCollection).to receive(:new).and_return(:klass)
8
- world = described_class.new
9
-
10
- world.double_collection_for(:klass)
11
- world.double_collection_for(:klass)
12
-
13
- expect(DoubleCollection).
14
- to have_received(:new).
15
- with(world, :klass).
16
- once
17
- end
18
-
19
- it 'returns the created DoubleCollection' do
20
- world = described_class.new
21
- double_collection = build_double_collection
22
- allow(DoubleCollection).
23
- to receive(:new).
24
- with(world, :klass).
25
- and_return(double_collection)
26
-
27
- expect(world.double_collection_for(:klass)).to be double_collection
28
- end
29
- end
30
-
31
- describe '#with_doubles_activated' do
32
- it 'installs all doubles, yields the block, then uninstalls them all' do
33
- block_called = false
34
- double_collections = Array.new(3) { build_double_collection }
35
- double_collections.each do |double_collection|
36
- allow(double_collection).to receive(:activate)
37
- allow(double_collection).to receive(:deactivate)
38
- end
39
- klasses = Array.new(3) { |i| "Klass #{i}" }
40
- world = described_class.new
41
- double_collections.zip(klasses).each do |double_collection, klass|
42
- allow(DoubleCollection).
43
- to receive(:new).
44
- with(world, klass).
45
- and_return(double_collection)
46
- world.double_collection_for(klass)
47
- end
48
-
49
- world.with_doubles_activated { block_called = true }
50
-
51
- expect(block_called).to eq true
52
-
53
- double_collections.each do |double_collection|
54
- expect(double_collection).to have_received(:activate)
55
- expect(double_collection).to have_received(:deactivate)
56
- end
57
- end
58
-
59
- it 'still makes sure to uninstall all doubles even if the block raises an error' do
60
- double_collection = build_double_collection
61
- allow(DoubleCollection).to receive(:new).and_return(double_collection)
62
- world = described_class.new
63
- world.double_collection_for(:klass)
64
-
65
- begin
66
- world.with_doubles_activated { raise 'error' }
67
- rescue RuntimeError
68
- end
69
-
70
- expect(double_collection).to have_received(:deactivate)
71
- end
72
- end
73
-
74
- def build_double_collection
75
- double('double_collection', activate: nil, deactivate: nil)
76
- end
77
- end
78
- end
@@ -1,27 +0,0 @@
1
- require 'doublespeak_spec_helper'
2
-
3
- module Shoulda::Matchers
4
- describe Doublespeak do
5
- describe '.double_collection_for' do
6
- it 'delegates to its world' do
7
- allow(Doublespeak.world).to receive(:double_collection_for)
8
-
9
- described_class.double_collection_for(:klass)
10
-
11
- expect(Doublespeak.world).
12
- to have_received(:double_collection_for).
13
- with(:klass)
14
- end
15
- end
16
-
17
- describe '.with_doubles_activated' do
18
- it 'delegates to its world' do
19
- allow(Doublespeak.world).to receive(:with_doubles_activated)
20
-
21
- described_class.with_doubles_activated
22
-
23
- expect(Doublespeak.world).to have_received(:with_doubles_activated)
24
- end
25
- end
26
- end
27
- end
@@ -1,43 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::Independent::DelegateMethodMatcher::StubbedTarget do
4
- subject(:target) { described_class.new(:stubbed_method) }
5
-
6
- describe '#has_received_method?' do
7
- it 'returns true when the method has been called on the target' do
8
- target.stubbed_method
9
-
10
- expect(target).to have_received_method
11
- end
12
-
13
- it 'returns false when the method has not been called on the target' do
14
- expect(target).not_to have_received_method
15
- end
16
- end
17
-
18
- describe '#has_received_arguments?' do
19
- context 'method is called with specified arguments' do
20
- it 'returns true' do
21
- target.stubbed_method(:arg1, :arg2)
22
-
23
- expect(target).to have_received_arguments(:arg1, :arg2)
24
- end
25
- end
26
-
27
- context 'method is not called with specified arguments' do
28
- it 'returns false' do
29
- target.stubbed_method
30
-
31
- expect(target).not_to have_received_arguments(:arg1)
32
- end
33
- end
34
-
35
- context 'method is called with arguments in incorrect order' do
36
- it 'returns false' do
37
- target.stubbed_method(:arg2, :arg1)
38
-
39
- expect(target).not_to have_received_arguments(:arg1, :arg2)
40
- end
41
- end
42
- end
43
- end
@@ -1,650 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Shoulda::Matchers::Independent::DelegateMethodMatcher do
4
- describe '#description' do
5
- context 'when the subject is an instance' do
6
- subject { Object.new }
7
-
8
- context 'without any qualifiers' do
9
- it 'states that it should delegate method to the right object' do
10
- matcher = delegate_method(:method_name).to(:delegate)
11
- message = 'delegate #method_name to the #delegate object'
12
-
13
- expect(matcher.description).to eq message
14
- end
15
- end
16
-
17
- context 'qualified with #as' do
18
- it 'states that it should delegate method to the right object and method' do
19
- matcher = delegate_method(:method_name).to(:delegate).as(:alternate)
20
- message = 'delegate #method_name to the #delegate object as #alternate'
21
-
22
- expect(matcher.description).to eq message
23
- end
24
- end
25
-
26
- context 'qualified with #with_arguments' do
27
- it 'states that it should delegate method to the right object with right argument' do
28
- matcher = delegate_method(:method_name).to(:delegate).
29
- with_arguments(:foo, bar: [1, 2])
30
- message = 'delegate #method_name to the #delegate object passing arguments [:foo, {:bar=>[1, 2]}]'
31
-
32
- expect(matcher.description).to eq message
33
- end
34
- end
35
-
36
- context 'qualified with #with_prefix' do
37
- context 'without arguments' do
38
- before do
39
- define_model('Country') do
40
- def hello; 'hello' end
41
- end
42
- end
43
-
44
- context "when the subject's delegating method also has a prefix" do
45
- it 'produces the correct description' do
46
- define_class('Person') do
47
- delegate :hello, to: :country, prefix: true
48
-
49
- def country
50
- Country.new
51
- end
52
- end
53
-
54
- matcher = delegate_method(:hello).to(:country).with_prefix
55
- expect(matcher.description).
56
- to eq('delegate #country_hello to the #country object as #hello')
57
- end
58
- end
59
- end
60
-
61
- context 'as true' do
62
- before do
63
- define_model('Country') do
64
- def hello; 'hello' end
65
- end
66
- end
67
-
68
- context "when the subject's delegating method also has a prefix" do
69
- it 'produces the correct description' do
70
- define_class('Person') do
71
- delegate :hello, to: :country, prefix: true
72
-
73
- def country
74
- Country.new
75
- end
76
- end
77
-
78
- matcher = delegate_method(:hello).to(:country).with_prefix(true)
79
- expect(matcher.description).
80
- to eq('delegate #country_hello to the #country object as #hello')
81
- end
82
- end
83
- end
84
-
85
- context 'as a symbol/string' do
86
- it 'should delegate as (prefix_supplied)_(method_on_target)' do
87
- define_model('Country') do
88
- def hello; 'hello' end
89
- end
90
-
91
- define_class('Person') do
92
- delegate :hello, to: :country, prefix: 'county'
93
-
94
- def country
95
- Country.new
96
- end
97
- end
98
-
99
- matcher = delegate_method(:hello).to(:country).with_prefix('county')
100
- expect(matcher.description).
101
- to eq('delegate #county_hello to the #country object as #hello')
102
- end
103
- end
104
- end
105
- end
106
-
107
- context 'when the subject is a class' do
108
- subject { Object }
109
-
110
- context 'without any qualifiers' do
111
- it 'states that it should delegate method to the right object' do
112
- matcher = delegate_method(:method_name).to(:delegate)
113
-
114
- expect(matcher.description).
115
- to eq 'delegate .method_name to the .delegate object'
116
- end
117
- end
118
-
119
- context 'qualified with #as' do
120
- it 'states that it should delegate method to the right object and method' do
121
- matcher = delegate_method(:method_name).to(:delegate).as(:alternate)
122
- message = 'delegate .method_name to the .delegate object as .alternate'
123
-
124
- expect(matcher.description).to eq message
125
- end
126
- end
127
-
128
- context 'qualified with #with_arguments' do
129
- it 'states that it should delegate method to the right object with right argument' do
130
- matcher = delegate_method(:method_name).to(:delegate).
131
- with_arguments(:foo, bar: [1, 2])
132
- message = 'delegate .method_name to the .delegate object passing arguments [:foo, {:bar=>[1, 2]}]'
133
-
134
- expect(matcher.description).to eq message
135
- end
136
- end
137
- end
138
- end
139
-
140
- it 'raises an error if the delegate object was never specified before matching' do
141
- expect {
142
- expect(Object.new).to delegate_method(:name)
143
- }.to raise_error described_class::DelegateObjectNotSpecified
144
- end
145
-
146
- context 'stubbing a delegating method on an instance' do
147
- it 'only happens temporarily and is removed after the match' do
148
- define_class('Company') do
149
- def name
150
- 'Acme Company'
151
- end
152
- end
153
-
154
- define_class('Person') do
155
- def company_name
156
- company.name
157
- end
158
-
159
- def company
160
- Company.new
161
- end
162
- end
163
-
164
- person = Person.new
165
- matcher = delegate_method(:company_name).to(:company).as(:name)
166
- matcher.matches?(person)
167
-
168
- expect(person.company.name).to eq 'Acme Company'
169
- end
170
- end
171
-
172
- context 'when the subject does not delegate anything' do
173
- before do
174
- define_class('PostOffice')
175
- end
176
-
177
- context 'when the subject is an instance' do
178
- it 'rejects with the correct failure message' do
179
- post_office = PostOffice.new
180
- message = [
181
- 'Expected PostOffice to delegate #deliver_mail to the #mailman object.',
182
- '',
183
- 'Method calls sent to PostOffice#mailman: (none)'
184
- ].join("\n")
185
-
186
- expect {
187
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
188
- }.to fail_with_message(message)
189
- end
190
- end
191
-
192
- context 'when the subject is a class' do
193
- it 'uses the proper syntax for class methods in errors' do
194
- message = [
195
- 'Expected PostOffice to delegate .deliver_mail to the .mailman object.',
196
- '',
197
- 'Method calls sent to PostOffice.mailman: (none)'
198
- ].join("\n")
199
-
200
- expect {
201
- expect(PostOffice).to delegate_method(:deliver_mail).to(:mailman)
202
- }.to fail_with_message(message)
203
- end
204
- end
205
- end
206
-
207
- context 'when the subject delegates correctly' do
208
- before do
209
- define_class('Mailman')
210
-
211
- define_class('PostOffice') do
212
- def deliver_mail
213
- mailman.deliver_mail
214
- end
215
-
216
- def mailman
217
- Mailman.new
218
- end
219
- end
220
- end
221
-
222
- it 'accepts' do
223
- post_office = PostOffice.new
224
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
225
- end
226
-
227
- context 'negating the matcher' do
228
- it 'rejects with the correct failure message' do
229
- post_office = PostOffice.new
230
- message = 'Expected PostOffice not to delegate #deliver_mail to the #mailman object, but it did.'
231
-
232
- expect {
233
- expect(post_office).not_to delegate_method(:deliver_mail).to(:mailman)
234
- }.to fail_with_message(message)
235
- end
236
- end
237
- end
238
-
239
- context 'when the delegating method is private' do
240
- before do
241
- define_class('Mailman')
242
-
243
- define_class('PostOffice') do
244
- def deliver_mail
245
- mailman.deliver_mail
246
- end
247
-
248
- def mailman
249
- Mailman.new
250
- end
251
-
252
- private :mailman
253
- end
254
- end
255
-
256
- it 'accepts' do
257
- post_office = PostOffice.new
258
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
259
- end
260
- end
261
-
262
- context 'qualified with #with_arguments' do
263
- before do
264
- define_class('Mailman')
265
-
266
- define_class('PostOffice') do
267
- def deliver_mail(*args)
268
- mailman.deliver_mail('221B Baker St.', hastily: true)
269
- end
270
-
271
- def mailman
272
- Mailman.new
273
- end
274
- end
275
- end
276
-
277
- context 'qualified with #with_arguments' do
278
- context 'when the subject delegates with matching arguments' do
279
- it 'accepts' do
280
- post_office = PostOffice.new
281
- expect(post_office).to delegate_method(:deliver_mail).
282
- to(:mailman).with_arguments('221B Baker St.', hastily: true)
283
- end
284
-
285
- context 'negating the matcher' do
286
- it 'rejects with the correct failure message' do
287
- post_office = PostOffice.new
288
- message = 'Expected PostOffice not to delegate #deliver_mail to the #mailman object passing arguments ["221B Baker St.", {:hastily=>true}], but it did.'
289
-
290
- expect {
291
- expect(post_office).
292
- not_to delegate_method(:deliver_mail).
293
- to(:mailman).
294
- with_arguments('221B Baker St.', hastily: true)
295
- }.to fail_with_message(message)
296
- end
297
- end
298
- end
299
-
300
- context 'when not given the correct arguments' do
301
- it 'rejects with the correct failure message' do
302
- post_office = PostOffice.new
303
- message = [
304
- 'Expected PostOffice to delegate #deliver_mail to the #mailman object',
305
- 'passing arguments ["123 Nowhere Ln."].',
306
- '',
307
- 'Method calls sent to PostOffice#mailman:',
308
- '',
309
- '1) deliver_mail("221B Baker St.", {:hastily=>true})'
310
- ].join("\n")
311
-
312
- expect {
313
- expect(post_office).to delegate_method(:deliver_mail).
314
- to(:mailman).with_arguments('123 Nowhere Ln.')
315
- }.to fail_with_message(message)
316
- end
317
- end
318
- end
319
- end
320
-
321
- context 'qualified with #as' do
322
- before do
323
- define_class(:mailman)
324
-
325
- define_class(:post_office) do
326
- def deliver_mail
327
- mailman.deliver_mail_and_avoid_dogs
328
- end
329
-
330
- def mailman
331
- Mailman.new
332
- end
333
- end
334
- end
335
-
336
- context "when the given method is the same as the subject's delegating method" do
337
- it 'accepts' do
338
- post_office = PostOffice.new
339
- expect(post_office).to delegate_method(:deliver_mail).
340
- to(:mailman).as(:deliver_mail_and_avoid_dogs)
341
- end
342
-
343
- context 'negating the assertion' do
344
- it 'rejects with the correct failure message' do
345
- post_office = PostOffice.new
346
- message = 'Expected PostOffice not to delegate #deliver_mail to the #mailman object as #deliver_mail_and_avoid_dogs, but it did.'
347
-
348
- expect {
349
- expect(post_office).
350
- not_to delegate_method(:deliver_mail).
351
- to(:mailman).
352
- as(:deliver_mail_and_avoid_dogs)
353
- }.to fail_with_message(message)
354
- end
355
- end
356
- end
357
-
358
- context "when the given method is not the same as the subject's delegating method" do
359
- it 'rejects with the correct failure message' do
360
- post_office = PostOffice.new
361
- message = [
362
- 'Expected PostOffice to delegate #deliver_mail to the #mailman object as',
363
- '#watch_tv.',
364
- '',
365
- 'Method calls sent to PostOffice#mailman:',
366
- '',
367
- '1) deliver_mail_and_avoid_dogs()'
368
- ].join("\n")
369
-
370
- expect {
371
- expect(post_office).to delegate_method(:deliver_mail).
372
- to(:mailman).as(:watch_tv)
373
- }.to fail_with_message(message)
374
- end
375
- end
376
- end
377
-
378
- context 'qualified with #with_prefix' do
379
- context 'without arguments' do
380
- before do
381
- define_model('Country') do
382
- def hello; 'hello' end
383
- end
384
- end
385
-
386
- context "when the subject's delegating method also has a prefix" do
387
- it 'accepts' do
388
- define_class('Person') do
389
- delegate :hello, to: :country, prefix: true
390
-
391
- def country
392
- Country.new
393
- end
394
- end
395
-
396
- person = Person.new
397
- expect(person).to delegate_method(:hello). to(:country).with_prefix
398
- end
399
- end
400
-
401
- context "when the subject's delegating method does not have a prefix" do
402
- it 'rejects with the correct failure message' do
403
- define_class('Person') do
404
- delegate :hello, to: :country
405
-
406
- def country
407
- Country.new
408
- end
409
- end
410
-
411
- message = [
412
- 'Expected Person to delegate #country_hello to the #country object as',
413
- '#hello.',
414
- '',
415
- 'Method calls sent to Person#country: (none)'
416
- ].join("\n")
417
-
418
- person = Person.new
419
-
420
- expect {
421
- expect(person).to delegate_method(:hello). to(:country).with_prefix
422
- }.to fail_with_message(message)
423
- end
424
- end
425
- end
426
-
427
- context 'as true' do
428
- before do
429
- define_model('Country') do
430
- def hello; 'hello' end
431
- end
432
- end
433
-
434
- context "when the subject's delegating method also has a prefix" do
435
- it 'accepts' do
436
- define_class('Person') do
437
- delegate :hello, to: :country, prefix: true
438
-
439
- def country
440
- Country.new
441
- end
442
- end
443
-
444
- person = Person.new
445
- expect(person).
446
- to delegate_method(:hello).
447
- to(:country).with_prefix(true)
448
- end
449
- end
450
-
451
- context "when the subject's delegating method does not have a prefix" do
452
- it 'rejects with the correct failure message' do
453
- define_class('Person') do
454
- delegate :hello, to: :country
455
-
456
- def country
457
- Country.new
458
- end
459
- end
460
-
461
- message = [
462
- 'Expected Person to delegate #country_hello to the #country object as',
463
- '#hello.',
464
- '',
465
- 'Method calls sent to Person#country: (none)'
466
- ].join("\n")
467
-
468
- person = Person.new
469
-
470
- expect {
471
- expect(person).
472
- to delegate_method(:hello).
473
- to(:country).with_prefix(true)
474
- }.to fail_with_message(message)
475
- end
476
- end
477
- end
478
-
479
- context 'as a symbol/string' do
480
- before do
481
- define_model('Country') do
482
- def hello; 'hello' end
483
- end
484
- end
485
-
486
- context "when the subject's delegating method has the same prefix" do
487
- it 'accepts' do
488
- define_class('Person') do
489
- delegate :hello, to: :country, prefix: 'county'
490
-
491
- def country
492
- Country.new
493
- end
494
- end
495
-
496
- person = Person.new
497
- expect(person).
498
- to delegate_method(:hello).
499
- to(:country).with_prefix('county')
500
- end
501
- end
502
-
503
- context "when the subject's delegating method has a different prefix" do
504
- it 'rejects with the correct failure message' do
505
- define_class('Person') do
506
- delegate :hello, to: :country, prefix: 'something_else'
507
-
508
- def country
509
- Country.new
510
- end
511
- end
512
-
513
- message = [
514
- 'Expected Person to delegate #county_hello to the #country object as',
515
- '#hello.',
516
- '',
517
- 'Method calls sent to Person#country: (none)'
518
- ].join("\n")
519
-
520
- person = Person.new
521
-
522
- expect {
523
- expect(person).
524
- to delegate_method(:hello).
525
- to(:country).with_prefix('county')
526
- }.to fail_with_message(message)
527
- end
528
- end
529
- end
530
- end
531
-
532
- context 'qualified with #allow_nil' do
533
- context 'when using delegate from Rails' do
534
- context 'when delegations were defined with :allow_nil' do
535
- it 'accepts' do
536
- define_class('Person') do
537
- delegate :hello, to: :country, allow_nil: true
538
- def country; end
539
- end
540
-
541
- person = Person.new
542
-
543
- expect(person).to delegate_method(:hello).to(:country).allow_nil
544
- end
545
- end
546
-
547
- context 'when delegations were not defined with :allow_nil' do
548
- it 'rejects with the correct failure message' do
549
- define_class('Person') do
550
- delegate :hello, to: :country
551
- def country; end
552
- end
553
-
554
- person = Person.new
555
-
556
- message = <<-MESSAGE
557
- Expected Person to delegate #hello to the #country object, allowing
558
- #country to return nil.
559
-
560
- Person#hello did delegate to #country when it was non-nil, but it failed
561
- to account for when #country *was* nil.
562
- MESSAGE
563
-
564
- expectation = lambda do
565
- expect(person).to delegate_method(:hello).to(:country).allow_nil
566
- end
567
-
568
- expect(&expectation).to fail_with_message(message)
569
- end
570
- end
571
- end
572
-
573
- context 'when using Forwardable' do
574
- context 'when the delegate object is nil' do
575
- it 'rejects with the correct failure message' do
576
- define_class('Person') do
577
- extend Forwardable
578
-
579
- def_delegators :country, :hello
580
-
581
- def country; end
582
- end
583
-
584
- person = Person.new
585
-
586
- message = <<-MESSAGE
587
- Expected Person to delegate #hello to the #country object, allowing
588
- #country to return nil.
589
-
590
- Person#hello did delegate to #country when it was non-nil, but it failed
591
- to account for when #country *was* nil.
592
- MESSAGE
593
-
594
- expectation = lambda do
595
- expect(person).to delegate_method(:hello).to(:country).allow_nil
596
- end
597
-
598
- expect(&expectation).to fail_with_message(message)
599
- end
600
- end
601
- end
602
-
603
- context 'when delegating manually' do
604
- context 'when the delegating method accounts for the delegate object being nil' do
605
- it 'accepts' do
606
- define_class('Person') do
607
- def country; end
608
-
609
- def hello
610
- return unless country
611
- country.hello
612
- end
613
- end
614
-
615
- person = Person.new
616
-
617
- expect(person).to delegate_method(:hello).to(:country).allow_nil
618
- end
619
- end
620
-
621
- context 'when the delegating method does not account for the delegate object being nil' do
622
- it 'rejects with the correct failure message' do
623
- define_class('Person') do
624
- def country; end
625
-
626
- def hello
627
- country.hello
628
- end
629
- end
630
-
631
- person = Person.new
632
-
633
- message = <<-MESSAGE
634
- Expected Person to delegate #hello to the #country object, allowing
635
- #country to return nil.
636
-
637
- Person#hello did delegate to #country when it was non-nil, but it failed
638
- to account for when #country *was* nil.
639
- MESSAGE
640
-
641
- expectation = lambda do
642
- expect(person).to delegate_method(:hello).to(:country).allow_nil
643
- end
644
-
645
- expect(&expectation).to fail_with_message(message)
646
- end
647
- end
648
- end
649
- end
650
- end