Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@directionless
Created December 30, 2010 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save directionless/759441 to your computer and use it in GitHub Desktop.
Save directionless/759441 to your computer and use it in GitHub Desktop.
Testing webrat and = in form values
# 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
@directionless
Copy link
Author

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:

First, webrat:

fourth:  correct
   expected: email@example.com
   got: email@example.com
third:  WRONG
   expected: qwerty=
   got: qwerty
first:  correct
   expected: qwerty123
   got: qwerty123
second:  WRONG
   expected: 123=345
   got: 345

And now mechanize:

first:  correct
   expected: qwerty123
   got: qwerty123
second:  correct
   expected: 123=345
   got: 123=345
third:  correct
   expected: qwerty=
   got: qwerty=
fourth:  correct
   expected: email@example.com
   got: email@example.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment