Sha256: b54d76d9834bd50ca156e3334b7d34ca71b893fc4803851c2bdfd710cfacf019

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'test/unit'
require 'rubygems'
require 'mechanize'
require 'test_includes'

class TestSetFields < Test::Unit::TestCase
  include TestMethods

  def setup
    @agent = WWW::Mechanize.new
    @page = @agent.get("http://localhost:#{PORT}/form_set_fields.html")
    @form = @page.forms.first
  end

  def test_set_no_fields
    before = {}
    @form.fields.each { |f| before[f.name] = f.value }
    @form.set_fields
    before.each { |k,v| assert_equal(v, @form.send(k)) }
  end

  def test_set_one_field
    @form.set_fields( :gender => 'male' )
    assert_equal('male', @form.gender)
  end

  def test_set_many_fields
    @form.set_fields( :gender       => 'male',
                      :first_name   => 'Aaron',
                      'green[eggs]' => 'Ham'
                    )
    assert_equal('male', @form.gender)
    assert_equal('Aaron', @form.first_name)
    assert_equal('Ham', @form.fields.name('green[eggs]').first.value)
  end

  def test_set_second_field
    @form.set_fields( :first_name => ['Aaron', 1] )
    assert_equal('Aaron', @form.fields.name('first_name')[1].value)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mechanize-0.6.0 test/tc_set_fields.rb
mechanize-0.5.4 test/tc_set_fields.rb
mechanize-0.5.3 test/tc_set_fields.rb
mechanize-0.6.1 test/tc_set_fields.rb
mechanize-0.5.2 test/tc_set_fields.rb
mechanize-0.6.10 test/tc_set_fields.rb
mechanize-0.6.3 test/tc_set_fields.rb
mechanize-0.6.4 test/tc_set_fields.rb
mechanize-0.6.5 test/tc_set_fields.rb
mechanize-0.6.7 test/tc_set_fields.rb
mechanize-0.6.6 test/tc_set_fields.rb
mechanize-0.6.9 test/tc_set_fields.rb
mechanize-0.6.2 test/tc_set_fields.rb
mechanize-0.6.8 test/tc_set_fields.rb
mechanize-0.6.11 test/tc_set_fields.rb