Skip to content

Instantly share code, notes, and snippets.

@jrichardlai
Created May 13, 2012 20:19
Show Gist options
  • Save jrichardlai/2690018 to your computer and use it in GitHub Desktop.
Save jrichardlai/2690018 to your computer and use it in GitHub Desktop.
Spec Matcher for Rails and Rspec1 to ensure that a route does not route to a specific path
# Sometimes in your app you may have a global route that will catch everything
# So it's not possible to use should_not be_routable or should_not route_to
# In this case you can use should not_route_to.
# Example:
# {:get => '/users/123/upgrade'}.should not_route_to(:controller => "users", :action => "upgrade", :user_id => "123")
Spec::Matchers.define :not_route_to do |destination|
extend Spec::Rails::Example::RoutingHelpers
match_unless_raises do |path|
method, path, querystring = Spec::Rails::Matchers::PathDecomposer.decompose_path(path)
params = querystring.blank? ? {} : Rack::Utils.parse_query(querystring).symbolize_keys!
params_from(method, path).merge(params).should_not == destination
end
failure_message_for_should do |path|
"expected that #{path.inspect} would not route to #{destination.inspect} but was"
end
failure_message_for_should_not do |path|
"expected that #{path.inspect} would route to #{destination.inspect} but was not"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment