shoulda-matchers 2.7.0 → 2.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -3
  3. data/Appraisals +18 -0
  4. data/CONTRIBUTING.md +13 -29
  5. data/Gemfile +1 -4
  6. data/Gemfile.lock +2 -10
  7. data/NEWS.md +100 -14
  8. data/README.md +62 -58
  9. data/Rakefile +9 -16
  10. data/gemfiles/3.0.gemfile +11 -12
  11. data/gemfiles/3.0.gemfile.lock +15 -10
  12. data/gemfiles/3.1.gemfile +11 -12
  13. data/gemfiles/3.1.gemfile.lock +14 -10
  14. data/gemfiles/3.1_1.9.2.gemfile +12 -11
  15. data/gemfiles/3.1_1.9.2.gemfile.lock +14 -3
  16. data/gemfiles/3.2.gemfile +11 -12
  17. data/gemfiles/3.2.gemfile.lock +15 -10
  18. data/gemfiles/3.2_1.9.2.gemfile +12 -11
  19. data/gemfiles/3.2_1.9.2.gemfile.lock +14 -2
  20. data/gemfiles/4.0.0.gemfile +10 -12
  21. data/gemfiles/4.0.0.gemfile.lock +13 -10
  22. data/gemfiles/4.0.1.gemfile +10 -12
  23. data/gemfiles/4.0.1.gemfile.lock +13 -10
  24. data/gemfiles/4.1.gemfile +13 -15
  25. data/gemfiles/4.1.gemfile.lock +45 -50
  26. data/gemfiles/4.2.gemfile +36 -0
  27. data/gemfiles/4.2.gemfile.lock +245 -0
  28. data/lib/shoulda/matchers.rb +3 -1
  29. data/lib/shoulda/matchers/action_controller.rb +1 -1
  30. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  31. data/lib/shoulda/matchers/action_controller/route_params.rb +9 -4
  32. data/lib/shoulda/matchers/action_controller/{set_the_flash_matcher.rb → set_flash_matcher.rb} +34 -26
  33. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +125 -69
  34. data/lib/shoulda/matchers/active_model.rb +1 -2
  35. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +18 -5
  36. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +2 -2
  37. data/lib/shoulda/matchers/active_model/helpers.rb +4 -4
  38. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +10 -3
  39. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +1 -1
  40. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +3 -1
  41. data/lib/shoulda/matchers/active_model/{ensure_length_of_matcher.rb → validate_length_of_matcher.rb} +30 -20
  42. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +21 -0
  43. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -2
  44. data/lib/shoulda/matchers/active_record.rb +2 -0
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +96 -2
  46. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
  47. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +3 -3
  48. data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +22 -2
  49. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +30 -4
  50. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +19 -3
  51. data/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
  52. data/lib/shoulda/matchers/active_record/uniqueness/model.rb +45 -0
  53. data/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +36 -0
  54. data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +50 -0
  55. data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +24 -0
  56. data/lib/shoulda/matchers/{active_model → active_record}/validate_uniqueness_of_matcher.rb +76 -16
  57. data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +117 -51
  58. data/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +1 -1
  59. data/lib/shoulda/matchers/matcher_context.rb +35 -0
  60. data/lib/shoulda/matchers/rails_shim.rb +23 -0
  61. data/lib/shoulda/matchers/util.rb +28 -0
  62. data/lib/shoulda/matchers/version.rb +1 -1
  63. data/script/SUPPORTED_VERSIONS +1 -1
  64. data/spec/acceptance/active_model_integration_spec.rb +20 -0
  65. data/spec/acceptance/independent_matchers_spec.rb +64 -0
  66. data/spec/acceptance/rails_integration_spec.rb +142 -0
  67. data/spec/acceptance_spec_helper.rb +23 -0
  68. data/spec/support/acceptance/helpers.rb +29 -0
  69. data/spec/support/acceptance/helpers/active_model_helpers.rb +11 -0
  70. data/spec/support/acceptance/helpers/array_helpers.rb +13 -0
  71. data/spec/support/acceptance/helpers/base_helpers.rb +14 -0
  72. data/spec/support/acceptance/helpers/command_helpers.rb +51 -0
  73. data/spec/support/acceptance/helpers/file_helpers.rb +19 -0
  74. data/spec/support/acceptance/helpers/gem_helpers.rb +31 -0
  75. data/spec/support/acceptance/helpers/minitest_helpers.rb +19 -0
  76. data/spec/support/acceptance/helpers/pluralization_helpers.rb +13 -0
  77. data/spec/support/acceptance/helpers/rails_version_helpers.rb +11 -0
  78. data/spec/support/acceptance/helpers/rspec_helpers.rb +26 -0
  79. data/spec/support/acceptance/helpers/ruby_version_helpers.rb +9 -0
  80. data/spec/support/acceptance/helpers/step_helpers.rb +117 -0
  81. data/spec/support/acceptance/matchers/have_output.rb +31 -0
  82. data/spec/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +55 -0
  83. data/spec/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +103 -0
  84. data/spec/support/tests/bundle.rb +94 -0
  85. data/spec/support/tests/command_runner.rb +214 -0
  86. data/spec/support/tests/filesystem.rb +77 -0
  87. data/spec/support/tests/version.rb +45 -0
  88. data/spec/support/unit/capture.rb +34 -0
  89. data/spec/support/unit/helpers/active_model_helpers.rb +25 -0
  90. data/spec/support/unit/helpers/active_model_versions.rb +20 -0
  91. data/spec/support/unit/helpers/active_resource_builder.rb +27 -0
  92. data/spec/support/unit/helpers/allow_value_matcher_helpers.rb +15 -0
  93. data/spec/support/unit/helpers/class_builder.rb +72 -0
  94. data/spec/support/unit/helpers/confirmation_matcher_helpers.rb +17 -0
  95. data/spec/support/unit/helpers/controller_builder.rb +91 -0
  96. data/spec/support/unit/helpers/i18n_faker.rb +15 -0
  97. data/spec/support/unit/helpers/mailer_builder.rb +12 -0
  98. data/spec/support/unit/helpers/model_builder.rb +102 -0
  99. data/spec/support/unit/helpers/rails_versions.rb +28 -0
  100. data/spec/support/unit/i18n.rb +7 -0
  101. data/spec/support/unit/matchers/deprecate.rb +60 -0
  102. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +50 -0
  103. data/spec/support/unit/matchers/fail_with_message_matcher.rb +50 -0
  104. data/spec/support/unit/matchers/print_warning_including.rb +59 -0
  105. data/spec/support/unit/rails_application.rb +110 -0
  106. data/spec/support/unit/record_builder_with_i18n_validation_message.rb +69 -0
  107. data/spec/support/unit/record_validating_confirmation_builder.rb +56 -0
  108. data/spec/support/unit/record_with_different_error_attribute_builder.rb +92 -0
  109. data/spec/support/{shared_examples → unit/shared_examples}/numerical_submatcher.rb +0 -2
  110. data/spec/support/{shared_examples → unit/shared_examples}/numerical_type_submatcher.rb +0 -2
  111. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/callback_matcher_spec.rb +2 -2
  112. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/filter_param_matcher_spec.rb +2 -2
  113. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/redirect_to_matcher_spec.rb +3 -3
  114. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_template_matcher_spec.rb +2 -4
  115. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/render_with_layout_matcher_spec.rb +9 -6
  116. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/rescue_from_matcher_spec.rb +2 -2
  117. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/respond_with_matcher_spec.rb +2 -2
  118. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +126 -0
  119. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/route_params_spec.rb +2 -2
  120. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +167 -0
  121. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +294 -0
  122. data/spec/{shoulda → unit/shoulda}/matchers/action_controller/strong_parameters_matcher_spec.rb +19 -11
  123. data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +2 -2
  124. data/spec/{shoulda → unit/shoulda}/matchers/active_model/allow_value_matcher_spec.rb +49 -21
  125. data/spec/{shoulda → unit/shoulda}/matchers/active_model/disallow_value_matcher_spec.rb +8 -4
  126. data/spec/{shoulda → unit/shoulda}/matchers/active_model/exception_message_finder_spec.rb +4 -4
  127. data/spec/{shoulda → unit/shoulda}/matchers/active_model/have_secure_password_matcher_spec.rb +2 -2
  128. data/spec/{shoulda → unit/shoulda}/matchers/active_model/helpers_spec.rb +7 -3
  129. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
  130. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +1 -1
  131. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +1 -1
  132. data/spec/{shoulda → unit/shoulda}/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +1 -1
  133. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_absence_of_matcher_spec.rb +3 -3
  134. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_acceptance_of_matcher_spec.rb +2 -2
  135. data/spec/unit/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +63 -0
  136. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_exclusion_of_matcher_spec.rb +5 -4
  137. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_inclusion_of_matcher_spec.rb +7 -14
  138. data/spec/{shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb → unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb} +43 -23
  139. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_numericality_of_matcher_spec.rb +3 -4
  140. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_presence_of_matcher_spec.rb +3 -3
  141. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +127 -2
  142. data/spec/{shoulda → unit/shoulda}/matchers/active_model/validation_message_finder_spec.rb +8 -6
  143. data/spec/{shoulda → unit/shoulda}/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +2 -2
  144. data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matcher_spec.rb +217 -26
  145. data/spec/{shoulda → unit/shoulda}/matchers/active_record/association_matchers/model_reflection_spec.rb +2 -2
  146. data/spec/{shoulda → unit/shoulda}/matchers/active_record/define_enum_for_matcher_spec.rb +2 -2
  147. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_column_matcher_spec.rb +2 -2
  148. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_db_index_matcher_spec.rb +8 -5
  149. data/spec/{shoulda → unit/shoulda}/matchers/active_record/have_readonly_attributes_matcher_spec.rb +2 -2
  150. data/spec/{shoulda → unit/shoulda}/matchers/active_record/serialize_matcher_spec.rb +3 -3
  151. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_collection_spec.rb +29 -7
  152. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
  153. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/double_spec.rb +20 -10
  154. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/object_double_spec.rb +1 -1
  155. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/proxy_implementation_spec.rb +13 -6
  156. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak/stub_implementation_spec.rb +2 -2
  157. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +77 -0
  158. data/spec/{shoulda → unit/shoulda}/matchers/doublespeak_spec.rb +11 -3
  159. data/spec/{shoulda → unit/shoulda}/matchers/independent/delegate_method_matcher/stubbed_target_spec.rb +1 -1
  160. data/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb +517 -0
  161. data/spec/unit_spec_helper.rb +66 -0
  162. data/spec/warnings_spy/partitioner.rb +10 -3
  163. data/spec/warnings_spy/reader.rb +9 -20
  164. data/spec/warnings_spy/reporter.rb +2 -1
  165. metadata +212 -149
  166. data/features/activemodel_integration.feature +0 -15
  167. data/features/rails_integration.feature +0 -160
  168. data/features/step_definitions/activemodel_steps.rb +0 -21
  169. data/features/step_definitions/rails_steps.rb +0 -227
  170. data/features/support/env.rb +0 -6
  171. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +0 -70
  172. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +0 -113
  173. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +0 -153
  174. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +0 -47
  175. data/spec/shoulda/matchers/doublespeak/world_spec.rb +0 -70
  176. data/spec/shoulda/matchers/independent/delegate_method_matcher_spec.rb +0 -309
  177. data/spec/spec_helper.rb +0 -42
  178. data/spec/support/active_model_versions.rb +0 -13
  179. data/spec/support/active_resource_builder.rb +0 -29
  180. data/spec/support/activemodel_helpers.rb +0 -23
  181. data/spec/support/capture_helpers.rb +0 -19
  182. data/spec/support/class_builder.rb +0 -46
  183. data/spec/support/controller_builder.rb +0 -102
  184. data/spec/support/fail_with_message_including_matcher.rb +0 -44
  185. data/spec/support/fail_with_message_matcher.rb +0 -44
  186. data/spec/support/i18n_faker.rb +0 -10
  187. data/spec/support/mailer_builder.rb +0 -10
  188. data/spec/support/model_builder.rb +0 -81
  189. data/spec/support/rails_versions.rb +0 -26
  190. data/spec/support/test_application.rb +0 -120
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::SetSessionMatcher do
4
- context 'a controller that sets a session variable' do
5
- it 'accepts assigning to that variable' do
6
- expect(controller_with_session(var: 'hi')).to set_session(:var)
7
- end
8
-
9
- it 'accepts assigning to that variable with specifying the key by string' do
10
- expect(controller_with_session(var: 'hi')).to set_session('var')
11
- end
12
-
13
- it 'accepts assigning the correct value to that variable' do
14
- expect(controller_with_session(var: 'hi')).to set_session(:var).to('hi')
15
- end
16
-
17
- it 'rejects assigning another value to that variable' do
18
- expect(controller_with_session(var: 'hi')).not_to set_session(:var).to('other')
19
- end
20
-
21
- it 'rejects assigning to another variable' do
22
- expect(controller_with_session(var: 'hi')).not_to set_session(:other)
23
- end
24
-
25
- it 'accepts assigning nil to another variable' do
26
- expect(controller_with_session(var: 'hi')).to set_session(:other).to(nil)
27
- end
28
-
29
- it 'rejects assigning nil to that variable' do
30
- expect(controller_with_session(var: 'hi')).not_to set_session(:var).to(nil)
31
- end
32
-
33
- it 'accepts assigning nil to cleared variable' do
34
- expect(controller_with_session(var: nil)).to set_session(:var).to(nil)
35
- end
36
-
37
- it 'accepts assigning false to that variable' do
38
- expect(controller_with_session(var: false)).to set_session(:var).to(false)
39
- end
40
-
41
- it 'rejects assigning false to other variable' do
42
- expect(controller_with_session(var: false)).not_to set_session(:other).to(false)
43
- end
44
-
45
- it 'rejects assigning false to a variable with value' do
46
- expect(controller_with_session(var: 'hi')).not_to set_session(:other).to(false)
47
- end
48
-
49
- it 'accepts assigning to the same value in the test context' do
50
- context = stub(expected: 'value')
51
-
52
- expect(controller_with_session(var: 'value')).
53
- to set_session(:var).in_context(context).to { expected }
54
- end
55
-
56
- it 'rejects assigning to the another value in the test context' do
57
- context = stub(expected: 'other')
58
-
59
- expect(controller_with_session(var: 'unexpected')).
60
- not_to set_session(:var).in_context(context).to { expected }
61
- end
62
-
63
- it 'accepts assigning nil to another variable in the test context' do
64
- context = stub(expected: nil)
65
-
66
- expect(controller_with_session(var: 'hi')).
67
- to set_session(:other).in_context(context).to { expected }
68
- end
69
-
70
- it 'rejects assigning nil to that variable in the test context' do
71
- context = stub(expected: nil)
72
-
73
- expect(controller_with_session(var: 'hi')).
74
- not_to set_session(:var).in_context(context).to { expected }
75
- end
76
-
77
- it 'accepts assigning nil to a cleared variable in the test context' do
78
- context = stub(expected: nil)
79
-
80
- expect(controller_with_session(var: nil)).
81
- to set_session(:var).in_context(context).to { expected }
82
- end
83
-
84
- it 'accepts assigning false to that variable in the test context' do
85
- context = stub(expected: false)
86
-
87
- expect(controller_with_session(var: false)).
88
- to set_session(:var).in_context(context).to { expected }
89
- end
90
-
91
- it 'accepts assigning false to other variable in the test context' do
92
- context = stub(expected: false)
93
-
94
- expect(controller_with_session(var: false)).
95
- not_to set_session(:other).in_context(context).to { expected }
96
- end
97
-
98
- it 'accepts assigning false to other variable in the test context' do
99
- context = stub(expected: false)
100
-
101
- expect(controller_with_session(var: 'hi')).
102
- not_to set_session(:var).in_context(context).to { expected }
103
- end
104
-
105
- def controller_with_session(session_hash)
106
- build_fake_response do
107
- session_hash.each do |key, value|
108
- session[key] = value
109
- end
110
- end
111
- end
112
- end
113
- end
@@ -1,153 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActionController::SetTheFlashMatcher do
4
- it 'fails with unmatchable #to' do
5
- expect { set_the_flash.to(1) }.to raise_error('cannot match against 1')
6
- end
7
-
8
- context 'a controller that sets a flash message' do
9
- it 'accepts setting any flash message' do
10
- expect(controller_with_flash(notice: 'hi')).to set_the_flash
11
- end
12
-
13
- it 'accepts setting the exact flash message' do
14
- expect(controller_with_flash(notice: 'hi')).to set_the_flash.to('hi')
15
- end
16
-
17
- it 'accepts setting a matched flash message' do
18
- expect(controller_with_flash(notice: 'hello')).to set_the_flash.to(/he/)
19
- end
20
-
21
- it 'rejects setting a different flash message' do
22
- expect(controller_with_flash(notice: 'hi')).
23
- not_to set_the_flash.to('other')
24
- end
25
-
26
- it 'rejects setting a different pattern' do
27
- expect(controller_with_flash(notice: 'hi')).
28
- not_to set_the_flash.to(/other/)
29
- end
30
- end
31
-
32
- context 'a controller that sets a flash.now message' do
33
- it 'rejects setting any flash message' do
34
- expect(controller_with_flash_now).not_to set_the_flash
35
- end
36
-
37
- it 'accepts setting any flash.now message' do
38
- expect(controller_with_flash_now).to set_the_flash.now
39
- end
40
-
41
- it 'accepts setting the exact flash.now message' do
42
- expect(controller_with_flash_now(notice: 'hi')).
43
- to set_the_flash.now.to('hi')
44
- end
45
-
46
- it 'accepts setting a matched flash.now message' do
47
- expect(controller_with_flash_now(notice: 'flasher')).
48
- to set_the_flash.now.to(/lash/)
49
- end
50
-
51
- it 'rejects setting a different flash.now message' do
52
- expect(controller_with_flash_now(notice: 'hi')).
53
- not_to set_the_flash.now.to('other')
54
- end
55
-
56
- it 'rejects setting a different flash.now pattern' do
57
- expect(controller_with_flash_now(notice: 'hi')).
58
- not_to set_the_flash.now.to(/other/)
59
- end
60
- end
61
-
62
- context 'a controller that sets flash messages for multiple keys' do
63
- it 'accepts flash message for either key' do
64
- controller = controller_with_flash(notice: 'one', alert: 'two')
65
-
66
- expect(controller).to set_the_flash[:notice]
67
- expect(controller).to set_the_flash[:alert]
68
- end
69
-
70
- it 'rejects a flash message that is not one of the set keys' do
71
- expect(controller_with_flash(notice: 'one', alert: 'two')).
72
- not_to set_the_flash[:warning]
73
- end
74
-
75
- it 'accepts exact flash message of notice' do
76
- expect(controller_with_flash(notice: 'one', alert: 'two')).
77
- to set_the_flash[:notice].to('one')
78
- end
79
-
80
- it 'accepts setting a matched flash message of notice' do
81
- expect(controller_with_flash(notice: 'one', alert: 'two')).
82
- to set_the_flash[:notice].to(/on/)
83
- end
84
-
85
- it 'rejects setting a different flash message of notice' do
86
- expect(controller_with_flash(notice: 'one', alert: 'two')).
87
- not_to set_the_flash[:notice].to('other')
88
- end
89
-
90
- it 'rejects setting a different pattern' do
91
- expect(controller_with_flash(notice: 'one', alert: 'two')).
92
- not_to set_the_flash[:notice].to(/other/)
93
- end
94
- end
95
-
96
- context 'a controller that sets flash and flash.now' do
97
- it 'accepts setting any flash.now message' do
98
- controller = build_fake_response do
99
- flash.now[:notice] = 'value'
100
- flash[:success] = 'great job'
101
- end
102
-
103
- expect(controller).to set_the_flash.now
104
- expect(controller).to set_the_flash
105
- end
106
-
107
- it 'accepts setting a matched flash.now message' do
108
- controller = build_fake_response do
109
- flash.now[:notice] = 'value'
110
- flash[:success] = 'great job'
111
- end
112
-
113
- expect(controller).to set_the_flash.now.to(/value/)
114
- expect(controller).to set_the_flash.to(/great/)
115
- end
116
-
117
- it 'rejects setting a different flash.now message' do
118
- controller = build_fake_response do
119
- flash.now[:notice] = 'value'
120
- flash[:success] = 'great job'
121
- end
122
-
123
- expect(controller).not_to set_the_flash.now.to('other')
124
- expect(controller).not_to set_the_flash.to('other')
125
- end
126
- end
127
-
128
- context 'a controller that does not set a flash message' do
129
- it 'rejects setting any flash message' do
130
- expect(controller_with_no_flashes).not_to set_the_flash
131
- end
132
- end
133
-
134
- def controller_with_no_flashes
135
- build_fake_response
136
- end
137
-
138
- def controller_with_flash(flash_hash)
139
- build_fake_response do
140
- flash_hash.each do |key, value|
141
- flash[key] = value
142
- end
143
- end
144
- end
145
-
146
- def controller_with_flash_now(flash_hash = { notice: 'hi' })
147
- build_fake_response do
148
- flash_hash.each do |key, value|
149
- flash.now[key] = value
150
- end
151
- end
152
- end
153
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher do
4
- context '#description' do
5
- it 'states that the confirmation must match its base attribute' do
6
- expect(matcher.description).to eq 'require attr_confirmation to match attr'
7
- end
8
- end
9
-
10
- context 'a model with a confirmation validation' do
11
- it 'accepts' do
12
- expect(validating_confirmation).to matcher
13
- end
14
-
15
- it 'does not override the default message with a blank' do
16
- expect(validating_confirmation).to matcher.with_message(nil)
17
- end
18
- end
19
-
20
- context 'a model without a confirmation validation' do
21
- it 'rejects' do
22
- expect(define_model(:example, attr: :string).new).not_to matcher
23
- end
24
- end
25
-
26
- context 'a confirmation validation with a custom message' do
27
- it 'accepts when the message matches' do
28
- expect(validating_confirmation(message: 'custom')).
29
- to matcher.with_message(/custom/)
30
- end
31
-
32
- it 'rejects when the messages do not match' do
33
- expect(validating_confirmation(message: 'custom')).
34
- not_to matcher.with_message(/wrong/)
35
- end
36
- end
37
-
38
- def matcher
39
- validate_confirmation_of(:attr)
40
- end
41
-
42
- def validating_confirmation(options = {})
43
- define_model(:example, attr: :string) do
44
- validates_confirmation_of :attr, options
45
- end.new
46
- end
47
- end
@@ -1,70 +0,0 @@
1
- require '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
- DoubleCollection.expects(:new).with(:klass).returns(:klass).once
8
- world = described_class.new
9
- world.double_collection_for(:klass)
10
- world.double_collection_for(:klass)
11
- end
12
-
13
- it 'returns the created DoubleCollection' do
14
- double_collection = Object.new
15
- DoubleCollection.stubs(:new).with(:klass).returns(double_collection)
16
- world = described_class.new
17
- expect(world.double_collection_for(:klass)).to be double_collection
18
- end
19
- end
20
-
21
- describe '#with_doubles_activated' do
22
- it 'installs all doubles, yields the block, then uninstalls them all' do
23
- block_called = false
24
-
25
- double_collections = Array.new(3) do
26
- stub.tap do |double_collection|
27
- sequence = sequence('with_doubles_activated')
28
- double_collection.expects(:activate).in_sequence(sequence)
29
- double_collection.expects(:deactivate).in_sequence(sequence)
30
- end
31
- end
32
-
33
- world = described_class.new
34
-
35
- DoubleCollection.stubs(:new).
36
- with(:klass1).
37
- returns(double_collections[0])
38
- DoubleCollection.stubs(:new).
39
- with(:klass2).
40
- returns(double_collections[1])
41
- DoubleCollection.stubs(:new).
42
- with(:klass3).
43
- returns(double_collections[2])
44
- world.double_collection_for(:klass1)
45
- world.double_collection_for(:klass2)
46
- world.double_collection_for(:klass3)
47
-
48
- world.with_doubles_activated { block_called = true }
49
-
50
- expect(block_called).to eq true
51
- end
52
-
53
- it 'still makes sure to uninstall all doubles even if the block raises an error' do
54
- double_collection = stub()
55
- double_collection.stubs(:activate)
56
- double_collection.expects(:deactivate)
57
-
58
- world = described_class.new
59
-
60
- DoubleCollection.stubs(:new).returns(double_collection)
61
- world.double_collection_for(:klass)
62
-
63
- begin
64
- world.with_doubles_activated { raise 'error' }
65
- rescue RuntimeError
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,309 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::Independent::DelegateMethodMatcher do
4
- describe '#description' do
5
- context 'against an instance' do
6
- subject { Object.new }
7
-
8
- context 'by default' do
9
- it 'states that it should delegate method to the right object' do
10
- matcher = delegate_method(:method_name).to(:target)
11
-
12
- expect(matcher.description).
13
- to eq 'delegate #method_name to #target object'
14
- end
15
- end
16
-
17
- context 'with #as chain' do
18
- it 'states that it should delegate method to the right object and method' do
19
- matcher = delegate_method(:method_name).to(:target).as(:alternate)
20
- message = 'delegate #method_name to #target object as #alternate'
21
-
22
- expect(matcher.description).to eq message
23
- end
24
- end
25
-
26
- context 'with #with_argument chain' do
27
- it 'states that it should delegate method to the right object with right argument' do
28
- matcher = delegate_method(:method_name).to(:target).
29
- with_arguments(:foo, bar: [1, 2])
30
- message = 'delegate #method_name to #target object passing arguments [:foo, {:bar=>[1, 2]}]'
31
-
32
- expect(matcher.description).to eq message
33
- end
34
- end
35
- end
36
-
37
- context 'against a class' do
38
- subject { Object }
39
-
40
- context 'by default' do
41
- it 'states that it should delegate method to the right object' do
42
- matcher = delegate_method(:method_name).to(:target)
43
-
44
- expect(matcher.description).
45
- to eq 'delegate .method_name to .target object'
46
- end
47
- end
48
-
49
- context 'with #as chain' do
50
- it 'states that it should delegate method to the right object and method' do
51
- matcher = delegate_method(:method_name).to(:target).as(:alternate)
52
- message = 'delegate .method_name to .target object as .alternate'
53
-
54
- expect(matcher.description).to eq message
55
- end
56
- end
57
-
58
- context 'with #with_argument chain' do
59
- it 'states that it should delegate method to the right object with right argument' do
60
- matcher = delegate_method(:method_name).to(:target).
61
- with_arguments(:foo, bar: [1, 2])
62
- message = 'delegate .method_name to .target object passing arguments [:foo, {:bar=>[1, 2]}]'
63
-
64
- expect(matcher.description).to eq message
65
- end
66
- end
67
- end
68
- end
69
-
70
- it 'raises an error if the target method was never specified before matching' do
71
- expect {
72
- expect(Object.new).to delegate_method(:name)
73
- }.to raise_error described_class::TargetNotDefinedError
74
- end
75
-
76
- context 'stubbing an instance delegating method' do
77
- it 'only happens temporarily and is removed after the match' do
78
- define_class(:company) do
79
- def name
80
- 'Acme Company'
81
- end
82
- end
83
-
84
- define_class(:person) do
85
- def company_name
86
- company.name
87
- end
88
-
89
- def company
90
- Company.new
91
- end
92
- end
93
-
94
- person = Person.new
95
- matcher = delegate_method(:company_name).to(:company).as(:name)
96
- matcher.matches?(person)
97
-
98
- expect(person.company.name).to eq 'Acme Company'
99
- end
100
- end
101
-
102
- context 'given a method that does not delegate' do
103
- before do
104
- define_class(:post_office) do
105
- def deliver_mail
106
- :delivered
107
- end
108
- end
109
- end
110
-
111
- it 'rejects' do
112
- post_office = PostOffice.new
113
- expect(post_office).not_to delegate_method(:deliver_mail).to(:mailman)
114
- end
115
-
116
- it 'has a failure message that indicates which method should have been delegated' do
117
- post_office = PostOffice.new
118
- message = [
119
- 'Expected PostOffice to delegate #deliver_mail to #mailman object',
120
- 'Method calls sent to PostOffice#mailman: (none)'
121
- ].join("\n")
122
-
123
- expect {
124
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
125
- }.to fail_with_message(message)
126
- end
127
-
128
- it 'uses the proper syntax for class methods in errors' do
129
- message = [
130
- 'Expected PostOffice to delegate .deliver_mail to .mailman object',
131
- 'Method calls sent to PostOffice.mailman: (none)'
132
- ].join("\n")
133
-
134
- expect {
135
- expect(PostOffice).to delegate_method(:deliver_mail).to(:mailman)
136
- }.to fail_with_message(message)
137
- end
138
- end
139
-
140
- context 'given a method that delegates properly' do
141
- before do
142
- define_class(:mailman)
143
-
144
- define_class(:post_office) do
145
- def deliver_mail
146
- mailman.deliver_mail
147
- end
148
-
149
- def mailman
150
- Mailman.new
151
- end
152
- end
153
- end
154
-
155
- it 'accepts' do
156
- post_office = PostOffice.new
157
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
158
- end
159
-
160
- it 'produces the correct failure message if the assertion was negated' do
161
- post_office = PostOffice.new
162
- message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object, but it did'
163
-
164
- expect {
165
- expect(post_office).not_to delegate_method(:deliver_mail).to(:mailman)
166
- }.to fail_with_message(message)
167
- end
168
- end
169
-
170
- context 'given a private method that delegates properly' do
171
- before do
172
- define_class(:mailman)
173
-
174
- define_class(:post_office) do
175
- def deliver_mail
176
- mailman.deliver_mail
177
- end
178
-
179
- def mailman
180
- Mailman.new
181
- end
182
-
183
- private :mailman
184
- end
185
- end
186
-
187
- it 'accepts' do
188
- post_office = PostOffice.new
189
- expect(post_office).to delegate_method(:deliver_mail).to(:mailman)
190
- end
191
- end
192
-
193
- context 'given a method that delegates properly with arguments' do
194
- before do
195
- define_class(:mailman)
196
-
197
- define_class(:post_office) do
198
- def deliver_mail(*args)
199
- mailman.deliver_mail('221B Baker St.', hastily: true)
200
- end
201
-
202
- def mailman
203
- Mailman.new
204
- end
205
- end
206
- end
207
-
208
- context 'when given the correct arguments' do
209
- it 'accepts' do
210
- post_office = PostOffice.new
211
- expect(post_office).to delegate_method(:deliver_mail).
212
- to(:mailman).with_arguments('221B Baker St.', hastily: true)
213
- end
214
-
215
- it 'produces the correct failure message if the assertion was negated' do
216
- post_office = PostOffice.new
217
- message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object passing arguments ["221B Baker St.", {:hastily=>true}], but it did'
218
-
219
- expect {
220
- expect(post_office).
221
- not_to delegate_method(:deliver_mail).
222
- to(:mailman).
223
- with_arguments('221B Baker St.', hastily: true)
224
- }.to fail_with_message(message)
225
- end
226
- end
227
-
228
- context 'when not given the correct arguments' do
229
- it 'rejects' do
230
- post_office = PostOffice.new
231
- expect(post_office).
232
- not_to delegate_method(:deliver_mail).to(:mailman).
233
- with_arguments('123 Nowhere Ln.')
234
- end
235
-
236
- it 'has a failure message that indicates which arguments were expected' do
237
- post_office = PostOffice.new
238
- message = [
239
- 'Expected PostOffice to delegate #deliver_mail to #mailman object passing arguments ["123 Nowhere Ln."]',
240
- 'Method calls sent to PostOffice#mailman:',
241
- '1) deliver_mail("221B Baker St.", {:hastily=>true})'
242
- ].join("\n")
243
-
244
- expect {
245
- expect(post_office).to delegate_method(:deliver_mail).
246
- to(:mailman).with_arguments('123 Nowhere Ln.')
247
- }.to fail_with_message(message)
248
- end
249
- end
250
- end
251
-
252
- context 'given a method that delegates properly to a method of a different name' do
253
- before do
254
- define_class(:mailman)
255
-
256
- define_class(:post_office) do
257
- def deliver_mail
258
- mailman.deliver_mail_and_avoid_dogs
259
- end
260
-
261
- def mailman
262
- Mailman.new
263
- end
264
- end
265
- end
266
-
267
- context 'when given the correct method name' do
268
- it 'accepts' do
269
- post_office = PostOffice.new
270
- expect(post_office).to delegate_method(:deliver_mail).
271
- to(:mailman).as(:deliver_mail_and_avoid_dogs)
272
- end
273
-
274
- it 'produces the correct failure message if the assertion was negated' do
275
- post_office = PostOffice.new
276
- message = 'Expected PostOffice not to delegate #deliver_mail to #mailman object as #deliver_mail_and_avoid_dogs, but it did'
277
-
278
- expect {
279
- expect(post_office).
280
- not_to delegate_method(:deliver_mail).
281
- to(:mailman).
282
- as(:deliver_mail_and_avoid_dogs)
283
- }.to fail_with_message(message)
284
- end
285
- end
286
-
287
- context 'when given an incorrect method name' do
288
- it 'rejects' do
289
- post_office = PostOffice.new
290
- expect(post_office).
291
- not_to delegate_method(:deliver_mail).to(:mailman).as(:watch_tv)
292
- end
293
-
294
- it 'has a failure message that indicates which method was expected' do
295
- post_office = PostOffice.new
296
- message = [
297
- 'Expected PostOffice to delegate #deliver_mail to #mailman object as #watch_tv',
298
- 'Method calls sent to PostOffice#mailman:',
299
- '1) deliver_mail_and_avoid_dogs()'
300
- ].join("\n")
301
-
302
- expect {
303
- expect(post_office).to delegate_method(:deliver_mail).
304
- to(:mailman).as(:watch_tv)
305
- }.to fail_with_message(message)
306
- end
307
- end
308
- end
309
- end