Permalink
Browse files

Client should propagate NoMethodErrors from tested application

  • Loading branch information...
1 parent e0bd222 commit 1ca3922babca06a31ee237fd60d3eba284288565 @mlen mlen committed Aug 21, 2013
View
@@ -15,18 +15,19 @@ def initialize(options = {})
HTTP_METHODS.each do |method|
class_eval <<-RUBY
def #{method}(path, params = {}, headers = {})
- response = driver.send(:#{method}, path, params, default_headers.merge(headers))
+ unless driver.respond_to? :#{method}
+ raise UnsupportedMethodError, "Your driver does not support #{method.upcase} method"
+ end
+
+ response = driver.#{method}(path, params, default_headers.merge(headers))
parsed_response = parse_response(response)
yield parsed_response if block_given?
parsed_response
- rescue NoMethodError
- raise UnsupportedMethodError, "Your driver does not support #{method.upcase} method"
end
RUBY
end
protected
-
def app
@options[:app] || Bbq.app
end
@@ -22,4 +22,8 @@ def rainbow
format.yaml { render :text => @rainbow.to_yaml }
end
end
+
+ def uh_oh
+ raise NoMethodError
+ end
end
@@ -5,4 +5,5 @@
match "/miracle" => "home#miracle"
match "/ponycorns" => "home#ponycorns"
match "/rainbow" => "home#rainbow"
+ match "/uh_oh" => "home#uh_oh"
end
@@ -136,6 +136,13 @@ def get_rainbow(*args)
assert_equal 7, response.body["colors"]
end
+ scenario 'client should propagate errors from the app' do
+ assert_raise NoMethodError do
+ client = Bbq::TestClient.new
+ client.get "/uh_oh"
+ end
+ end
+
scenario 'client using driver with unsupported method' do
class CustomDriverClient < Bbq::TestClient
def driver
@@ -152,7 +159,7 @@ def driver
TESTUNIT
run_cmd 'ruby -Ilib -Itest/dummy/test test/dummy/test/acceptance/api_test.rb'
- assert_match /5 tests, \d+ assertions, 0 failures, 0 errors/, output
+ assert_match /\d+ tests, \d+ assertions, 0 failures, 0 errors/, output
end
def test_session_pool

0 comments on commit 1ca3922

Please sign in to comment.