require File.dirname(__FILE__) + "/helper" class FillsInTest < Test::Unit::TestCase def setup @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end def test_should_work_with_textareas @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"text" => "filling text area"}) @session.fills_in "User Text", :with => "filling text area" @session.clicks_button end def test_should_work_with_password_fields @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"text" => "pass"}) @session.fills_in "user_text", :with => "pass" @session.clicks_button end def test_should_fail_if_input_not_found @response.stubs(:body).returns(<<-EOS)
EOS assert_raises RuntimeError do @session.fills_in "Email", :with => "foo@example.com" end end def test_should_allow_overriding_default_form_values @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "user[email]", :with => "foo@example.com" @session.clicks_button end def test_should_choose_the_shortest_label_match @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) @session.fills_in "Some", :with => "value" @session.clicks_button end def test_should_choose_the_first_label_match_if_closest_is_a_tie @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) @session.fills_in "Some mail", :with => "value" @session.clicks_button end def test_should_anchor_label_matches_to_start_of_label @response.stubs(:body).returns(<<-EOS)
EOS assert_raises(RuntimeError) { @session.fills_in "mail", :with => "value" } end def test_should_anchor_label_matches_to_word_boundaries @response.stubs(:body).returns(<<-EOS)
EOS assert_raises(RuntimeError) { @session.fills_in "Email", :with => "value" } end def test_should_work_with_inputs_nested_in_labels @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "Email", :with => "foo@example.com" @session.clicks_button end def test_should_work_with_full_input_names @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "user[email]", :with => "foo@example.com" @session.clicks_button end def test_should_work_with_symbols @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in :email, :with => "foo@example.com" @session.clicks_button end end