Class: Spec::Rails::Matchers::BeRoutable

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ BeRoutable

Returns a new instance of BeRoutable.



90
91
92
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 90

def initialize(example)
  @example = example
end

Instance Method Details

#failure_message_for_shouldObject



108
109
110
111
112
113
114
115
116
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 108

def failure_message_for_should
  "Expected '#{@actual.keys.first.to_s.upcase} #{@actual.values.first}' to be routable, but it wasn't.\n"+
  "To really test routability, we recommend #{@actual.inspect}.\n"+
  "  should route_to( :action => 'action', :controller => 'controller' )\n\n"+

  "That way, you'll verify where your route goes to.  Plus, we'll verify\n"+
  "the generation of the expected path from the action/controller, as in\n"+
  "the url_for() helper."
end

#failure_message_for_should_notObject



118
119
120
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 118

def failure_message_for_should_not
  "Expected '#{@actual.keys.first.to_s.upcase} #{@actual.values.first}' to fail, but it routed to #{@actual_place} instead"
end

#matches?(path) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 94

def matches?(path)
  begin
    @actual = path
    method, path = PathDecomposer.decompose_path(path)
    @example.assert_recognizes({}, { :method => method, :path => path }, {} )
    true
  rescue ActionController::RoutingError, ActionController::MethodNotAllowed
    false
  rescue ::Test::Unit::AssertionFailedError => e
    # the second thingy will always be "<{}>" becaues of the way we called assert_recognizes({}...) above.
    e.to_s =~ /<(.*)> did not match <\{\}>/ and @actual_place = $1 or raise
    true
  end
end