class Shoulda::Matchers::ActionController::SetSessionOrFlashMatcher
@private
Attributes
context[R]
controller[R]
expected_value[R]
key[R]
store[R]
Public Class Methods
new(store)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 6 def initialize(store) @store = store end
Public Instance Methods
[](key)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 15 def [](key) @key = key self end
description()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 37 def description "should #{expectation_description}" end
failure_message()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 46 def failure_message "Expected #{controller.class} to #{expectation_description},"\ ' but it did not' end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 52 def failure_message_when_negated "Expected #{controller.class} not to #{expectation_description},"\ ' but it did' end
Also aliased as: failure_message_for_should_not
in_context(context)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 10 def in_context(context) @context = context self end
matches?(controller)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 41 def matches?(controller) @controller = store.controller = controller !store.empty? && key_matches? && expected_value_matches? end
to(expected_value = nil, &block)
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 20 def to(expected_value = nil, &block) if block unless context_set? message = 'When specifying a value as a block, a context must be'\ ' specified beforehand,'\ " e.g., #{store.name}.in_context(context).to { ... }" raise ArgumentError, message end @expected_value = context.instance_eval(&block) else @expected_value = expected_value end self end
Private Instance Methods
context_set?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 65 def context_set? defined?(@context) end
expectation_description()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 85 def expectation_description string = 'set' string << if key_set? " #{store.name}[#{key.inspect}]" else " any key in #{store.name}" end if expected_value_set? string << if expected_value.is_a?(Regexp) " to a value matching #{expected_value.inspect}" else " to #{expected_value.inspect}" end end string end
expected_value_matches?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 81 def expected_value_matches? !expected_value_set? || store.has_value?(expected_value) end
expected_value_set?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 73 def expected_value_set? defined?(@expected_value) end
key_matches?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 77 def key_matches? !key_set? || store.has_key?(key) end
key_set?()
click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 69 def key_set? defined?(@key) end