Class: Shoulda::Matchers::ActionController::SetSessionOrFlashMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ SetSessionOrFlashMatcher

Returns a new instance of SetSessionOrFlashMatcher.



6
7
8
# File 'lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb', line 6

def initialize(store)
  @store = store
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
18
# File 'lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb', line 15

def [](key)
  @key = key
  self
end

#descriptionObject



37
38
39
# File 'lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb', line 37

def description
  "should #{expectation_description}"
end

#failure_messageObject Also known as: failure_message_for_should



46
47
48
49
# 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

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



52
53
54
55
# 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

#in_context(context) ⇒ Object



10
11
12
13
# File 'lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb', line 10

def in_context(context)
  @context = context
  self
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# 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) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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