Class: Merb::Test::Rspec::ControllerMatchers::RedirectTo

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/test/matchers/controller_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ RedirectTo

Parameters

String

The expected location



39
40
41
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 39

def initialize(expected)
  @expected = expected
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



57
58
59
60
61
62
63
64
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 57

def failure_message
  msg = "expected #{inspect_target} to redirect to <#{@expected}>, but "
  if @redirected
    msg << "was <#{target_location}>"
  else
    msg << "there was no redirection"
  end
end

#inspect_targetObject

Returns

String

The controller and action name.



74
75
76
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 74

def inspect_target
  "#{@target.controller_name}##{@target.action_name}"
end

#matches?(target) ⇒ Boolean

Parameters

target<Merb::Controller>

The controller to match

Returns

Boolean

True if the controller status is redirect and the locations match.

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 49

def matches?(target)
  @target, @location = target, target.headers['Location']
  @redirected = BeRedirect.new.matches?(target.status)
  @location == @expected && @redirected
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



68
69
70
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 68

def negative_failure_message
  "expected #{inspect_target} not to redirect to <#{@expected}>, but did anyway"
end

#target_locationObject

Returns

String

Either the target’s location header or the target itself.



80
81
82
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 80

def target_location
  @target.respond_to?(:headers) ? @target.headers['Location'] : @target
end