shoulda-matchers 2.8.0 → 3.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.hound_config/ruby.yml +7 -0
  3. data/.travis.yml +11 -54
  4. data/Appraisals +45 -100
  5. data/CONTRIBUTING.md +51 -7
  6. data/Gemfile +7 -19
  7. data/Gemfile.lock +60 -134
  8. data/Guardfile +5 -0
  9. data/NEWS.md +203 -0
  10. data/README.md +95 -50
  11. data/Rakefile +1 -0
  12. data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
  13. data/gemfiles/4.0.0.gemfile +10 -7
  14. data/gemfiles/4.0.0.gemfile.lock +103 -79
  15. data/gemfiles/4.0.1.gemfile +10 -7
  16. data/gemfiles/4.0.1.gemfile.lock +109 -83
  17. data/gemfiles/4.1.gemfile +10 -7
  18. data/gemfiles/4.1.gemfile.lock +109 -85
  19. data/gemfiles/4.2.gemfile +10 -9
  20. data/gemfiles/4.2.gemfile.lock +86 -78
  21. data/lib/shoulda/matchers.rb +13 -18
  22. data/lib/shoulda/matchers/action_controller.rb +4 -1
  23. data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
  24. data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
  25. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
  26. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
  27. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
  28. data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
  29. data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
  30. data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
  31. data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
  32. data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
  33. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
  34. data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
  35. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
  36. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
  37. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
  38. data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
  39. data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
  40. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
  41. data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
  42. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
  43. data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
  44. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
  45. data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
  46. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
  47. data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
  48. data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
  49. data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
  50. data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
  51. data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
  52. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
  53. data/lib/shoulda/matchers/configuration.rb +20 -0
  54. data/lib/shoulda/matchers/doublespeak.rb +11 -1
  55. data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
  56. data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
  57. data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
  58. data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
  59. data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
  60. data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
  61. data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
  62. data/lib/shoulda/matchers/integrations.rb +43 -0
  63. data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
  64. data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
  65. data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
  66. data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
  67. data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
  68. data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
  69. data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
  70. data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
  71. data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
  72. data/lib/shoulda/matchers/integrations/rails.rb +12 -0
  73. data/lib/shoulda/matchers/integrations/registry.rb +28 -0
  74. data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
  75. data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
  76. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
  77. data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
  78. data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
  79. data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
  80. data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
  81. data/lib/shoulda/matchers/rails_shim.rb +0 -40
  82. data/lib/shoulda/matchers/version.rb +1 -1
  83. data/script/SUPPORTED_VERSIONS +1 -1
  84. data/script/update_gems_in_all_appraisals +14 -0
  85. data/shoulda-matchers.gemspec +2 -2
  86. data/spec/acceptance/active_model_integration_spec.rb +4 -1
  87. data/spec/acceptance/independent_matchers_spec.rb +6 -6
  88. data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
  89. data/spec/acceptance/rails_integration_spec.rb +15 -5
  90. data/spec/acceptance_spec_helper.rb +8 -0
  91. data/spec/doublespeak_spec_helper.rb +14 -0
  92. data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
  93. data/spec/support/acceptance/helpers.rb +2 -0
  94. data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
  95. data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
  96. data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
  97. data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
  98. data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
  99. data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
  100. data/spec/support/acceptance/matchers/have_output.rb +1 -1
  101. data/spec/support/tests/bundle.rb +1 -1
  102. data/spec/support/tests/command_runner.rb +25 -13
  103. data/spec/support/tests/current_bundle.rb +47 -0
  104. data/spec/support/tests/database.rb +28 -0
  105. data/spec/support/tests/database_adapters/postgresql.rb +25 -0
  106. data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
  107. data/spec/support/tests/database_configuration.rb +33 -0
  108. data/spec/support/tests/database_configuration_registry.rb +28 -0
  109. data/spec/support/tests/filesystem.rb +25 -2
  110. data/spec/support/unit/helpers/active_record_versions.rb +12 -0
  111. data/spec/support/unit/helpers/class_builder.rb +6 -2
  112. data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
  113. data/spec/support/unit/helpers/controller_builder.rb +0 -28
  114. data/spec/support/unit/helpers/database_helpers.rb +18 -0
  115. data/spec/support/unit/helpers/model_builder.rb +38 -6
  116. data/spec/support/unit/helpers/rails_versions.rb +2 -2
  117. data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
  118. data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
  119. data/spec/support/unit/rails_application.rb +29 -13
  120. data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
  121. data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
  122. data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
  123. data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
  124. data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
  125. data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
  126. data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
  127. data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
  128. data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
  129. data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
  130. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
  131. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
  132. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
  133. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
  134. data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
  135. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
  136. data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
  137. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
  138. data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
  139. data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
  140. data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
  141. data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
  142. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
  143. data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
  144. data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
  145. data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
  146. data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
  147. data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
  148. data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
  149. data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
  150. data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
  151. data/spec/unit_spec_helper.rb +15 -14
  152. data/spec/warnings_spy.rb +1 -1
  153. metadata +68 -29
  154. data/docs.watchr +0 -5
  155. data/gemfiles/3.0.gemfile +0 -26
  156. data/gemfiles/3.0.gemfile.lock +0 -173
  157. data/gemfiles/3.1.gemfile +0 -32
  158. data/gemfiles/3.1.gemfile.lock +0 -212
  159. data/gemfiles/3.1_1.9.2.gemfile +0 -32
  160. data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
  161. data/gemfiles/3.2.gemfile +0 -33
  162. data/gemfiles/3.2.gemfile.lock +0 -212
  163. data/gemfiles/3.2_1.9.2.gemfile +0 -31
  164. data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
  165. data/lib/shoulda/matchers/assertion_error.rb +0 -27
  166. data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
  167. data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
  168. data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
  169. data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
  170. data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
  171. data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -1,167 +1,43 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
