Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: rspec/rspec-rails
...
head fork: rspec/rspec-rails
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
8 lib/rspec/rails/matchers/redirect_to.rb
View
@@ -3,13 +3,17 @@ module RedirectTo
extend RSpec::Matchers::DSL
matcher :redirect_to do |destination|
- match_unless_raises Test::Unit::AssertionFailedError do |_|
+ match_unless_raises ActiveSupport::TestCase::Assertion do |_|
assert_redirected_to destination
end
- failure_message_for_should do
+ failure_message_for_should do |_|
rescued_exception.message
end
+
+ failure_message_for_should_not do |_|
+ "expected not to redirect to #{destination.inspect}, but did"
+ end
end
end
end
64 spec/rspec/rails/matchers/redirect_to_spec.rb
View
@@ -1,20 +1,68 @@
require "spec_helper"
-require "action_controller/test_case"
+require "active_support/test_case"
describe "redirect_to" do
include RSpec::Rails::Matchers::RedirectTo
+ let(:response) { ActionController::TestResponse.new }
+
it "delegates to assert_redirected_to" do
self.should_receive(:assert_redirected_to).with("destination")
"response".should redirect_to("destination")
end
- it "uses failure message from assert_redirected_to" do
- self.stub!(:assert_redirected_to).and_raise(
- Test::Unit::AssertionFailedError.new("this message"))
- response = ActionController::TestResponse.new
- expect do
- response.should redirect_to("destination")
- end.to raise_error("this message")
+ context "with should" do
+ context "passing" do
+ it "passes" do
+ self.stub!(:assert_redirected_to)
+ expect do
+ response.should redirect_to("destination")
+ end.to_not raise_exception
+ end
+ end
+
+ context "failing due to assert_redirected_to failing" do
+ it "uses failure message from assert_redirected_to" do
+ self.stub!(:assert_redirected_to) do
+ raise ActiveSupport::TestCase::Assertion.new("this message")
+ end
+ expect do
+ response.should redirect_to("destination")
+ end.to raise_error("this message")
+ end
+ end
+
+ context "failing due to some other exception" do
+ it "raises that exception" do
+ self.stub!(:assert_redirected_to) do
+ raise "oops"
+ end
+ expect do
+ response.should redirect_to("destination")
+ end.to raise_exception("oops")
+ end
+ end
+ end
+
+ context "with should_not" do
+ context "passing (i.e. assert_redirected_to fails)" do
+ it "passes" do
+ self.stub!(:assert_redirected_to) do
+ raise ActiveSupport::TestCase::Assertion.new("this message")
+ end
+ expect do
+ response.should_not redirect_to("destination")
+ end.to_not raise_exception
+ end
+ end
+
+ context "failing due to assert_redirected_to passing" do
+ it "uses failure message from assert_redirected_to" do
+ self.stub!(:assert_redirected_to)
+ expect do
+ response.should_not redirect_to("destination")
+ end.to raise_error(/expected not to redirect to \"destination\", but did/)
+ end
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.