Skip to content

Commit

Permalink
dev: refactor a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 9, 2012
1 parent 63a9efd commit 0677052
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions spec/rspec/rails/matchers/redirect_to_spec.rb
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 0677052

Please sign in to comment.