- describe Shoulda::Matchers::ActionController, type: :controller do
4
- describe '#set_the_flash' do
5
- it 'is deprecated in favor of #set_flash' do
6
- expect { set_the_flash }.to deprecate(:set_the_flash, :set_flash)
3
+ describe Shoulda::Matchers::ActionController::SetFlashMatcher, type: :controller do
4
+ it_behaves_like 'set session or flash matcher' do
5
+ def store_name
6
+ 'flash'
7
7
  end
8
8
 
9
- it 'still works regardless' do
10
- silence_warnings do
11
- expect(controller_with_flash(notice: 'hi')).to set_the_flash
12
- end
13
- end
14
- end
15
-
16
- describe '#set_flash' do
17
- it 'fails with unmatchable #to' do
18
- expect { set_flash.to(1) }.to raise_error('cannot match against 1')
9
+ def set_store
10
+ set_flash
19
11
  end
20
12
 
21
- context 'a controller that sets a flash message' do
22
- it 'accepts setting any flash message' do
23
- expect(controller_with_flash(notice: 'hi')).to set_flash
24
- end
25
-
26
- it 'accepts setting the exact flash message' do
27
- expect(controller_with_flash(notice: 'hi')).to set_flash.to('hi')
28
- end
29
-
30
- it 'accepts setting a matched flash message' do
31
- expect(controller_with_flash(notice: 'hello')).to set_flash.to(/he/)
32
- end
33
-
34
- it 'rejects setting a different flash message' do
35
- expect(controller_with_flash(notice: 'hi')).
36
- not_to set_flash.to('other')
37
- end
38
-
39
- it 'rejects setting a different pattern' do
40
- expect(controller_with_flash(notice: 'hi')).
41
- not_to set_flash.to(/other/)
42
- end
13
+ def store_within(controller)
14
+ controller.flash
43
15
  end
16
+ end
44
17
 
