Created
December 30, 2010 04:13
-
-
Save directionless/759441 to your computer and use it in GitHub Desktop.
Testing webrat and = in form values
This file contains 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
# for | |
# https://webrat.lighthouseapp.com/projects/10503/tickets/401-webrat-doesnt-handle-form-fields-with-an-equals-sign#ticket-401-1 | |
require 'webrat' | |
require 'webrat/adapters/mechanize' | |
include Webrat::Methods | |
TESTURL = "http://www.directionless.org/webrat-test.pl" | |
Webrat.configure do |config| | |
config.mode = :mechanize | |
end | |
class Webrat::Form | |
def self.query_string_to_params(query_string) | |
# Bug is here. This splits to an array and only takes the first | |
# and last. While we need everything in between. | |
case Webrat.configuration.mode | |
when :rails | |
parse_rails_request_params(query_string) | |
when :merb | |
::Merb::Parse.query(query_string) | |
when :rack, :sinatra | |
Rack::Utils.parse_nested_query(query_string) | |
else | |
query_string.split('&').map {|query| { query.split('=',2).first => query.split('=',2).last }} | |
end | |
end | |
end | |
puts "First, webrat:\n\n" | |
visit TESTURL | |
response = click_button | |
puts response.body | |
puts "\nAnd now mechanize:\n\n" | |
mresponse = Mechanize.new.get(TESTURL).forms.first.submit | |
puts mresponse.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That TESTURL is a simple form that checks if the default values were actually submitted, and outputs. Running this script, with webrat 0.7.2 and mechanize 1.0.0 results in: