From 31aa659a6732ca0f9637695db960a72fa45ddcdf Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Fri, 28 Nov 2008 00:34:35 -0500 Subject: [PATCH] Ensure all example HTML is wrapped in tags --- spec/api/basic_auth_spec.rb | 2 + spec/api/check_spec.rb | 12 ++++ spec/api/choose_spec.rb | 16 +++++ spec/api/click_area_spec.rb | 16 +++++ spec/api/click_button_spec.rb | 66 +++++++++++++++++++ spec/api/click_link_spec.rb | 86 +++++++++++++++++++++---- spec/api/fill_in_spec.rb | 28 ++++++++ spec/api/locators/field_labeled_spec.rb | 12 ++++ spec/api/matchers_spec.rb | 20 +++--- spec/api/select_date_spec.rb | 8 +++ spec/api/select_datetime_spec.rb | 8 +++ spec/api/select_spec.rb | 28 ++++++++ spec/api/select_time_spec.rb | 8 +++ spec/api/visit_spec.rb | 4 ++ spec/spec_helper.rb | 7 ++ spec/webrat/rails/attaches_file_spec.rb | 10 +++ 16 files changed, 308 insertions(+), 23 deletions(-) diff --git a/spec/api/basic_auth_spec.rb b/spec/api/basic_auth_spec.rb index 16f908d..02156cf 100644 --- a/spec/api/basic_auth_spec.rb +++ b/spec/api/basic_auth_spec.rb @@ -12,9 +12,11 @@ describe "Basic Auth HTTP headers" do it "should be present in form submits" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"}) click_button diff --git a/spec/api/check_spec.rb b/spec/api/check_spec.rb index 8e9bcd4..9254960 100644 --- a/spec/api/check_spec.rb +++ b/spec/api/check_spec.rb @@ -26,12 +26,14 @@ describe "check" do it "should check rails style checkboxes" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @@ -86,8 +88,10 @@ end describe "uncheck" do it "should fail if no checkbox found" do with_html <<-HTML +
+ HTML lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError) @@ -95,9 +99,11 @@ describe "uncheck" do it "should fail if input is not a checkbox" do with_html <<-HTML +
+ HTML lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError) @@ -105,22 +111,26 @@ describe "uncheck" do it "should fail if the checkbox is disabled" do with_html <<-HTML +
+ HTML lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError) end it "should uncheck rails style checkboxes" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) check "TOS" @@ -130,10 +140,12 @@ describe "uncheck" do it "should result in value not being posted" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", {}) uncheck "remember_me" diff --git a/spec/api/choose_spec.rb b/spec/api/choose_spec.rb index 9137388..31df4ae 100644 --- a/spec/api/choose_spec.rb +++ b/spec/api/choose_spec.rb @@ -3,8 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "choose" do it "should fail if no radio buttons found" do with_html <<-HTML +
+ HTML lambda { choose "first option" }.should raise_error(Webrat::NotFoundError) @@ -12,9 +14,11 @@ describe "choose" do it "should fail if input is not a radio button" do with_html <<-HTML +
+ HTML lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError) @@ -22,6 +26,7 @@ describe "choose" do it "should check rails style radio buttons" do with_html <<-HTML +
@@ -29,6 +34,7 @@ describe "choose" do
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) choose "Male" @@ -37,6 +43,7 @@ describe "choose" do it "should only submit last chosen value" do with_html <<-HTML +
@@ -44,6 +51,7 @@ describe "choose" do
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) choose "Female" @@ -53,10 +61,12 @@ describe "choose" do it "should fail if the radio button is disabled" do with_html <<-HTML +
+ HTML lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError) @@ -64,10 +74,12 @@ describe "choose" do it "should result in the value on being posted if not specified" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "first_option" => "on") choose "first_option" @@ -76,10 +88,12 @@ describe "choose" do it "should result in the value on being posted if not specified and checked by default" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "first_option" => "on") click_button @@ -87,6 +101,7 @@ describe "choose" do it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do with_html <<-HTML +
@@ -94,6 +109,7 @@ describe "choose" do
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"}) choose "Male" diff --git a/spec/api/click_area_spec.rb b/spec/api/click_area_spec.rb index 791817f..65bfbbe 100644 --- a/spec/api/click_area_spec.rb +++ b/spec/api/click_area_spec.rb @@ -3,9 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "click_area" do it "should use get by default" do with_html <<-HTML + Berlin + HTML webrat_session.should_receive(:get).with("/page", {}) click_area "Berlin" @@ -13,9 +15,11 @@ describe "click_area" do it "should assert valid response" do with_html <<-HTML + Berlin + HTML webrat_session.response_code = 501 lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError) @@ -24,9 +28,11 @@ describe "click_area" do [200, 300, 400, 499].each do |status| it "should consider the #{status} status code as success" do with_html <<-HTML + Berlin + HTML webrat_session.response_code = status lambda { click_area "Berlin" }.should_not raise_error @@ -35,9 +41,11 @@ describe "click_area" do it "should fail if the area doesn't exist" do with_html <<-HTML + Berlin + HTML lambda { @@ -47,9 +55,11 @@ describe "click_area" do it "should not be case sensitive" do with_html <<-HTML + Berlin + HTML webrat_session.should_receive(:get).with("/page", {}) click_area "berlin" @@ -59,9 +69,11 @@ describe "click_area" do it "should follow relative links" do webrat_session.stub!(:current_url => "/page") with_html <<-HTML + Berlin + HTML webrat_session.should_receive(:get).with("/page/sub", {}) click_area "Berlin" @@ -69,9 +81,11 @@ describe "click_area" do it "should follow fully qualified local links" do with_html <<-HTML + Berlin + HTML webrat_session.should_receive(:get).with("http://www.example.com/page", {}) click_area "Berlin" @@ -79,9 +93,11 @@ describe "click_area" do it "should follow query parameters" do with_html <<-HTML + Berlin + HTML webrat_session.should_receive(:get).with("/page?foo=bar", {}) click_area "Berlin" diff --git a/spec/api/click_button_spec.rb b/spec/api/click_button_spec.rb index 5e55ad1..ab6913d 100644 --- a/spec/api/click_button_spec.rb +++ b/spec/api/click_button_spec.rb @@ -3,7 +3,9 @@ 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) @@ -11,9 +13,11 @@ describe "click_button" do it "should fail if input is not a submit button" do with_html <<-HTML +
+ HTML lambda { click_button }.should raise_error(Webrat::NotFoundError) @@ -22,9 +26,11 @@ describe "click_button" do it "should fail if button is disabled" do with_html <<-HTML +
+ HTML lambda { click_button }.should raise_error(Webrat::DisabledFieldError) @@ -32,9 +38,11 @@ describe "click_button" do it "should default to get method" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get) click_button @@ -42,9 +50,11 @@ describe "click_button" do it "should assert valid response" do with_html <<-HTML +
+ HTML webrat_session.response_code = 501 lambda { click_button }.should raise_error(Webrat::PageLoadError) @@ -53,9 +63,11 @@ describe "click_button" do [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 @@ -64,12 +76,14 @@ describe "click_button" do it "should submit the first form by default" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/form1", {}) click_button @@ -77,10 +91,12 @@ describe "click_button" do it "should not explode on file fields" do with_html <<-HTML +
+ HTML click_button end @@ -102,9 +118,11 @@ describe "click_button" do it "should use action from form" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", {}) click_button @@ -112,9 +130,11 @@ describe "click_button" do it "should use method from form" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post) click_button @@ -122,10 +142,12 @@ describe "click_button" do 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") @@ -133,10 +155,12 @@ describe "click_button" do 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") @@ -144,10 +168,12 @@ describe "click_button" do it "should send default password field values" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) click_button @@ -155,10 +181,12 @@ describe "click_button" do 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 @@ -166,10 +194,12 @@ describe "click_button" do 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 @@ -177,6 +207,7 @@ describe "click_button" do it "should not send disabled field values" do with_html <<-HTML +
@@ -185,6 +216,7 @@ describe "click_button" do
+ HTML webrat_session.should_receive(:get).with("/login", {}) click_button @@ -192,10 +224,12 @@ describe "click_button" do it "should send default checked fields" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) click_button @@ -203,6 +237,7 @@ describe "click_button" do it "should send default radio options" do with_html <<-HTML +
@@ -210,6 +245,7 @@ describe "click_button" do
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) click_button @@ -217,11 +253,13 @@ describe "click_button" do 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 @@ -229,11 +267,13 @@ describe "click_button" do 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 @@ -241,6 +281,7 @@ describe "click_button" do it "should send default collection fields" do with_html <<-HTML +
@@ -254,6 +295,7 @@ describe "click_button" do
+ HTML webrat_session.should_receive(:post).with("/login", "options" => ["burger", "fries", "soda", "soda", "dessert"], @@ -263,10 +305,12 @@ describe "click_button" do it "should not send default unchecked fields" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", {}) click_button @@ -274,10 +318,12 @@ describe "click_button" do 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 @@ -285,6 +331,7 @@ describe "click_button" do 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 @@ -299,6 +347,7 @@ describe "click_button" do 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 @@ -313,6 +363,7 @@ describe "click_button" do 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 @@ -327,11 +379,13 @@ describe "click_button" do 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 @@ -339,10 +393,12 @@ describe "click_button" do it "should send default empty text field values" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) click_button @@ -350,10 +406,12 @@ describe "click_button" do it "should recognize button tags" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) click_button "Login" diff --git a/spec/api/click_link_spec.rb b/spec/api/click_link_spec.rb index a7aace4..f602d94 100644 --- a/spec/api/click_link_spec.rb +++ b/spec/api/click_link_spec.rb @@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "click_link" do it "should click links with ampertands" do with_html <<-HTML + Save & go back + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "Save & go back" @@ -11,7 +13,9 @@ describe "click_link" do it "should use get by default" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "Link text" @@ -19,7 +23,9 @@ describe "click_link" do it "should click get links" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "Link text", :method => :get @@ -27,7 +33,9 @@ describe "click_link" do it "should click link on substring" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "ink tex", :method => :get @@ -35,7 +43,9 @@ describe "click_link" do it "should click delete links" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:delete).with("/page", {}) click_link "Link text", :method => :delete @@ -44,7 +54,9 @@ describe "click_link" do it "should click post links" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:post).with("/page", {}) click_link "Link text", :method => :post @@ -52,7 +64,9 @@ describe "click_link" do it "should click put links" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:put).with("/page", {}) click_link "Link text", :method => :put @@ -60,7 +74,9 @@ describe "click_link" do it "should click links by regexp" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link /link [a-z]/i @@ -68,7 +84,9 @@ describe "click_link" do it "should click links by id" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "link_text_link" @@ -76,7 +94,9 @@ describe "click_link" do it "should click links by id regexp" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link /_text_/ @@ -84,6 +104,7 @@ describe "click_link" do it "should click rails javascript links with authenticity tokens" do with_html <<-HTML + Posts + HTML webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") click_link "Posts" @@ -103,6 +125,7 @@ describe "click_link" do it "should click rails javascript delete links" do with_html <<-HTML + Delete + HTML webrat_session.should_receive(:delete).with("/posts/1", {}) click_link "Delete" @@ -122,6 +146,7 @@ describe "click_link" do it "should click rails javascript post links" do with_html <<-HTML + Posts + HTML webrat_session.should_receive(:post).with("/posts", {}) click_link "Posts" @@ -136,6 +162,7 @@ describe "click_link" do it "should click rails javascript post links without javascript" do with_html <<-HTML + Posts + HTML webrat_session.should_receive(:get).with("/posts", {}) click_link "Posts", :javascript => false @@ -150,6 +178,7 @@ describe "click_link" do it "should click rails javascript put links" do with_html <<-HTML + Put + HTML webrat_session.should_receive(:put).with("/posts", {}) click_link "Put" @@ -169,6 +199,7 @@ describe "click_link" do it "should fail if the javascript link doesn't have a value for the _method input" do with_html <<-HTML + Link + HTML lambda { @@ -189,7 +221,9 @@ describe "click_link" do it "should assert valid response" do with_html <<-HTML + Link text + HTML webrat_session.response_code = 501 lambda { click_link "Link text" }.should raise_error(Webrat::PageLoadError) @@ -198,7 +232,9 @@ describe "click_link" do [200, 300, 400, 499].each do |status| it "should consider the #{status} status code as success" do with_html <<-HTML + Link text + HTML webrat_session.response_code = status lambda { click_link "Link text" }.should_not raise_error @@ -207,7 +243,9 @@ describe "click_link" do it "should fail is the link doesn't exist" do with_html <<-HTML + Link text + HTML lambda { @@ -217,7 +255,9 @@ describe "click_link" do it "should not be case sensitive" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "LINK TEXT" @@ -225,7 +265,9 @@ describe "click_link" do it "should match link substrings" do with_html <<-HTML + This is some cool link text, isn't it? + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "Link text" @@ -233,7 +275,9 @@ describe "click_link" do it "should work with elements in the link" do with_html <<-HTML + Link text + HTML webrat_session.should_receive(:get).with("/page", {}) click_link "Link text" @@ -241,8 +285,10 @@ describe "click_link" do it "should match the first matching link" do with_html <<-HTML + Link text Link text + HTML webrat_session.should_receive(:get).with("/page1", {}) click_link "Link text" @@ -250,10 +296,10 @@ describe "click_link" do it "should choose the shortest link text match" do with_html <<-HTML - - Linkerama - Link - + + Linkerama + Link + HTML webrat_session.should_receive(:get).with("/page2", {}) @@ -262,9 +308,9 @@ describe "click_link" do it "should treat non-breaking spaces as spaces" do with_html <<-HTML - - This is a link - + + This is a link + HTML webrat_session.should_receive(:get).with("/page1", {}) @@ -274,8 +320,10 @@ describe "click_link" do it "should not match on non-text contents" do pending "needs fix" do with_html <<-HTML - My house - Location + + My house + Location + HTML webrat_session.should_receive(:get).with("/page2", {}) @@ -286,10 +334,10 @@ describe "click_link" do it "should click link within a selector" do with_html <<-HTML - Link -
- Link -
+ Link +
+ Link +
HTML @@ -299,7 +347,9 @@ describe "click_link" do it "should not make request when link is local anchor" do with_html <<-HTML - Jump to Section 1 + + Jump to Section 1 + HTML # Don't know why webrat_session.should_receive(:get).never doesn't work here webrat_session.should_receive(:send).with('get_via_redirect', '#section-1', {}).never @@ -309,7 +359,9 @@ describe "click_link" do it "should follow relative links" do webrat_session.stub!(:current_url => "/page") with_html <<-HTML + Jump to sub page + HTML webrat_session.should_receive(:get).with("/page/sub", {}) click_link "Jump to sub page" @@ -318,7 +370,9 @@ describe "click_link" do it "should follow fully qualified local links" do webrat_session.stub!(:current_url => "/page") with_html <<-HTML + Jump to sub page + HTML webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {}) click_link "Jump to sub page" @@ -326,7 +380,9 @@ describe "click_link" do it "should follow fully qualified local links to example.com" do with_html <<-HTML + Jump to sub page + HTML webrat_session.should_receive(:get).with("http://www.example.com/page/sub", {}) click_link "Jump to sub page" @@ -335,7 +391,9 @@ describe "click_link" do it "should follow query parameters" do webrat_session.stub!(:current_url => "/page") with_html <<-HTML + Jump to foo bar + HTML webrat_session.should_receive(:get).with("/page?foo=bar", {}) click_link "Jump to foo bar" diff --git a/spec/api/fill_in_spec.rb b/spec/api/fill_in_spec.rb index 2d6a1c4..d3bb4a6 100644 --- a/spec/api/fill_in_spec.rb +++ b/spec/api/fill_in_spec.rb @@ -3,11 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "fill_in" do it "should work with textareas" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"}) fill_in "User Text", :with => "filling text area" @@ -16,10 +18,12 @@ describe "fill_in" do it "should work with password fields" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"text" => "pass"}) fill_in "user_text", :with => "pass" @@ -28,8 +32,10 @@ describe "fill_in" do it "should fail if input not found" do with_html <<-HTML +
+ HTML lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::NotFoundError) @@ -37,11 +43,13 @@ describe "fill_in" do it "should fail if input is disabled" do with_html <<-HTML +
+ HTML lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::DisabledFieldError) @@ -49,11 +57,13 @@ describe "fill_in" do it "should allow overriding default form values" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) fill_in "user[email]", :with => "foo@example.com" @@ -62,6 +72,7 @@ describe "fill_in" do it "should choose the shortest label match" do with_html <<-HTML +
@@ -69,6 +80,7 @@ describe "fill_in" do
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) @@ -78,6 +90,7 @@ describe "fill_in" do it "should choose the first label match if closest is a tie" do with_html <<-HTML +
@@ -85,6 +98,7 @@ describe "fill_in" do
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) @@ -94,10 +108,12 @@ describe "fill_in" do it "should anchor label matches to start of label" do with_html <<-HTML +
+ HTML lambda { fill_in "mail", :with => "value" }.should raise_error(Webrat::NotFoundError) @@ -105,10 +121,12 @@ describe "fill_in" do it "should anchor label matches to word boundaries" do with_html <<-HTML +
+ HTML lambda { fill_in "Email", :with => "value" }.should raise_error(Webrat::NotFoundError) @@ -116,6 +134,7 @@ describe "fill_in" do it "should work with inputs nested in labels" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) fill_in "Email", :with => "foo@example.com" @@ -131,10 +151,12 @@ describe "fill_in" do it "should work with full input names" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) fill_in "user[email]", :with => "foo@example.com" @@ -143,10 +165,12 @@ describe "fill_in" do it "should work if the input type is not set" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) fill_in "user[email]", :with => "foo@example.com" @@ -155,11 +179,13 @@ describe "fill_in" do it "should work with symbols" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) fill_in :email, :with => "foo@example.com" @@ -168,11 +194,13 @@ describe "fill_in" do it "should escape field values" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"}) fill_in 'Phone', :with => "+1 22 33" diff --git a/spec/api/locators/field_labeled_spec.rb b/spec/api/locators/field_labeled_spec.rb index 414af51..33066b3 100644 --- a/spec/api/locators/field_labeled_spec.rb +++ b/spec/api/locators/field_labeled_spec.rb @@ -43,10 +43,12 @@ describe "field_labeled" do describe "finding a text field" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::TextField, :for => "The Label" @@ -56,10 +58,12 @@ describe "field_labeled" do describe "finding a hidden field" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::HiddenField, :for => "The Label" @@ -69,10 +73,12 @@ describe "field_labeled" do describe "finding a checkbox" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::CheckboxField, :for => "The Label" @@ -82,10 +88,12 @@ describe "field_labeled" do describe "finding a radio button" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::RadioField, :for => "The Label" @@ -96,10 +104,12 @@ describe "field_labeled" do describe "finding a text area" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::TextareaField, :for => "The Label" @@ -109,6 +119,7 @@ describe "field_labeled" do describe "finding a field with it's label containing newlines" do using_this_html <<-HTML +
+ HTML should_return_a Webrat::TextField, :for => "A label with a link on it's own line" diff --git a/spec/api/matchers_spec.rb b/spec/api/matchers_spec.rb index 1cfbe5c..c879ff6 100644 --- a/spec/api/matchers_spec.rb +++ b/spec/api/matchers_spec.rb @@ -5,15 +5,17 @@ describe Webrat::Matchers do include Webrat::HaveTagMatcher before(:each) do - @body = <<-EOF -
-
hello, world!
- -
- EOF + @body = <<-HTML + +
+
hello, world!
+ +
+ + HTML end describe "#have_xpath" do diff --git a/spec/api/select_date_spec.rb b/spec/api/select_date_spec.rb index 11089cb..3fd14fa 100644 --- a/spec/api/select_date_spec.rb +++ b/spec/api/select_date_spec.rb @@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "select_date" do it "should send the values for each individual date component" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @@ -25,6 +27,7 @@ describe "select_date" do it "should accept a date object" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @@ -47,6 +51,7 @@ describe "select_date" do it "should work when no label is specified" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) @@ -68,10 +74,12 @@ describe "select_date" do it "should fail if the specified label is not found" do with_html <<-HTML +
+ HTML lambda { select_date "December 25, 2003", :from => "date" }.should raise_error(Webrat::NotFoundError) diff --git a/spec/api/select_datetime_spec.rb b/spec/api/select_datetime_spec.rb index ade53f8..1173835 100644 --- a/spec/api/select_datetime_spec.rb +++ b/spec/api/select_datetime_spec.rb @@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "select_datetime" do it "should send the values for each individual date and time components" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) @@ -31,6 +33,7 @@ describe "select_datetime" do it "should accept a time object" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) @@ -59,6 +63,7 @@ describe "select_datetime" do it "should work when no label is specified" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) @@ -86,10 +92,12 @@ describe "select_datetime" do it "should fail if the specified label is not found" do with_html <<-HTML +
+ HTML lambda { select_datetime "December 25, 2003 9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError) diff --git a/spec/api/select_spec.rb b/spec/api/select_spec.rb index 2437128..7af4b3a 100644 --- a/spec/api/select_spec.rb +++ b/spec/api/select_spec.rb @@ -3,9 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "select" do it "should fail with a helpful message when option not found" do with_html <<-HTML +
+ HTML lambda { select "February", :from => "month" }.should raise_error(Webrat::NotFoundError, @@ -14,10 +16,12 @@ describe "select" do it "should fail if option not found in list specified by element name" do with_html <<-HTML +
+ HTML lambda { select "February", :from => "year" }.should raise_error(Webrat::NotFoundError) @@ -25,9 +29,11 @@ describe "select" do it "should fail if specified list not found" do with_html <<-HTML +
+ HTML lambda { select "February", :from => "year" }.should raise_error(Webrat::NotFoundError) @@ -36,10 +42,12 @@ describe "select" do it "should fail if the select is disabled" do with_html <<-HTML +
+ HTML lambda { select "January", :from => "month" }.should raise_error(Webrat::DisabledFieldError) @@ -47,10 +55,12 @@ describe "select" do it "should send value from option" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "month" => "1") select "January", :from => "month" @@ -59,10 +69,12 @@ describe "select" do it "should send values with HTML encoded ampersands" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "encoded" => "A & B") select "Encoded", :from => "encoded" @@ -71,10 +83,12 @@ describe "select" do it "should work with empty select lists" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", 'month' => '') click_button @@ -82,10 +96,12 @@ describe "select" do it "should work without specifying the field name or label" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "month" => "1") select "January" @@ -94,11 +110,13 @@ describe "select" do it "should send value from option in list specified by name" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") select "January", :from => "end_month" @@ -107,6 +125,7 @@ describe "select" do it "should send value from option in list specified by label" do with_html <<-HTML +
@@ -114,6 +133,7 @@ describe "select" do
+ HTML webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") select "January", :from => "End Month" @@ -122,10 +142,12 @@ describe "select" do it "should use option text if no value" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "month" => "January") select "January", :from => "month" @@ -134,10 +156,12 @@ describe "select" do it "should find option by regexp" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/login", "month" => "January") select /jan/i @@ -146,10 +170,12 @@ describe "select" do it "should fail if no option matching the regexp exists" do with_html <<-HTML +
+ HTML lambda { @@ -159,6 +185,7 @@ describe "select" do it "should find option by regexp in list specified by label" do with_html <<-HTML +
@@ -166,6 +193,7 @@ describe "select" do
+ HTML webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") select /jan/i, :from => "End Month" diff --git a/spec/api/select_time_spec.rb b/spec/api/select_time_spec.rb index 7acea40..d0001ae 100644 --- a/spec/api/select_time_spec.rb +++ b/spec/api/select_time_spec.rb @@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "select_time" do it "should send the values for each individual time component" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) @@ -22,6 +24,7 @@ describe "select_time" do it "should accept a time object" do with_html <<-HTML +

+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) @@ -41,6 +45,7 @@ describe "select_time" do it "should work when no label is specified" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/appointments", "appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) @@ -59,10 +65,12 @@ describe "select_time" do it "should fail if the specified label is not found" do with_html <<-HTML +
+ HTML lambda { select_time "9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError) diff --git a/spec/api/visit_spec.rb b/spec/api/visit_spec.rb index a147756..a0e823d 100644 --- a/spec/api/visit_spec.rb +++ b/spec/api/visit_spec.rb @@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe "visit" do before do with_html <<-HTML + Hello world + HTML end @@ -33,7 +35,9 @@ describe "visit with referer" do before do webrat_session.instance_variable_set(:@current_url, "/old_url") with_html <<-HTML + Hello world + HTML end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23900b3..1ddf33a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,8 +16,15 @@ Spec::Runner.configure do |config| include Webrat::Methods def with_html(html) + raise "This doesn't look like HTML. Wrap it in a tag" unless html =~ /^\s*<[^Hh>]*html/i webrat_session.response_body = html end + + def with_xml(xml) + raise "This looks like HTML" if xml =~ /^\s*<[^Hh>]*html/i + webrat_session.response_body = xml + end + end module Webrat diff --git a/spec/webrat/rails/attaches_file_spec.rb b/spec/webrat/rails/attaches_file_spec.rb index 610f6d4..e4b25bd 100644 --- a/spec/webrat/rails/attaches_file_spec.rb +++ b/spec/webrat/rails/attaches_file_spec.rb @@ -9,18 +9,22 @@ describe "attach_file" do it "should fail if no file field found" do with_html <<-HTML +
+ HTML lambda { attach_file("Doc", "/some/path") }.should raise_error(Webrat::NotFoundError) end it "should submit empty strings for blank file fields" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } }) click_button @@ -28,11 +32,13 @@ describe "attach_file" do it "should submit the attached file" do with_html <<-HTML +
+ HTML webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => @uploaded_file } }) attach_file "Document", @filename @@ -41,6 +47,7 @@ describe "attach_file" do it "should support collections" do with_html <<-HTML +
@@ -48,6 +55,7 @@ describe "attach_file" do
+ HTML webrat_session.should_receive(:post).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } }) attach_file "Document", @filename @@ -57,11 +65,13 @@ describe "attach_file" do it "should allow the content type to be specified" do with_html <<-HTML +
+ HTML ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times attach_file "Picture", @filename, "image/png"