Class: Spec::Rails::Matchers::RouteTo

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(expected, example) ⇒ RouteTo

Returns a new instance of RouteTo.



22
23
24
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 22

def initialize(expected, example)
  @route, @example = expected,example
end

Instance Method Details

#descriptionObject



53
54
55
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 53

def description
  "route to #{@expected.inspect}"
end

#does_not_match(path) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 40

def does_not_match(path)
  raise ArgumentError, "Don't test a negative route like this."
end

#failure_message_for_shouldObject



44
45
46
47
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 44

def failure_message_for_should
  "Expected #{@expected.inspect} to route to #{@actual.inspect}, but it didn't.\n"+
  "In this case, we expected you to get an exception.  So this message probably means something weird happened."
end

#failure_message_for_should_notObject



49
50
51
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 49

def failure_message_for_should_not
  "Expected a routing error, but the route passed instead.  \nNote, when expecting routes to fail, you should use 'should_not be_routable' instead."
end

#matches?(path) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/route_to.rb', line 26

def matches?(path)
  begin
    @actual = path
    method, path, querystring = PathDecomposer.decompose_path(path)
    params = querystring.blank? ? {} : Rack::Utils.parse_query(querystring).symbolize_keys!
    @example.assert_routing({ :method => method, :path => path }, @route, {}, params)
    true
  rescue ActionController::RoutingError, ::Test::Unit::AssertionFailedError, ActionController::MethodNotAllowed => e
    raise e.class, "#{e}\nIf you're expecting this failure, we suggest { :#{method} => \"#{path}\" }.should_not be_routable"
  rescue Exception => e
    raise e.class, "#{e}\n#{e.backtrace.join( "\n" )}"
  end
end