Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add description method to route_to matcher #473

Merged
merged 2 commits into from

2 participants

@jwulff

Adds a description to the Rails routes route_to matcher. Before, the default description for this spec
it { { :get => '/register' }.should route_to(:controller => 'registration', :action => 'new') }
was:
should route {:controller=>"registration", :action=>"new"}
With this description method it is:
should route {:get=>"/register"} to {:controller=>"registration", :action=>"new"}

@dchelimsky
Owner

Specs, please.

@jwulff

Spec added

@dchelimsky dchelimsky merged commit d5d3dfb into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Changelog for #473.
Also aligned the example with others in the spec.
ea2be20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2011
  1. @jwulff
Commits on Dec 22, 2011
  1. @jwulff
This page is out of date. Refresh to see the latest.
View
5 lib/rspec/rails/matchers/routing_matchers.rb
@@ -15,9 +15,14 @@ def initialize(scope, *expected)
@expected_options.merge!(:controller => controller, :action => action)
end
end
+
+ def description
+ "route #{@verb_to_path_map} to #{@expected_options}"
+ end
# @api private
def matches?(verb_to_path_map)
+ @verb_to_path_map = verb_to_path_map
match_unless_raises ActiveSupport::TestCase::Assertion do
path, query = *verb_to_path_map.values.first.split('?')
@scope.assert_recognizes(
View
6 spec/rspec/rails/matchers/route_to_spec.rb
@@ -4,6 +4,12 @@
include RSpec::Rails::Matchers::RoutingMatchers
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
+ it "provides a description" do
+ matcher = route_to 'these' => 'options'
+ matcher.instance_variable_set(:@verb_to_path_map, { :get => 'path' })
+ matcher.description.should == "route {:get=>\"path\"} to {\"these\"=>\"options\"}"
+ end
+
it "delegates to assert_recognizes" do
self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" }, {})
{:get => "path"}.should route_to("these" => "options")
Something went wrong with that request. Please try again.