Ensure NoMethodError propogates correctly.

When a delegated method calls a non-existant method the correct
NoMethodError should be called. If the NoMethodError is swallowed by
the decorator it can cause problems with BDD workflow.
This commit is contained in:
Steve Tooke 2012-01-31 11:03:14 +00:00
parent 51b03097f2
commit 7168e2ca74
3 changed files with 19 additions and 2 deletions

View File

@ -197,8 +197,9 @@ module Draper
model.send(method, *args, &block)
end
self.send(method, *args, &block)
rescue NoMethodError
super
rescue NoMethodError => no_method_error
super if no_method_error.name == method
raise no_method_error
end
else
super

View File

@ -551,6 +551,18 @@ describe Draper::Base do
subject.hello_world
end
end
context "when the delegated method calls a non-existant method" do
it "raises the correct NoMethodError" do
begin
subject.some_action
rescue NoMethodError => e
e.name.should_not == :some_action
else
fail("No exception raised")
end
end
end
end
describe "#kind_of?" do

View File

@ -45,6 +45,10 @@ class Product < ActiveRecord::Base
"Sample Title"
end
def some_action
self.nonexistant_method
end
def block
yield
end