45
- context 'a controller that sets a flash.now message' do
46
- it 'rejects setting any flash message' do
47
- expect(controller_with_flash_now).not_to set_flash
48
- end
49
-
50
- it 'accepts setting any flash.now message' do
51
- expect(controller_with_flash_now).to set_flash.now
52
- end
53
-
54
- it 'accepts setting the exact flash.now message' do
55
- expect(controller_with_flash_now(notice: 'hi')).
56
- to set_flash.now.to('hi')
57
- end
58
-
59
- it 'accepts setting a matched flash.now message' do
60
- expect(controller_with_flash_now(notice: 'flasher')).
61
- to set_flash.now.to(/lash/)
62
- end
63
-
64
- it 'rejects setting a different flash.now message' do
65
- expect(controller_with_flash_now(notice: 'hi')).
66
- not_to set_flash.now.to('other')
67
- end
68
-
69
- it 'rejects setting a different flash.now pattern' do
70
- expect(controller_with_flash_now(notice: 'hi')).
71
- not_to set_flash.now.to(/other/)
72
- end
73
- end
74
-
75
- context 'a controller that sets flash messages for multiple keys' do
76
- it 'accepts flash message for either key' do
77
- controller = controller_with_flash(notice: 'one', alert: 'two')
78
-
79
- expect(controller).to set_flash[:notice]
80
- expect(controller).to set_flash[:alert]
81
- end
82
-
83
- it 'rejects a flash message that is not one of the set keys' do
84
- expect(controller_with_flash(notice: 'one', alert: 'two')).
85
- not_to set_flash[:warning]
86
- end
87
-
88
- it 'accepts exact flash message of notice' do
89
- expect(controller_with_flash(notice: 'one', alert: 'two')).
90
- to set_flash[:notice].to('one')
91
- end
92
-
93
- it 'accepts setting a matched flash message of notice' do
94
- expect(controller_with_flash(notice: 'one', alert: 'two')).
95
- to set_flash[:notice].to(/on/)
96
- end
97
-
98
- it 'rejects setting a different flash message of notice' do
99
- expect(controller_with_flash(notice: 'one', alert: 'two')).
100
- not_to set_flash[:notice].to('other')
101
- end
102
-
103
- it 'rejects setting a different pattern' do
104
- expect(controller_with_flash(notice: 'one', alert: 'two')).
105
- not_to set_flash[:notice].to(/other/)
106
- end
18
+ it_behaves_like 'set session or flash matcher' do
19
+ def store_name
20
+ 'flash.now'
107
21
  end
108
22
 
109
- context 'a controller that sets flash and flash.now' do
110
- it 'accepts setting any flash.now message' do
111
- controller = build_fake_response do
112
- flash.now[:notice] = 'value'
113
- flash[:success] = 'great job'
114
- end
115
-
116
- expect(controller).to set_flash.now
117
- expect(controller).to set_flash
118
- end
119
-
120
- it 'accepts setting a matched flash.now message' do
121
- controller = build_fake_response do
122
- flash.now[:notice] = 'value'
123
- flash[:success] = 'great job'
124
- end
125
-
126
- expect(controller).to set_flash.now.to(/value/)
127
- expect(controller).to set_flash.to(/great/)
128
- end
129
-
130
- it 'rejects setting a different flash.now message' do
131
- controller = build_fake_response do
132
- flash.now[:notice] = 'value'
133
- flash[:success] = 'great job'
134
- end
135
-
136
- expect(controller).not_to set_flash.now.to('other')
137
- expect(controller).not_to set_flash.to('other')
138
- end
23
+ def set_store
24
+ set_flash.now
139
25
  end
140
26
 
141
- context 'a controller that does not set a flash message' do
142
- it 'rejects setting any flash message' do
143
- expect(controller_with_no_flashes).not_to set_flash
144
- end
27
+ def store_within(controller)
28
+ controller.flash.now
145
29
  end
146
30
  end
147
31
 
148
- def controller_with_no_flashes
149
- build_fake_response
150
- end
151
-
152
- def controller_with_flash(flash_hash)
153
- build_fake_response do
154
- flash_hash.each do |key, value|
155
- flash[key] = value
32
+ context 'when the controller sets both flash and flash.now' do
33
+ it 'does not mix flash and flash.now' do
34
+ controller = build_fake_response do
35
+ flash['key for flash'] = 'value for flash'
36
+ flash.now['key for flash.now'] = 'value for flash.now'
156
37
  end
157
- end
158
- end
159
38
 
160
- def controller_with_flash_now(flash_hash = { notice: 'hi' })
161
- build_fake_response do
162
- flash_hash.each do |key, value|
163
- flash.now[key] = value
164
- end
39
+ expect(controller).not_to set_flash['key for flash.now']
40
+ expect(controller).not_to set_flash.now['key for flash']
165
41
  end
166
42
  end
167
43
  end
