Ensure all example HTML is wrapped in <html> tags

This commit is contained in:
Bryan Helmkamp 2008-11-28 00:34:35 -05:00
parent 3744009dd2
commit 31aa659a67
16 changed files with 308 additions and 23 deletions

View File

@ -12,9 +12,11 @@ describe "Basic Auth HTTP headers" do
it "should be present in form submits" do
with_html <<-HTML
<html>
<form method="post" action="/form1">
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
click_button

View File

@ -26,12 +26,14 @@ describe "check" do
it "should check rails style checkboxes" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
</form>
</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>
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
</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>
<form method="post" action="/login">
<input type="checkbox" name="remember_me" checked="checked" disabled="disabled" />
<input type="submit" />
</form>
</html>
HTML
lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError)
end
it "should uncheck rails style checkboxes" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", {})
uncheck "remember_me"

View File

@ -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>
<form method="post" action="/login">
</form>
</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>
<form method="post" action="/login">
<input type="text" name="first_option" />
</form>
</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
<html>
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
@ -29,6 +34,7 @@ describe "choose" do
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
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
<html>
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
@ -44,6 +51,7 @@ describe "choose" do
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
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>
<form method="post" action="/login">
<input type="radio" name="first_option" disabled="disabled" />
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="radio" name="first_option" />
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/>
<input type="submit" />
</form>
</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
<html>
<form method="post" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
@ -94,6 +109,7 @@ describe "choose" do
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"})
choose "Male"

View File

@ -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
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
lambda {
@ -47,9 +55,11 @@ describe "click_area" do
it "should not be case sensitive" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="http://www.example.com/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
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
<html>
<map name="map_de" id="map_de">
<area href="/page?foo=bar" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_area "Berlin"

View File

@ -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>
<form method="get" action="/login"></form>
</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>
<form method="get" action="/login">
<input type="reset" />
</form>
</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>
<form method="get" action="/login">
<input type="submit" disabled="disabled" />
</form>
</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>
<form action="/login">
<input type="submit" />
</form>
</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>
<form action="/login">
<input type="submit" />
</form>
</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>
<form action="/login">
<input type="submit" />
</form>
</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>
<form method="get" action="/form1">
<input type="submit" />
</form>
<form method="get" action="/form2">
<input type="submit" />
</form>
</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>
<form method="get" action="/form1">
<input type="file" />
<input type="submit" />
</form>
</html>
HTML
click_button
end
@ -102,9 +118,11 @@ describe "click_button" do
it "should use action from form" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" />
<input type="submit" name="login" value="Login" />
</form>
</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>
<form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" />
<input type="submit" value="Login" />
</form>
</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>
<form method="get" action="/login">
<input id="user_password" name="user[password]" value="mypass" type="password" />
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
<input type="submit" />
</form>
</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
<html>
<form method="get" action="/login">
<input disabled id="user_email" name="user[email]" value="test@example.com" type="text" />
<input disabled id="user_gender_male" name="user[gender]" type="radio" value="M" />
@ -185,6 +216,7 @@ describe "click_button" do
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
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>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" />
<input type="submit" />
</form>
</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
<html>
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
@ -210,6 +245,7 @@ describe "click_button" do
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
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
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" /> TOS
<input type="submit" />
</form>
</html>
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
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" /> TOS
<input type="submit" />
</form>
</html>
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
<html>
<form method="post" action="/login">
<input type="checkbox" name="options[]" value="burger" checked="checked" />
<input type="radio" name="options[]" value="fries" checked="checked" />
@ -254,6 +295,7 @@ describe "click_button" do
<input type="hidden" name="response[choices][][selected]" value="two" />
<input type="submit" />
</form>
</html>
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>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" />
<input type="submit" />
</form>
</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>
<form method="post" action="/posts">
<textarea name="post[body]">Post body here!</textarea>
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<select name="month">
<option value="1">January</option>
@ -292,6 +339,7 @@ describe "click_button" do
</select>
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<select name="month">
<option>January</option>
@ -306,6 +355,7 @@ describe "click_button" do
</select>
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<select name="month">
<option value="1">January</option>
@ -320,6 +371,7 @@ describe "click_button" do
</select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/>
<input type="text" id="contestant_scores_13" name="contestant[scores][3]" value="4"/>
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" />
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" />
<button type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button
@ -361,9 +419,11 @@ describe "click_button" do
it "should recognize image button tags" do
with_html <<-HTML
<html>
<form action="/">
<input type="image" />
</form>
</html>
HTML
webrat_session.should_receive(:get)
click_button
@ -371,9 +431,11 @@ describe "click_button" do
it "should find buttons by their IDs" do
with_html <<-HTML
<html>
<form action="/">
<input type="submit" id="my_button" />
</form>
</html>
HTML
webrat_session.should_receive(:get)
click_button "my_button"
@ -381,9 +443,11 @@ describe "click_button" do
it "should find image buttons by their alt text" do
with_html <<-HTML
<html>
<form action="/">
<input type="image" alt="Go" />
</form>
</html>
HTML
webrat_session.should_receive(:get)
click_button "Go"
@ -391,10 +455,12 @@ describe "click_button" do
it "should recognize button tags by content" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" />
<button type="submit">Login</button>
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button "Login"

View File

@ -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
<html>
<a href="/page">Save &amp; go back</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a id="link_text_link" href="/page">Link text</a>
</html>
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
<html>
<a id="link_text_link" href="/page">Link text</a>
</html>
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
<html>
<a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -96,6 +117,7 @@ describe "click_link" do
f.appendChild(s);
f.submit();
return false;">Posts</a>
</html>
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
<html>
<a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -115,6 +138,7 @@ describe "click_link" do
f.appendChild(m);
f.submit();
return false;">Delete</a>
</html>
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
<html>
<a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -129,6 +154,7 @@ describe "click_link" do
f.action = this.href;
f.submit();
return false;">Posts</a>
</html>
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
<html>
<a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -143,6 +170,7 @@ describe "click_link" do
f.action = this.href;
f.submit();
return false;">Posts</a>
</html>
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
<html>
<a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -162,6 +191,7 @@ describe "click_link" do
f.appendChild(m);
f.submit();
return false;">Put</a></h2>
</html>
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
<html>
<a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
@ -180,6 +211,7 @@ describe "click_link" do
f.appendChild(m);
f.submit();
return false;">Link</a>
</html>
HTML
lambda {
@ -189,7 +221,9 @@ describe "click_link" do
it "should assert valid response" do
with_html <<-HTML
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">Link text</a>
</html>
HTML
lambda {
@ -217,7 +255,9 @@ describe "click_link" do
it "should not be case sensitive" do
with_html <<-HTML
<html>
<a href="/page">Link text</a>
</html>
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
<html>
<a href="/page">This is some cool link text, isn't it?</a>
</html>
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
<html>
<a href="/page"><span>Link text</span></a>
</html>
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
<html>
<a href="/page1">Link text</a>
<a href="/page2">Link text</a>
</html>
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
<html>
<a href="/page1">Linkerama</a>
<a href="/page2">Link</a>
</html>
<html>
<a href="/page1">Linkerama</a>
<a href="/page2">Link</a>
</html>
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
<html>
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
</html>
<html>
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
</html>
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
<a href="/page1"><span class="location">My house</span></a>
<a href="/page2">Location</a>
<html>
<a href="/page1"><span class="location">My house</span></a>
<a href="/page2">Location</a>
</html>
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
<html>
<a href="/page1">Link</a>
<div id="container">
<a href="/page2">Link</a>
</div>
<a href="/page1">Link</a>
<div id="container">
<a href="/page2">Link</a>
</div>
</html>
HTML
@ -299,7 +347,9 @@ describe "click_link" do
it "should not make request when link is local anchor" do
with_html <<-HTML
<a href="#section-1">Jump to Section 1</a>
<html>
<a href="#section-1">Jump to Section 1</a>
</html>
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
<html>
<a href="sub">Jump to sub page</a>
</html>
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
<html>
<a href="http://subdomain.example.com/page/sub">Jump to sub page</a>
</html>
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
<html>
<a href="http://www.example.com/page/sub">Jump to sub page</a>
</html>
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
<html>
<a href="?foo=bar">Jump to foo bar</a>
</html>
HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_link "Jump to foo bar"

View File

@ -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>
<form method="post" action="/login">
<label for="user_text">User Text</label>
<textarea id="user_text" name="user[text]"></textarea>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input id="user_text" name="user[text]" type="password" />
<input type="submit" />
</form>
</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>
<form method="get" action="/login">
</form>
</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>
<form method="get" action="/login">
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="text" disabled="disabled" />
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
<input type="submit" />
</form>
</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
<html>
<form method="post" action="/login">
<label for="user_mail1">Some other mail</label>
<input id="user_mail1" name="user[mail1]" type="text" />
@ -69,6 +80,7 @@ describe "fill_in" do
<input id="user_mail2" name="user[mail2]" type="text" />
<input type="submit" />
</form>
</html>
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
<html>
<form method="post" action="/login">
<label for="user_mail1">Some mail one</label>
<input id="user_mail1" name="user[mail1]" type="text" />
@ -85,6 +98,7 @@ describe "fill_in" do
<input id="user_mail2" name="user[mail2]" type="text" />
<input type="submit" />
</form>
</html>
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>
<form method="post" action="/login">
<label for="user_email">Some mail</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
</form>
</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>
<form method="post" action="/login">
<label for="user_email">Emailtastic</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" />
</form>
</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>
<form method="post" action="/login">
<label>
Email
@ -123,6 +142,7 @@ describe "fill_in" do
</label>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input id="user_email" name="user[email]" type="text" />
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<input id="user_email" name="user[email]" />
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="text" />
<input type="submit" />
</form>
</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>
<form method="post" action="/users">
<label for="user_phone">Phone</label>
<input id="user_phone" name="user[phone]" type="text" />
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"})
fill_in 'Phone', :with => "+1 22 33"

View File

@ -43,10 +43,12 @@ describe "field_labeled" do
describe "finding a text field" do
using_this_html <<-HTML
<html>
<form>
<label for="element_42">The Label</label>
<input type="text" id="element_42">
</form>
</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>
<form>
<label for="element_42">The Label</label>
<input type="hidden" id="element_42">
</form>
</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>
<form>
<label for="element_42">The Label</label>
<input type="checkbox" id="element_42">
</form>
</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>
<form>
<label for="element_42">The Label</label>
<input type="radio" id="element_42">
</form>
</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>
<form>
<label for="element_42">The Label</label>
<textarea id="element_42"></textarea>
</form>
</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>
<form>
<label for="element_42">
A label with
@ -116,6 +127,7 @@ describe "field_labeled" do
</label>
<input type="text" id="element_42">
</form>
</html>
HTML
should_return_a Webrat::TextField, :for => "A label with a link on it's own line"

View File

@ -5,15 +5,17 @@ describe Webrat::Matchers do
include Webrat::HaveTagMatcher
before(:each) do
@body = <<-EOF
<div id='main'>
<div class='inner'>hello, world!</div>
<ul>
<li>First</li>
<li>Second</li>
</ul>
</div>
EOF
@body = <<-HTML
<html>
<div id='main'>
<div class='inner'>hello, world!</div>
<ul>
<li>First</li>
<li>Second</li>
</ul>
</div>
</html>
HTML
end
describe "#have_xpath" do

View File

@ -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>
<form action="/appointments" method="post">
<label for="appointment_date">Date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]">
@ -16,6 +17,7 @@ describe "select_date" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<label for="appointment_date">date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]">
@ -38,6 +41,7 @@ describe "select_date" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<select id="appointment_date_1i" name="appointment[date(1i)]">
<option value="2003">2003</option>
@ -59,6 +64,7 @@ describe "select_date" do
</select>
<input type="submit" />
</form>
</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>
<form method="post" action="/appointments">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</html>
HTML
lambda { select_date "December 25, 2003", :from => "date" }.should raise_error(Webrat::NotFoundError)

View File

@ -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>
<form action="/appointments" method="post">
<label for="appointment_time">Time</label><br />
<select id="appointment_time_1i" name="appointment[time(1i)]">
@ -22,6 +23,7 @@ describe "select_datetime" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<label for="appointment_time">Time</label><br />
<select id="appointment_time_1i" name="appointment[time(1i)]">
@ -50,6 +53,7 @@ describe "select_datetime" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<select id="appointment_time_1i" name="appointment[time(1i)]">
<option value="2003">2003</option>
@ -77,6 +82,7 @@ describe "select_datetime" do
</select>
<input type="submit" />
</form>
</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>
<form method="post" action="/appointments">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</html>
HTML
lambda { select_datetime "December 25, 2003 9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError)

View File

@ -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>
<form method="get" action="/login">
<select name="month"><option value="1">January</option></select>
</form>
</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>
<form method="get" action="/login">
<select name="month"><option value="1">January</option></select>
<select name="year"><option value="2008">2008</option></select>
</form>
</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>
<form method="get" action="/login">
<select name="month"><option value="1">January</option></select>
</form>
</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>
<form method="post" action="/login">
<select name="month" disabled="disabled"><option value="1">January</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="month"><option value="1">January</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="encoded"><option value="A &amp; B">Encoded</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="month"></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="month"><option value="1">January</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="start_month"><option value="s1">January</option></select>
<select name="end_month"><option value="e1">January</option></select>
<input type="submit" />
</form>
</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
<html>
<form method="post" action="/login">
<label for="start_month">Start Month</label>
<select id="start_month" name="start_month"><option value="s1">January</option></select>
@ -114,6 +133,7 @@ describe "select" do
<select id="end_month" name="end_month"><option value="e1">January</option></select>
<input type="submit" />
</form>
</html>
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>
<form method="post" action="/login">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</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>
<form method="post" action="/login">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</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
<html>
<form method="post" action="/login">
<label for="start_month">Start Month</label>
<select id="start_month" name="start_month"><option value="s1">January</option></select>
@ -166,6 +193,7 @@ describe "select" do
<select id="end_month" name="end_month"><option value="e1">January</option></select>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
select /jan/i, :from => "End Month"

View File

@ -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>
<form action="/appointments" method="post">
<label for="appointment_time">Time</label><br />
<select id="appointment_time_4i" name="appointment[time(4i)]">
@ -13,6 +14,7 @@ describe "select_time" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<label for="appointment_time">Time</label><br />
<select id="appointment_time_4i" name="appointment[time(4i)]">
@ -32,6 +35,7 @@ describe "select_time" do
</select>
<input type="submit" />
</form>
</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>
<form action="/appointments" method="post">
<select id="appointment_time_4i" name="appointment[time(4i)]">
<option value="09">09</option>
@ -50,6 +55,7 @@ describe "select_time" do
</select>
<input type="submit" />
</form>
</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>
<form method="post" action="/appointments">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</html>
HTML
lambda { select_time "9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError)

View File

@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "visit" do
before do
with_html <<-HTML
<html>
Hello world
</html>
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
<html>
Hello world
</html>
HTML
end

View File

@ -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 <html> 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

View File

@ -9,18 +9,22 @@ describe "attach_file" do
it "should fail if no file field found" do
with_html <<-HTML
<html>
<form method="post" action="/widgets">
</form>
</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>
<form method="post" action="/widgets">
<input type="file" id="widget_file" name="widget[file]" />
<input type="submit" />
</form>
</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>
<form method="post" action="/widgets">
<label for="widget_file">Document</label>
<input type="file" id="widget_file" name="widget[file]" />
<input type="submit" />
</form>
</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
<html>
<form method="post" action="/widgets">
<label for="widget_file1">Document</label>
<input type="file" id="widget_file1" name="widget[files][]" />
@ -48,6 +55,7 @@ describe "attach_file" do
<input type="file" id="widget_file2" name="widget[files][]" />
<input type="submit" />
</form>
</html>
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>
<form method="post" action="/widgets">
<label for="person_picture">Picture</label>
<input type="file" id="person_picture" name="person[picture]" />
<input type="submit" />
</form>
</html>
HTML
ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times
attach_file "Picture", @filename, "image/png"