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.
- checksums.yaml +4 -4
- data/.hound_config/ruby.yml +7 -0
- data/.travis.yml +11 -54
- data/Appraisals +45 -100
- data/CONTRIBUTING.md +51 -7
- data/Gemfile +7 -19
- data/Gemfile.lock +60 -134
- data/Guardfile +5 -0
- data/NEWS.md +203 -0
- data/README.md +95 -50
- data/Rakefile +1 -0
- data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
- data/gemfiles/4.0.0.gemfile +10 -7
- data/gemfiles/4.0.0.gemfile.lock +103 -79
- data/gemfiles/4.0.1.gemfile +10 -7
- data/gemfiles/4.0.1.gemfile.lock +109 -83
- data/gemfiles/4.1.gemfile +10 -7
- data/gemfiles/4.1.gemfile.lock +109 -85
- data/gemfiles/4.2.gemfile +10 -9
- data/gemfiles/4.2.gemfile.lock +86 -78
- data/lib/shoulda/matchers.rb +13 -18
- data/lib/shoulda/matchers/action_controller.rb +4 -1
- data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
- data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
- data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
- data/lib/shoulda/matchers/configuration.rb +20 -0
- data/lib/shoulda/matchers/doublespeak.rb +11 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
- data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
- data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
- data/lib/shoulda/matchers/integrations.rb +43 -0
- data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
- data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
- data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
- data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
- data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
- data/lib/shoulda/matchers/integrations/rails.rb +12 -0
- data/lib/shoulda/matchers/integrations/registry.rb +28 -0
- data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
- data/lib/shoulda/matchers/rails_shim.rb +0 -40
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/script/update_gems_in_all_appraisals +14 -0
- data/shoulda-matchers.gemspec +2 -2
- data/spec/acceptance/active_model_integration_spec.rb +4 -1
- data/spec/acceptance/independent_matchers_spec.rb +6 -6
- data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
- data/spec/acceptance/rails_integration_spec.rb +15 -5
- data/spec/acceptance_spec_helper.rb +8 -0
- data/spec/doublespeak_spec_helper.rb +14 -0
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
- data/spec/support/acceptance/helpers.rb +2 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
- data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
- data/spec/support/acceptance/matchers/have_output.rb +1 -1
- data/spec/support/tests/bundle.rb +1 -1
- data/spec/support/tests/command_runner.rb +25 -13
- data/spec/support/tests/current_bundle.rb +47 -0
- data/spec/support/tests/database.rb +28 -0
- data/spec/support/tests/database_adapters/postgresql.rb +25 -0
- data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
- data/spec/support/tests/database_configuration.rb +33 -0
- data/spec/support/tests/database_configuration_registry.rb +28 -0
- data/spec/support/tests/filesystem.rb +25 -2
- data/spec/support/unit/helpers/active_record_versions.rb +12 -0
- data/spec/support/unit/helpers/class_builder.rb +6 -2
- data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
- data/spec/support/unit/helpers/controller_builder.rb +0 -28
- data/spec/support/unit/helpers/database_helpers.rb +18 -0
- data/spec/support/unit/helpers/model_builder.rb +38 -6
- data/spec/support/unit/helpers/rails_versions.rb +2 -2
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
- data/spec/support/unit/rails_application.rb +29 -13
- data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
- data/spec/unit_spec_helper.rb +15 -14
- data/spec/warnings_spy.rb +1 -1
- metadata +68 -29
- data/docs.watchr +0 -5
- data/gemfiles/3.0.gemfile +0 -26
- data/gemfiles/3.0.gemfile.lock +0 -173
- data/gemfiles/3.1.gemfile +0 -32
- data/gemfiles/3.1.gemfile.lock +0 -212
- data/gemfiles/3.1_1.9.2.gemfile +0 -32
- data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
- data/gemfiles/3.2.gemfile +0 -33
- data/gemfiles/3.2.gemfile.lock +0 -212
- data/gemfiles/3.2_1.9.2.gemfile +0 -31
- data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
- data/lib/shoulda/matchers/assertion_error.rb +0 -27
- data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
- data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
- data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
- data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
- data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
- data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -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
|
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
|
-
|
31
|
+
normalize_values(params)
|
30
32
|
end
|
31
33
|
|
32
34
|
def stringify_params
|
33
|
-
|
35
|
+
normalize_values(args[0])
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
hash.
|
38
|
-
hash_copy[key] =
|
39
|
-
|
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
|
-
|
166
|
-
@
|
171
|
+
store = FlashStore.future
|
172
|
+
@underlying_matcher = SetSessionOrFlashMatcher.new(store)
|
167
173
|
end
|
168
174
|
|
169
|
-
def
|
170
|
-
|
171
|
-
|
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
|
178
|
-
|
181
|
+
def in_context(context)
|
182
|
+
underlying_matcher.in_context(context)
|
179
183
|
self
|
180
184
|
end
|
181
185
|
|
182
186
|
def [](key)
|
183
|
-
|
187
|
+
underlying_matcher[key]
|
184
188
|
self
|
185
189
|
end
|
186
190
|
|
187
|
-
def
|
188
|
-
|
189
|
-
|
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
|
-
|
287
|
-
"flash#{pretty_now}#{pretty_key}"
|
288
|
-
end
|
196
|
+
protected
|
289
197
|
|
290
|
-
|
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
|
116
|
-
SetSessionMatcher.new(
|
117
|
+
def set_session
|
118
|
+
SetSessionMatcher.new.in_context(self)
|
117
119
|
end
|
118
120
|
|
119
121
|
# @private
|
120
122
|
class SetSessionMatcher
|
121
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
180
|
-
|
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
|
-
|
143
|
+
underlying_matcher.in_context(context)
|
185
144
|
self
|
186
145
|
end
|
187
146
|
|
188
|
-
|
189
|
-
|
190
|
-
|
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
|
211
|
-
|
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
|
-
|
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
|
-
|
239
|
-
@controller.session
|
240
|
-
end
|
159
|
+
attr_reader :underlying_matcher
|
241
160
|
end
|
242
161
|
end
|
243
162
|
end
|