require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "fill_in" do before do @session = Webrat::TestSession.new end it "should work with textareas" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"}) @session.fill_in "User Text", :with => "filling text area" @session.click_button end it "should work with password fields" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"text" => "pass"}) @session.fill_in "user_text", :with => "pass" @session.click_button end it "should fail if input not found" do @session.response_body = <<-EOS
EOS lambda { @session.fill_in "Email", :with => "foo@example.com" }.should raise_error end it "should fail if input is disabled" do @session.response_body = <<-EOS
EOS lambda { @session.fill_in "Email", :with => "foo@example.com" }.should raise_error end it "should allow overriding default form values" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fill_in "user[email]", :with => "foo@example.com" @session.click_button end it "should choose the shortest label match" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) @session.fill_in "Some", :with => "value" @session.click_button end it "should choose the first label match if closest is a tie" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) @session.fill_in "Some mail", :with => "value" @session.click_button end it "should anchor label matches to start of label" do @session.response_body = <<-EOS
EOS lambda { @session.fill_in "mail", :with => "value" }.should raise_error end it "should anchor label matches to word boundaries" do @session.response_body = <<-EOS
EOS lambda { @session.fill_in "Email", :with => "value" }.should raise_error end it "should work with inputs nested in labels" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fill_in "Email", :with => "foo@example.com" @session.click_button end it "should work with full input names" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fill_in "user[email]", :with => "foo@example.com" @session.click_button end it "should work if the input type is not set" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fill_in "user[email]", :with => "foo@example.com" @session.click_button end it "should work with symbols" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fill_in :email, :with => "foo@example.com" @session.click_button end it "should escape field values" do @session.response_body = <<-EOS
EOS @session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"}) @session.fill_in 'Phone', :with => "+1 22 33" @session.click_button end end