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 35
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 44
def failure_message
  "Expected #{controller.class} to #{expectation_description}, but it did not"
end
Also aliased as: failure_message_for_should
failure_message_for_should()
Alias for: failure_message
failure_message_for_should_not()
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb, line 49
def failure_message_when_negated
  "Expected #{controller.class} not to #{expectation_description}, but it did"
end
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 39
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 61
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 81
def expectation_description
  string = 'set'

  if key_set?
    string << " #{store.name}[#{key.inspect}]"
  else
    string << " any key in #{store.name}"
  end

  if expected_value_set?
    if expected_value.is_a?(Regexp)
      string << " to a value matching #{expected_value.inspect}"
    else
      string << " 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 77
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 69
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 73
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 65
def key_set?
  defined?(@key)
end