Permalink
Browse files

dev: refactor a spec

  • Loading branch information...
1 parent 63a9efd commit 0677052ae4f37b50411b862111cc716fd0c3d347 @dchelimsky dchelimsky committed May 9, 2012
Showing with 22 additions and 21 deletions.
  1. +22 −21 spec/rspec/rails/matchers/redirect_to_spec.rb
@@ -6,37 +6,35 @@
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
-
context "with should" do
context "when assert_redirected_to passes" do
+ def assert_redirected_to(*); end
+
it "passes" do
- self.stub!(:assert_redirected_to)
expect do
response.should redirect_to("destination")
end.to_not raise_exception
end
end
context "when assert_redirected_to fails" do
+ def assert_redirected_to(*)
+ raise ActiveSupport::TestCase::Assertion.new("this message")
+ end
+
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.to raise_exception("this message")
end
end
context "when fails due to some other exception" do
+ def assert_redirected_to(*)
+ raise "oops"
+ end
+
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")
@@ -46,30 +44,33 @@
context "with should_not" do
context "when assert_redirected_to fails" do
+ def assert_redirected_to(*)
+ raise ActiveSupport::TestCase::Assertion.new("this message")
+ end
+
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 "when assert_redirected_to passes" do
+ def assert_redirected_to(*); end
+
it "fails with custom failure message" 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.to raise_exception(/expected not to redirect to \"destination\", but did/)
end
end
context "when fails due to some other exception" do
+ def assert_redirected_to(*)
+ raise "oops"
+ end
+
it "raises that exception" do
- self.stub!(:assert_redirected_to) do
- raise "oops"
- end
expect do
response.should_not redirect_to("destination")
end.to raise_exception("oops")

0 comments on commit 0677052

Please sign in to comment.