require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "click_button" do it "should fail if no buttons" do with_html <<-HTML
HTML lambda { click_button }.should raise_error(Webrat::NotFoundError) end it "should fail if input is not a submit button" do with_html <<-HTML
HTML lambda { click_button }.should raise_error(Webrat::NotFoundError) end it "should fail if button is disabled" do with_html <<-HTML
HTML lambda { click_button }.should raise_error(Webrat::DisabledFieldError) end it "should default to get method" do with_html <<-HTML
HTML webrat_session.should_receive(:get) click_button end it "should assert valid response" do with_html <<-HTML
HTML webrat_session.response_code = 501 lambda { click_button }.should raise_error(Webrat::PageLoadError) end [200, 300, 400, 499].each do |status| it "should consider the #{status} status code as success" do with_html <<-HTML
HTML webrat_session.response_code = status lambda { click_button }.should_not raise_error end end it "should submit the first form by default" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/form1", {}) click_button end it "should not explode on file fields" do with_html <<-HTML
HTML click_button end it "should submit the form with the specified button" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/form2", {}) click_button "Form2" end it "should use action from form" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", {}) click_button end it "should use method from form" do with_html <<-HTML
HTML webrat_session.should_receive(:post) click_button end it "should send button as param if it has a name" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/login", "login" => "Login") click_button("Login") end it "should not send button as param if it has no name" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/login", {}) click_button("Login") end it "should send default password field values" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) click_button end it "should send default hidden field values" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) click_button end it "should send default text field values" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) click_button end it "should not send disabled field values" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", {}) click_button end it "should send default checked fields" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) click_button end it "should send default radio options" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) click_button end it "should send correct data for rails style unchecked fields" do with_html <<-HTML
TOS
HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) click_button end it "should send correct data for rails style checked fields" do with_html <<-HTML
TOS
HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) click_button end it "should send default collection fields" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/login", "options" => ["burger", "fries", "soda", "soda", "dessert"], "response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]}) click_button end it "should not send default unchecked fields" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", {}) click_button end it "should send default textarea values" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"}) click_button end it "should properly handle HTML entities in textarea default values" do pending "needs bug fix" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"}) click_button end end it "should send default selected option value from select" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "month" => "2") click_button end it "should send default selected option inner html from select when no value attribute" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "month" => "February") click_button end it "should send first select option value when no option selected" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "month" => "1") click_button end it "should handle nested properties" do with_html <<-HTML
HTML webrat_session.should_receive(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) click_button end it "should send default empty text field values" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) click_button end it "should recognize button tags" do with_html <<-HTML
HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) click_button "Login" end end