shoulda-matchers 2.8.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -54,7 +54,7 @@ module Shoulda
54
54
  end
55
55
 
56
56
  def description
57
- description = "rescues from #{exception}"
57
+ description = "rescue from #{exception}"
58
58
  description << " with ##{expected_method}" if expected_method
59
59
  description
60
60
  end
@@ -79,6 +79,10 @@ module Shoulda
79
79
  #
80
80
  # route(:get, '/posts/1').to('posts#show', id: 1)
81
81
  #
82
+ # You may also specify special parameters such as `:format`:
83
+ #
84
+ # route(:get, '/posts').to('posts#index', format: :json)
85
+ #
82
86
  # @return [RouteMatcher]
83
87
  #
84
88
  def route(method, path)
@@ -135,7 +139,7 @@ module Shoulda
135
139
  rescue ::ActionController::RoutingError => error
136
140
  @failure_message = error.message
137
141
  false
138
- rescue Shoulda::Matchers::AssertionError => error
142
+ rescue Shoulda::Matchers.assertion_exception_class => error
139
143
  @failure_message = error.message
140
144
  false
141
145
  end
@@ -3,6 +3,8 @@ module Shoulda
3
3
  module ActionController
4
4
  # @private
5
5
  class RouteParams
6
+ PARAMS_TO_SYMBOLIZE = %i{ format }
7
+
6
8
  def initialize(args)
7
9
  @args = args
8
10
  end
@@ -26,17 +28,24 @@ module Shoulda
26
28
  def extract_params_from_string
27
29
  controller, action = args[0].split('#')
28
30
  params = (args[1] || {}).merge(controller: controller, action: action)
29
- stringify_values(params)
31
+ normalize_values(params)
30
32
  end
31
33
 
32
34
  def stringify_params
33
- stringify_values(args[0])
35
+ normalize_values(args[0])
34
36
  end
35
37
 
36
- def stringify_values(hash)
37
- hash.inject({}) do |hash_copy, (key, value)|
38
- hash_copy[key] = stringify(value)
39
- hash_copy
38
+ def normalize_values(hash)
39
+ hash.each_with_object({}) do |(key, value), hash_copy|
40
+ hash_copy[key] = symbolize_or_stringify(key, value)
41
+ end
42
+ end
43
+
44
+ def symbolize_or_stringify(key, value)
45
+ if key.in?(PARAMS_TO_SYMBOLIZE)
46
+ value.to_sym
47
+ else
48
+ stringify(value)
40
49
  end
41
50
  end
42
51
 
@@ -0,0 +1,34 @@
1
+ module Shoulda
2
+ module Matchers
3
+ module ActionController
4
+ # @private
5
+ class SessionStore
6
+ attr_accessor :controller
7
+
8
+ def name
9
+ 'session'
10
+ end
11
+
12
+ def has_key?(key)
13
+ session.key?(key)
14
+ end
15
+
16
+ def has_value?(expected_value)
17
+ session.values.any? do |actual_value|
18
+ expected_value === actual_value
19
+ end
20
+ end
21
+
22
+ def empty?
23
+ session.empty?
24
+ end
25
+
26
+ private
27
+
28
+ def session
29
+ controller.session
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Shoulda
2
4
  module Matchers
3
5
  module ActionController
@@ -146,162 +148,54 @@ module Shoulda
146
148
  # @return [SetFlashMatcher]
147
149
  #
148
150
  def set_flash
149
- SetFlashMatcher.new
150
- end
151
-
152
- # @deprecated Use {#set_flash} instead.
153
- # @return [SetFlashMatcher]
154
- def set_the_flash
155
- Shoulda::Matchers.warn_about_deprecated_method(
156
- :set_the_flash,
157
- :set_flash
158
- )
159
- set_flash
151
+ SetFlashMatcher.new.in_context(self)
160
152
  end
161
153
 
162
154
  # @private
163
155
  class SetFlashMatcher
156
+ extend Forwardable
157
+
158
+ def_delegators :underlying_matcher,
159
+ :description,
160
+ :matches?,
161
+ :failure_message,
162
+ :failure_message_when_negated
163
+ alias_method \
164
+ :failure_message_for_should,
165
+ :failure_message
166
+ alias_method \
167
+ :failure_message_for_should_not,
168
+ :failure_message_when_negated
169
+
164
170
  def initialize
165
- @options = {}
166
- @value = nil
171
+ store = FlashStore.future
172
+ @underlying_matcher = SetSessionOrFlashMatcher.new(store)
167
173
  end
168
174
 
169
- def to(value)
170
- if !value.is_a?(String) && !value.is_a?(Regexp)
171
- raise "cannot match against #{value.inspect}"
172
- end
173
- @value = value
175
+ def now
176
+ store = FlashStore.now
177
+ @underlying_matcher = SetSessionOrFlashMatcher.new(store)
174
178
  self
175
179
  end
176
180
 
177
- def now
178
- @options[:now] = true
181
+ def in_context(context)
182
+ underlying_matcher.in_context(context)
179
183
  self
180
184
  end
181
185
 
182
186
  def [](key)
183
- @options[:key] = key
187
+ underlying_matcher[key]
184
188
  self
185
189
  end
186
190
 
187
- def matches?(controller)
188
- @controller = controller
189
- sets_the_flash? && string_value_matches? && regexp_value_matches?
190
- end
191
-
192
- def description
193
- description = "set the #{expected_flash_invocation}"
194
- description << " to #{@value.inspect}" unless @value.nil?
195
- description
196
- end
197
-
198
- def failure_message
199
- "Expected #{expectation}"
200
- end
201
- alias failure_message_for_should failure_message
202
-
203
- def failure_message_when_negated
204
- "Did not expect #{expectation}"
205
- end
206
- alias failure_message_for_should_not failure_message_when_negated
207
-
208
- private
209
-
210
- def sets_the_flash?
211
- flash_values.any?
212
- end
213
-
214
- def string_value_matches?
215
- if @value.is_a?(String)
216
- flash_values.any? {|value| value == @value }
217
- else
218
- true
219
- end
220
- end
221
-
222
- def regexp_value_matches?
223
- if @value.is_a?(Regexp)
224
- flash_values.any? {|value| value =~ @value }
225
- else
226
- true
227
- end
228
- end
229
-
230
- def flash_values
231
- if @options.key?(:key)
232
- flash_hash = HashWithIndifferentAccess.new(flash.to_hash)
233
- [flash_hash[@options[:key]]]
234
- else
235
- flash.to_hash.values
236
- end
237
- end
238
-
239
- def flash
240
- @flash ||= copy_of_flash_from_controller
241
- end
242
-
243
- def copy_of_flash_from_controller
244
- @controller.flash.dup.tap do |flash|
245
- copy_flashes(@controller.flash, flash)
246
- copy_discard_if_necessary(@controller.flash, flash)
247
- sweep_flash_if_necessary(flash)
248
- end
249
- end
250
-
251
- def copy_flashes(original_flash, new_flash)
252
- flashes_ivar = Shoulda::Matchers::RailsShim.flashes_ivar
253
- flashes = original_flash.instance_variable_get(flashes_ivar).dup
254
- new_flash.instance_variable_set(flashes_ivar, flashes)
255
- end
256
-
257
- def copy_discard_if_necessary(original_flash, new_flash)
258
- discard_ivar = :@discard
259
- if original_flash.instance_variable_defined?(discard_ivar)
260
- discard = original_flash.instance_variable_get(discard_ivar).dup
261
- new_flash.instance_variable_set(discard_ivar, discard)
262
- end
263
- end
264
-
265
- def sweep_flash_if_necessary(flash)
266
- unless @options[:now]
267
- flash.sweep
268
- end
269
- end
270
-
271
- def expectation
272
- expectation = "the #{expected_flash_invocation} to be set"
273
- expectation << " to #{@value.inspect}" unless @value.nil?
274
- expectation << ", but #{flash_description}"
275
- expectation
276
- end
277
-
278
- def flash_description
279
- if flash.blank?
280
- 'no flash was set'
281
- else
282
- "was #{flash.inspect}"
283
- end
191
+ def to(expected_value = nil, &block)
192
+ underlying_matcher.to(expected_value, &block)
193
+ self
284
194
  end
285
195
 
286
- def expected_flash_invocation
287
- "flash#{pretty_now}#{pretty_key}"
288
- end
196
+ protected
289
197
 
290
- def pretty_now
291
- if @options[:now]
292
- '.now'
293
- else
294
- ''
295
- end
296
- end
297
-
298
- def pretty_key
299
- if @options[:key]
300
- "[:#{@options[:key]}]"
301
- else
302
- ''
303
- end
304
- end
198
+ attr_reader :underlying_matcher
305
199
  end
306
200
  end
307
201
  end
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Shoulda
2
4
  module Matchers
3
5
  module ActionController
@@ -112,132 +114,49 @@ module Shoulda
112
114
  #
113
115
  # @return [SetSessionMatcher]
114
116
  #
115
- def set_session(key = nil)
116
- SetSessionMatcher.new(key)
117
+ def set_session
118
+ SetSessionMatcher.new.in_context(self)
117
119
  end
118
120
 
119
121
  # @private
120
122
  class SetSessionMatcher
121
- def initialize(key)
122
- if key
123
- Shoulda::Matchers.warn <<EOT
124
- Passing a key to set_session is deprecated.
125
- Please use the hash syntax instead (e.g., `set_session[:foo]`, not `set_session(:foo)`).
126
- EOT
127
- self[key]
128
- end
129
-
130
- @value_block = nil
131
- end
132
-
133
- def [](key)
134
- @key = key.to_s
135
- self
136
- end
137
-
138
- def to(value = nil, &block)
139
- @value = value
140
- @value_block = block
141
- self
142
- end
143
-
144
- def matches?(controller)
145
- @controller = controller
146
-
147
- if @value_block
148
- @value = @context.instance_eval(&@value_block)
149
- end
123
+ extend Forwardable
150
124
 
151
- if nil_value_expected_but_actual_value_unset?
152
- Shoulda::Matchers.warn <<EOT
153
- Using `should set_session[...].to(nil)` to assert that a variable is unset is deprecated.
154
- Please use `should_not set_session[...]` instead.
155
- EOT
156
- end
157
-
158
- if key_specified? && value_specified?
159
- @value === session[@key]
160
- elsif key_specified?
161
- session.key?(@key)
162
- elsif value_specified?
163
- session.values.any? { |value| @value === value }
164
- else
165
- session_present?
166
- end
167
- end
168
-
169
- def failure_message
170
- "Expected #{expectation}, but #{result}"
171
- end
172
- alias failure_message_for_should failure_message
173
-
174
- def failure_message_when_negated
175
- "Didn't expect #{expectation}, but it was"
176
- end
177
- alias failure_message_for_should_not failure_message_when_negated
125
+ def_delegators :underlying_matcher,
126
+ :description,
127
+ :matches?,
128
+ :failure_message,
129
+ :failure_message_when_negated
130
+ alias_method \
131
+ :failure_message_for_should,
132
+ :failure_message
133
+ alias_method \
134
+ :failure_message_for_should_not,
135
+ :failure_message_when_negated
178
136
 
179
- def description
180
- "should #{expectation}"
137
+ def initialize
138
+ store = SessionStore.new
139
+ @underlying_matcher = SetSessionOrFlashMatcher.new(store)
181
140
  end
182
141
 
183
142
  def in_context(context)
184
- @context = context
143
+ underlying_matcher.in_context(context)
185
144
  self
186
145
  end
187
146
 
188
- private
189
-
190
- def key_specified?
191
- defined?(@key)
192
- end
193
-
194
- def value_specified?
195
- defined?(@value)
196
- end
197
-
198
- def value_or_default_value
199
- defined?(@value) && @value
200
- end
201
-
202
- def nil_value_expected_but_actual_value_unset?
203
- value_specified? && @value.nil? && !session.key?(@key)
204
- end
205
-
206
- def session_present?
207
- !session.empty?
147
+ def [](key)
148
+ underlying_matcher[key]
149
+ self
208
150
  end
209
151
 
210
- def expectation
211
- expectation = ""
212
-
213
- if key_specified?
214
- expectation << "session variable #{@key.inspect}"
215
- else
216
- expectation << "any session variable"
217
- end
218
-
219
- expectation << " to be"
220
-
221
- if value_specified? && !@value.nil?
222
- expectation << " #{@value.inspect}"
223
- else
224
- expectation << " set"
225
- end
226
-
227
- expectation
152
+ def to(expected_value = nil, &block)
153
+ underlying_matcher.to(expected_value, &block)
154
+ self
228
155
  end
229
156
 
230
- def result
231
- if session_present?
232
- "the session was #{session.inspect}"
233
- else
234
- 'no session variables were set'
235
- end
236
- end
157
+ protected
237
158
 
238
- def session
239
- @controller.session
240
- end
159
+ attr_reader :underlying_matcher
241
160
  end
242
161
  end
243
162
  end