@@ -1,294 +1,17 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
- describe Shoulda::Matchers::ActionController, '#set_session', type: :controller do
4
- context 'passing an argument to the initializer' do
5
- it 'is deprecated in favor of using #[]' do
6
- expectation = proc { set_session(:foo) }
7
-
8
- expect(&expectation).to print_warning_including(
9
- 'Passing a key to set_session is deprecated'
10
- )
11
- end
12
-
13
- it 'still works regardless' do
14
- silence_warnings do
15
- expect(controller_with_session(var: 'hi')).to set_session(:var)
16
- end
17
- end
18
- end
19
-
20
- context 'a controller that sets a session variable' do
21
- context 'without any qualifiers' do
22
- it 'accepts' do
23
- expect(controller_with_session(var: 'hi')).to set_session
24
- end
25
- end
26
-
27
- context 'with #to' do
28
- context 'given a static value' do
29
- context 'when any key in session has the given value' do
30
- it 'accepts' do
31
- expect(controller_with_session(var: 'hi')).
32
- to set_session.to('hi')
33
- end
34
-
35
- it 'accepts given nil' do
36
- silence_warnings do
37
- expect(controller_with_session(var: nil)).
38
- to set_session.to(nil)
39
- end
40
- end
41
-
42
- it 'accepts given false' do
43
- expect(controller_with_session(var: false)).
44
- to set_session.to(false)
45
- end
46
- end
47
-
48
- context 'when no key in session has the given value' do
49
- it 'rejects' do
50
- expect(controller_with_session(var: 'hi')).
51
- not_to set_session.to('different')
52
- end
53
- end
54
- end
55
-
56
- context 'given a dynamic value' do
57
- context 'when any key in session has the given value' do
58
- it 'accepts' do
59
- context = double(expected: 'hi')
60
- expect(controller_with_session(var: 'hi')).
61
- to set_session.in_context(context).to { expected }
62
- end
63
-
64
- it 'accepts given nil' do
65
- silence_warnings do
66
- context = double(expected: nil)
67
- expect(controller_with_session(var: nil)).
68
- to set_session.in_context(context).to { expected }
69
- end
70
- end
71
-
72
- it 'accepts given false' do
73
- context = double(expected: false)
74
- expect(controller_with_session(var: false)).
75
- to set_session.in_context(context).to { expected }
76
- end
77
- end
78
-
79
- context 'when no key in session has the given value' do
80
- it 'rejects' do
81
- context = double(expected: 'different')
82
- expect(controller_with_session(var: 'hi')).
83
- not_to set_session.in_context(context).to { expected }
84
- end
85
- end
86
- end
87
-
88
- context 'given a regexp' do
89
- context 'when any value in session matches the regexp' do
90
- it 'accepts' do
91
- expect(controller_with_session(var: 'hello')).
92
- to set_session.to(/ello/)
93
- end
94
- end
95
-
96
- context 'when no value in session matches the regexp' do
97
- it 'rejects' do
98
- expect(controller_with_session(var: 'hello')).
99
- not_to set_session.to(/different/)
100
- end
101
- end
102
- end
103
- end
104
-
105
- context 'with #[]' do
106
- context 'when the given key is present in session' do
107
- it 'accepts' do
108
- expect(controller_with_session(var: 'hi')).to set_session[:var]
109
- end
110
-
111
- it 'accepts when expected key is a string' do
112
- expect(controller_with_session(var: 'hi')).to set_session['var']
113
- end
114
- end
115
-
116
- context 'when the given key is not present in session' do
117
- it 'rejects' do
118
- expect(controller_with_session(var: 'hi')).not_to set_session[:other]
119
- end
120
- end
121
- end
122
-
123
- context 'with #[] + #to' do
124
- context 'given a static value' do
125
- context 'when the given key and value are present in session' do
126
- it 'accepts' do
127
- expect(controller_with_session(var: 'hi')).
128
- to set_session[:var].to('hi')
129
- end
130
-
131
- it 'accepts given nil' do
132
- silence_warnings do
133
- expect(controller_with_session(var: nil)).
134
- to set_session[:var].to(nil)
135
- end
136
- end
137
-
138
- it 'accepts given false' do
139
- expect(controller_with_session(var: false)).
140
- to set_session[:var].to(false)
141
- end
142
- end
143
-
144
- context 'when the given key is present in session but not the given value' do
145
- it 'rejects' do
146
- expect(controller_with_session(var: 'hi')).
147
- not_to set_session[:var].to('other')
148
- end
149
-
150
- it 'rejects given nil' do
151
- expect(controller_with_session(var: 'hi')).
152
- not_to set_session[:var].to(nil)
153
- end
154
- end
155
-
156
- context 'when the given key is not present in session' do
157
- it 'accepts given nil' do
158
- silence_warnings do
159
- expect(controller_with_session(var: 'hi')).
160
- to set_session[:other].to(nil)
161
- end
162
- end
163
-
164
- it 'rejects given false' do
165
- expect(controller_with_session(var: false)).
166
- not_to set_session[:other].to(false)
167
- end
168
- end
169
- end
170
-
171
- context 'given a dynamic value' do
172
- context 'when the given key and value are present in session' do
173
- it 'accepts' do
174
- context = double(expected: 'value')
175
-
176
- expect(controller_with_session(var: 'value')).
177
- to set_session[:var].in_context(context).to { expected }
178
- end
179
-
180
- it 'accepts given nil' do
181
- silence_warnings do
182
- context = double(expected: nil)
183
-
184
- expect(controller_with_session(var: nil)).
185
- to set_session[:var].in_context(context).to { expected }
186
- end
187
- end
188
-
189
- it 'accepts given false' do
190
- context = double(expected: false)
191
-
192
- expect(controller_with_session(var: false)).
193
- to set_session[:var].in_context(context).to { expected }
194
- end
195
- end
196
-
197
- context 'when the given key is present in session but not the given value' do
198
- it 'rejects given nil' do
199
- context = double(expected: nil)
200
-
201
- expect(controller_with_session(var: 'hi')).
202
- not_to set_session[:var].in_context(context).to { expected }
203
- end
204
-
205
- it 'rejects given false' do
206
- context = double(expected: false)
207
-
208
- expect(controller_with_session(var: 'hi')).
209
- not_to set_session[:var].in_context(context).to { expected }
210
- end
211
- end
212
-
213
- context 'when the given key is not present in session' do
214
- it 'rejects' do
215
- context = double(expected: 'other')
216
-
217
- expect(controller_with_session(var: 'unexpected')).
218
- not_to set_session[:var].in_context(context).to { expected }
219
- end
220
-
221
- it 'accepts given nil' do
222
- silence_warnings do
223
- context = double(expected: nil)
224
-
225
- expect(controller_with_session(var: 'hi')).
226
- to set_session[:other].in_context(context).to { expected }
227
- end
228
- end
229
-
230
- it 'rejects given false' do
231
- context = double(expected: false)
232
-
233
- expect(controller_with_session(var: false)).
234
- not_to set_session[:other].in_context(context).to { expected }
235
- end
236
- end
237
- end
238
- end
239
- end
240
-
241
- context 'a controller that does not set any session variables' do
242
- context 'without any qualifiers' do
243
- it 'rejects' do
244
- expect(controller_without_session).not_to set_session
245
- end
246
- end
247
-
248
- context 'with #[]' do
249
- it 'rejects' do
250
- expect(controller_without_session).
251
- not_to set_session['any key']
252
- end
253
- end
254
-
255
- context 'with #to' do
256
- it 'rejects' do
257
- expect(controller_without_session).
258
- not_to set_session.to('any value')
259
- end
3
+ describe Shoulda::Matchers::ActionController::SetSessionMatcher, type: :controller do
4
+ it_behaves_like 'set session or flash matcher' do
5
+ def store_name
6
+ 'session'
260
7
  end
261
8
 
262
- context 'with #[] + #to' do
263
- it 'rejects' do
264
- expect(controller_without_session).
265
- not_to set_session['any key'].to('any value')
266
- end
267
-
268
- it 'prints a warning when using .to(nil) to assert that a variable is unset' do
269
- expectation = proc do
270
- expect(controller_without_session).to set_session['any key'].to(nil)
271
- end
272
-
273
- expected_warning = <<EOT
274
- Using `should set_session[...].to(nil)` to assert that a variable is unset is deprecated.
275
- Please use `should_not set_session[...]` instead.
276
- EOT
277
-
278
- expect(&expectation).to print_warning_including(expected_warning)
279
- end
9
+ def set_store
10
+ set_session
280
11
  end
281
- end
282
-
283
- def controller_without_session
284
- build_fake_response
285
- end
286
12
 
287
- def controller_with_session(session_hash)
288
- build_fake_response do
289
- session_hash.each do |key, value|
290
- session[key] = value
291
- end
13
+ def store_within(controller)
14
+ controller.session
292
15
  end
293
16
  end
294
17
  end