require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "clicks_button" do before do @session = Webrat::TestSession.new end it "should fail if no buttons" do @session.response_body = <<-EOS
EOS lambda { @session.clicks_button }.should raise_error end it "should fail if input is not a submit button" do @session.response_body = <<-EOS EOS lambda { @session.clicks_button }.should raise_error end it "should fail if button is disabled" do @session.response_body = <<-EOS EOS lambda { @session.clicks_button }.should raise_error end it "should default to get method" do @session.response_body = <<-EOS EOS @session.should_receive(:get) @session.clicks_button end it "should assert valid response" do @session.response_body = <<-EOS EOS @session.response_code = 404 lambda { @session.clicks_button }.should raise_error end it "should submit the first form by default" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/form1", {}) @session.clicks_button end it "should not explode on file fields" do @session.response_body = <<-EOS EOS @session.clicks_button end it "should submit the form with the specified button" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/form2", {}) @session.clicks_button "Form2" end it "should use action from form" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", {}) @session.clicks_button end it "should use method from form" do @session.response_body = <<-EOS EOS @session.should_receive(:post) @session.clicks_button end it "should send button as param if it has a name" do @session.response_body = <<-EOS EOS @session.should_receive(:post).with("/login", "login" => "Login") @session.clicks_button("Login") end it "should not send button as param if it has no name" do @session.response_body = <<-EOS EOS @session.should_receive(:post).with("/login", {}) @session.clicks_button("Login") end it "should send default password field values" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) @session.clicks_button end it "should send default hidden field values" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end it "should send default text field values" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end it "should send default checked fields" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end it "should send default radio options" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) @session.clicks_button end it "should send correct data for rails style unchecked fields" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) @session.clicks_button end it "should send correct data for rails style checked fields" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end it "should send default collection fields" do @session.response_body = <<-EOS EOS @session.should_receive(:post).with("/login", "options" => ["burger", "fries", "soda", "soda", "dessert"], "response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]}) @session.clicks_button end it "should not send default unchecked fields" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", {}) @session.clicks_button end it "should send default textarea values" do @session.response_body = <<-EOS EOS @session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"}) @session.clicks_button end it "should send default selected option value from select" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "month" => "2") @session.clicks_button end it "should send default selected option inner html from select when no value attribute" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "month" => "February") @session.clicks_button end it "should send first select option value when no option selected" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "month" => "1") @session.clicks_button end it "should handle nested properties" do @session.response_body = <<-EOS EOS @session.should_receive(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) @session.clicks_button end it "should send default empty text field values" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button end it "should recognize button tags" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button end it "should recognize image button tags" do @session.response_body = <<-EOS EOS @session.should_receive(:get) @session.clicks_button end it "should find buttons by their IDs" do @session.response_body = <<-EOS EOS @session.should_receive(:get) @session.clicks_button "my_button" end it "should find image buttons by their alt text" do @session.response_body = <<-EOS EOS @session.should_receive(:get) @session.clicks_button "Go" end it "should recognize button tags by content" do @session.response_body = <<-EOS EOS @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button "Login" end end