Created
August 21, 2009 00:24
-
-
Save cee-dub/171570 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
require 'www/mechanize' | |
# Patches WWW::Mechanize for Cucumber + Webrat | |
module WWW | |
class Mechanize | |
def self.log_disabled | |
@@log ||= Logger.new(STDOUT) | |
end | |
class File | |
attr_accessor :redirects | |
def redirect? | |
redirects > 0 | |
end | |
def response_code | |
code.to_i | |
end | |
def error? | |
(500..599).include?(response_code) | |
end | |
def success? | |
(200..299).include?(response_code) | |
end | |
def unauthorized? | |
response_code == 401 | |
end | |
end | |
# Mechanize throws exceptions for certain HTTP status codes. | |
# We want to catch these and still create a page. | |
def fetch_page_with_secret_sauce(params) | |
begin | |
page = fetch_page_without_secret_sauce(params) | |
rescue ResponseCodeError => e | |
page = e.page | |
end | |
page.redirects ||= params[:redirects].to_i | |
page | |
end | |
alias_method :fetch_page_without_secret_sauce, :fetch_page | |
alias_method :fetch_page, :fetch_page_with_secret_sauce | |
end | |
end |
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
require 'webrat' | |
require 'action_controller' | |
require 'test/unit' | |
Webrat.configure do |config| | |
config.mode = :mechanize | |
end | |
World do | |
Webrat::Session.new(Webrat::MechanizeAdapter.new) | |
end | |
World(Webrat::Matchers) | |
World(Test::Unit::Assertions) | |
World(ActionController::TestCase::Assertions) | |
World(ActionController::Assertions::ResponseAssertions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment