Created
November 12, 2008 22:09
-
-
Save jackdempsey/24284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ~/git/merb/merb-core (master)$ gd lib/merb-core/test/helpers/request_helper.rb spec/public/test/request_helper_spec.rb | |
| diff --git a/merb-core/lib/merb-core/test/helpers/request_helper.rb b/merb-core/lib/merb-core/test/helpers/request_helper.rb | |
| index 7ab15f5..4cc2c31 100644 | |
| --- a/merb-core/lib/merb-core/test/helpers/request_helper.rb | |
| +++ b/merb-core/lib/merb-core/test/helpers/request_helper.rb | |
| @@ -49,6 +49,25 @@ module Merb | |
| Merb::Dispatcher.work_queue.pop.call | |
| end | |
| + def rack.method_missing(method,*args) | |
| + # method comes in like :created? or :not_found? | |
| + # slice off ? | |
| + method_string = method.to_s | |
| + if method_string[-1,1] == '?' | |
| + method_name = method_string.camel_case | |
| + method_name = method_name[0,method_name.size-1] | |
| + begin | |
| + if exception = Object.full_const_get("Merb::ControllerExceptions::#{method_name}") | |
| + exception.status == self.status | |
| + end | |
| + rescue NameError | |
| + super | |
| + end | |
| + else | |
| + super | |
| + end | |
| + end | |
| + | |
| rack | |
| end | |
| end | |
| diff --git a/merb-core/spec/public/test/request_helper_spec.rb b/merb-core/spec/public/test/request_helper_spec.rb | |
| index d61dd50..18c7bcd 100644 | |
| --- a/merb-core/spec/public/test/request_helper_spec.rb | |
| +++ b/merb-core/spec/public/test/request_helper_spec.rb | |
| @@ -121,4 +121,12 @@ describe Merb::Test::RequestHelper do | |
| request("/expires").should have_body("1") | |
| end | |
| + it "should intercept methods ending in ? and try to match to controller exceptions" do | |
| + # for more targeted exception checking like request(...).should be_not_found etc | |
| + request("/nonexistant_method").should be_not_found | |
| + end | |
| + | |
| + it "should reraise methods ending in ? that don't match an exception" do | |
| + lambda { request("/error_should_raise_up").should be_something_wrong_here }.should raise_error(NoMethodError ) | |
| + end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment