Sha256: e5a9f160fc7946b65a06514901933744c98db3a12e447de7a05783c2c680ebc4

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "helper"))

class TestSetFields < Test::Unit::TestCase
  def setup
    @agent = WWW::Mechanize.new
    @page = @agent.get("http://localhost/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_multiple_duplicate_fields
    page = @agent.get("http://localhost/form_multival.html")
    form = page.form('post_form')
    form.set_fields( :first => { 0 => 'a', 1 => 'b' } )
    assert_equal('a', form.fields.name('first')[0].value)
    assert_equal('b', form.fields.name('first')[1].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

5 entries across 5 versions & 1 rubygems

Version Path
mechanize-0.8.0 test/test_set_fields.rb
mechanize-0.8.1 test/test_set_fields.rb
mechanize-0.8.2 test/test_set_fields.rb
mechanize-0.8.3 test/test_set_fields.rb
mechanize-0.8.4 test/test_set_fields.rb