Navigation Menu

Skip to content

Commit

Permalink
use failure messages from rails assertions when delegating to them
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jun 8, 2010
1 parent a491d18 commit d29bbf5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rspec/rails/matchers.rb
Expand Up @@ -23,13 +23,21 @@ class AssertionFailedError < StandardError
match_unless_raises Test::Unit::AssertionFailedError do |_|
assert_redirected_to destination
end

failure_message_for_should do
rescued_exception.message
end
end

RSpec::Matchers.define :render_template do |options, message|
match_unless_raises Test::Unit::AssertionFailedError do |_|
options = options.to_s if Symbol === options
assert_template options, message
end

failure_message_for_should do
rescued_exception.message
end
end

RSpec::Matchers.define :be_a_new do |model_klass|
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/rails/matchers/redirect_to_spec.rb
@@ -1,8 +1,18 @@
require "spec_helper"
require "action_controller/test_case"

describe "redirect_to" do
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")
end
end
9 changes: 9 additions & 0 deletions spec/rspec/rails/matchers/render_template_spec.rb
@@ -1,6 +1,15 @@
require "spec_helper"

describe "render_template" do
it "uses failure message from render_template" do
self.stub!(:assert_template).and_raise(
Test::Unit::AssertionFailedError.new("this message"))
response = ActionController::TestResponse.new
expect do
response.should render_template("destination")
end.to raise_error("this message")
end

context "given a hash" do
it "delegates to assert_template" do
self.should_receive(:assert_template).with({:this => "hash"}, "this message")
Expand Down

0 comments on commit d29bbf5

Please sign in to comment.