class Shoulda::Matchers::ActionController::SetSessionMatcher
@private
Public Class Methods
new(key)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 121 def initialize(key) if key Shoulda::Matchers.warn <<EOT Passing a key to set_session is deprecated. Please use the hash syntax instead (e.g., `set_session[:foo]`, not `set_session(:foo)`). EOT self[key] end @value_block = nil end
Public Instance Methods
[](key)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 133 def [](key) @key = key.to_s self end
description()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 179 def description "should #{expectation}" end
failure_message()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 169 def failure_message "Expected #{expectation}, but #{result}" end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 174 def failure_message_when_negated "Didn't expect #{expectation}, but it was" end
Also aliased as: failure_message_for_should_not
in_context(context)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 183 def in_context(context) @context = context self end
matches?(controller)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 144 def matches?(controller) @controller = controller if @value_block @value = @context.instance_eval(&@value_block) end if nil_value_expected_but_actual_value_unset? Shoulda::Matchers.warn <<EOT Using `should set_session[...].to(nil)` to assert that a variable is unset is deprecated. Please use `should_not set_session[...]` instead. EOT end if key_specified? && value_specified? @value === session[@key] elsif key_specified? session.key?(@key) elsif value_specified? session.values.any? { |value| @value === value } else session_present? end end
to(value = nil, &block)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 138 def to(value = nil, &block) @value = value @value_block = block self end
Private Instance Methods
expectation()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 210 def expectation expectation = "" if key_specified? expectation << "session variable #{@key.inspect}" else expectation << "any session variable" end expectation << " to be" if value_specified? && !@value.nil? expectation << " #{@value.inspect}" else expectation << " set" end expectation end
key_specified?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 190 def key_specified? defined?(@key) end
nil_value_expected_but_actual_value_unset?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 202 def nil_value_expected_but_actual_value_unset? value_specified? && @value.nil? && !session.key?(@key) end
result()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 230 def result if session_present? "the session was #{session.inspect}" else 'no session variables were set' end end
session()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 238 def session @controller.session end
session_present?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 206 def session_present? !session.empty? end
value_or_default_value()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 198 def value_or_default_value defined?(@value) && @value end
value_specified?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_matcher.rb, line 194 def value_specified? defined?(@value) end