Permalink
Browse files

route_to matcher captures ActionController::RoutingError as well as

Assertion failures.

- Fixes #530.
  • Loading branch information...
1 parent 10bba44 commit 61e2ac1ca5d0971811c55975eabfd0f90b7c8153 @dchelimsky dchelimsky committed Apr 20, 2012
Showing with 29 additions and 6 deletions.
  1. +3 −1 lib/rspec/rails/matchers/routing_matchers.rb
  2. +26 −5 spec/rspec/rails/matchers/route_to_spec.rb
@@ -23,7 +23,9 @@ def description
# @api private
def matches?(verb_to_path_map)
@verb_to_path_map = verb_to_path_map
- match_unless_raises ActiveSupport::TestCase::Assertion do
+ # assert_recognizes does not consider ActionController::RoutingError an
+ # assertion failure, so we have to capture that and Assertion here.
+ match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
path, query = *verb_to_path_map.values.first.split('?')
@scope.assert_recognizes(
@expected_options,
@@ -20,7 +20,6 @@ def assert_recognizes(*)
end
context "with shortcut syntax" do
-
it "routes with extra options" do
self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" }, {})
get("path").should route_to("controller#action", :extra => "options")
@@ -65,14 +64,25 @@ def assert_recognizes(*)
end
end
- context "when assert_recognizes fails" do
+ context "when assert_recognizes fails with an assertion failure" do
it "fails with message from assert_recognizes" do
self.stub!(:assert_recognizes) do
raise ActiveSupport::TestCase::Assertion.new("this message")
end
expect do
{:get => "path"}.should route_to("these" => "options")
- end.to raise_error("this message")
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
+ end
+ end
+
+ context "when assert_recognizes fails with a routing error" do
+ it "fails with message from assert_recognizes" do
+ self.stub!(:assert_recognizes) do
+ raise ActionController::RoutingError.new("this message")
+ end
+ expect do
+ {:get => "path"}.should route_to("these" => "options")
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
end
end
@@ -98,7 +108,7 @@ def assert_recognizes(*)
end
end
- context "when assert_recognizes fails" do
+ context "when assert_recognizes fails with an assertion failure" do
it "passes" do
self.stub!(:assert_recognizes) do
raise ActiveSupport::TestCase::Assertion.new("this message")
@@ -109,6 +119,17 @@ def assert_recognizes(*)
end
end
+ context "when assert_recognizes fails with a routing error" do
+ it "passes" do
+ self.stub!(:assert_recognizes) do
+ raise ActionController::RoutingError.new("this message")
+ end
+ expect do
+ {:get => "path"}.should_not route_to("these" => "options")
+ end.to_not raise_error
+ end
+ end
+
context "when an exception is raised" do
it "raises that exception" do
self.stub!(:assert_recognizes) do
@@ -120,6 +141,7 @@ def assert_recognizes(*)
end
end
end
+
it "uses failure message from assert_recognizes" do
self.stub!(:assert_recognizes).and_raise(
ActiveSupport::TestCase::Assertion.new("this message"))
@@ -128,4 +150,3 @@ def assert_recognizes(*)
end.to raise_error("this message")
end
end
-

0 comments on commit 61e2ac1

Please sign in to comment.