lib/capybara/httpclient_json/driver.rb in capybara-json-0.1.0 vs lib/capybara/httpclient_json/driver.rb in capybara-json-0.1.1

- old
+ new

@@ -52,10 +52,26 @@ end def delete(url, params = {}, headers = {}) process :delete, url, params, headers end + + %w[ get delete ].each do |method| + class_eval %{ + def #{method}!(url, params = {}, env = {}) + handle_error { #{method}(url, params, env) } + end + } + end + + %w[ post put ].each do |method| + class_eval %{ + def #{method}!(url, json, headers = {}) + handle_error { #{method}(url, json, headers) } + end + } + end def reset! @client = nil end @@ -70,7 +86,12 @@ raise Capybara::InfiniteRedirectError else @response = e.res end end + end + + def handle_error(&block) + yield + raise(Capybara::Json::Error, response) if status_code >= 400 end end