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 it "should be present in form submits" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/form1"> <form method="post" action="/form1">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"}) webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
click_button click_button

View File

@ -26,12 +26,14 @@ describe "check" do
it "should check rails style checkboxes" do it "should check rails style checkboxes" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" /> <input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label> <label for="user_tos">TOS</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
@ -86,8 +88,10 @@ end
describe "uncheck" do describe "uncheck" do
it "should fail if no checkbox found" do it "should fail if no checkbox found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
</html>
HTML HTML
lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if input is not a checkbox" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="remember_me" /> <input type="text" name="remember_me" />
</form> </form>
</html>
HTML HTML
lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if the checkbox is disabled" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" checked="checked" disabled="disabled" /> <input type="checkbox" name="remember_me" checked="checked" disabled="disabled" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError) lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError)
end end
it "should uncheck rails style checkboxes" do it "should uncheck rails style checkboxes" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" /> <input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label> <label for="user_tos">TOS</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
check "TOS" check "TOS"
@ -130,10 +140,12 @@ describe "uncheck" do
it "should result in value not being posted" do it "should result in value not being posted" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" /> <input type="checkbox" name="remember_me" value="yes" checked="checked" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", {}) webrat_session.should_receive(:post).with("/login", {})
uncheck "remember_me" uncheck "remember_me"

View File

@ -3,8 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "choose" do describe "choose" do
it "should fail if no radio buttons found" do it "should fail if no radio buttons found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
</form> </form>
</html>
HTML HTML
lambda { choose "first option" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if input is not a radio button" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" name="first_option" /> <input type="text" name="first_option" />
</form> </form>
</html>
HTML HTML
lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError) lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError)
@ -22,6 +26,7 @@ describe "choose" do
it "should check rails style radio buttons" do it "should check rails style radio buttons" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label> <label for="user_gender_male">Male</label>
@ -29,6 +34,7 @@ describe "choose" do
<label for="user_gender_female">Female</label> <label for="user_gender_female">Female</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
choose "Male" choose "Male"
@ -37,6 +43,7 @@ describe "choose" do
it "should only submit last chosen value" do it "should only submit last chosen value" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label> <label for="user_gender_male">Male</label>
@ -44,6 +51,7 @@ describe "choose" do
<label for="user_gender_female">Female</label> <label for="user_gender_female">Female</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
choose "Female" choose "Female"
@ -53,10 +61,12 @@ describe "choose" do
it "should fail if the radio button is disabled" do it "should fail if the radio button is disabled" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" disabled="disabled" /> <input type="radio" name="first_option" disabled="disabled" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError) 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 it "should result in the value on being posted if not specified" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" /> <input type="radio" name="first_option" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "first_option" => "on") webrat_session.should_receive(:post).with("/login", "first_option" => "on")
choose "first_option" 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 it "should result in the value on being posted if not specified and checked by default" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/> <input type="radio" name="first_option" checked="checked"/>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "first_option" => "on") webrat_session.should_receive(:post).with("/login", "first_option" => "on")
click_button 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 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 with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label> <label for="user_gender_male">Male</label>
@ -94,6 +109,7 @@ describe "choose" do
<label for="user_gender_female">Female</label> <label for="user_gender_female">Female</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"}) webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"})
choose "Male" choose "Male"

View File

@ -3,9 +3,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "click_area" do describe "click_area" do
it "should use get by default" do it "should use get by default" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_area "Berlin" click_area "Berlin"
@ -13,9 +15,11 @@ describe "click_area" do
it "should assert valid response" do it "should assert valid response" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError) lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError)
@ -24,9 +28,11 @@ describe "click_area" do
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_area "Berlin" }.should_not raise_error 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 it "should fail if the area doesn't exist" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
lambda { lambda {
@ -47,9 +55,11 @@ describe "click_area" do
it "should not be case sensitive" do it "should not be case sensitive" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_area "berlin" click_area "berlin"
@ -59,9 +69,11 @@ describe "click_area" do
it "should follow relative links" do it "should follow relative links" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page/sub", {}) webrat_session.should_receive(:get).with("/page/sub", {})
click_area "Berlin" click_area "Berlin"
@ -69,9 +81,11 @@ describe "click_area" do
it "should follow fully qualified local links" do it "should follow fully qualified local links" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <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" /> <area href="http://www.example.com/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.should_receive(:get).with("http://www.example.com/page", {}) webrat_session.should_receive(:get).with("http://www.example.com/page", {})
click_area "Berlin" click_area "Berlin"
@ -79,9 +93,11 @@ describe "click_area" do
it "should follow query parameters" do it "should follow query parameters" do
with_html <<-HTML with_html <<-HTML
<html>
<map name="map_de" id="map_de"> <map name="map_de" id="map_de">
<area href="/page?foo=bar" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" /> <area href="/page?foo=bar" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map> </map>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {}) webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_area "Berlin" click_area "Berlin"

View File

@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "click_button" do describe "click_button" do
it "should fail if no buttons" do it "should fail if no buttons" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"></form> <form method="get" action="/login"></form>
</html>
HTML HTML
lambda { click_button }.should raise_error(Webrat::NotFoundError) 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 it "should fail if input is not a submit button" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input type="reset" /> <input type="reset" />
</form> </form>
</html>
HTML HTML
lambda { click_button }.should raise_error(Webrat::NotFoundError) lambda { click_button }.should raise_error(Webrat::NotFoundError)
@ -22,9 +26,11 @@ describe "click_button" do
it "should fail if button is disabled" do it "should fail if button is disabled" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input type="submit" disabled="disabled" /> <input type="submit" disabled="disabled" />
</form> </form>
</html>
HTML HTML
lambda { click_button }.should raise_error(Webrat::DisabledFieldError) lambda { click_button }.should raise_error(Webrat::DisabledFieldError)
@ -32,9 +38,11 @@ describe "click_button" do
it "should default to get method" do it "should default to get method" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button click_button
@ -42,9 +50,11 @@ describe "click_button" do
it "should assert valid response" do it "should assert valid response" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_button }.should raise_error(Webrat::PageLoadError) lambda { click_button }.should raise_error(Webrat::PageLoadError)
@ -53,9 +63,11 @@ describe "click_button" do
[200, 300, 400, 499].each do |status| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/login"> <form action="/login">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_button }.should_not raise_error lambda { click_button }.should_not raise_error
@ -64,12 +76,14 @@ describe "click_button" do
it "should submit the first form by default" do it "should submit the first form by default" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="submit" /> <input type="submit" />
</form> </form>
<form method="get" action="/form2"> <form method="get" action="/form2">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/form1", {}) webrat_session.should_receive(:get).with("/form1", {})
click_button click_button
@ -77,10 +91,12 @@ describe "click_button" do
it "should not explode on file fields" do it "should not explode on file fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/form1"> <form method="get" action="/form1">
<input type="file" /> <input type="file" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
click_button click_button
end end
@ -102,9 +118,11 @@ describe "click_button" do
it "should use action from form" do it "should use action from form" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
@ -112,9 +130,11 @@ describe "click_button" do
it "should use method from form" do it "should use method from form" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post) webrat_session.should_receive(:post)
click_button click_button
@ -122,10 +142,12 @@ describe "click_button" do
it "should send button as param if it has a name" do it "should send button as param if it has a name" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
<input type="submit" name="login" value="Login" /> <input type="submit" name="login" value="Login" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "login" => "Login") webrat_session.should_receive(:post).with("/login", "login" => "Login")
click_button("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 it "should not send button as param if it has no name" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="submit" name="cancel" value="Cancel" /> <input type="submit" name="cancel" value="Cancel" />
<input type="submit" value="Login" /> <input type="submit" value="Login" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", {}) webrat_session.should_receive(:post).with("/login", {})
click_button("Login") click_button("Login")
@ -144,10 +168,12 @@ describe "click_button" do
it "should send default password field values" do it "should send default password field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_password" name="user[password]" value="mypass" type="password" /> <input id="user_password" name="user[password]" value="mypass" type="password" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) webrat_session.should_receive(:get).with("/login", "user" => {"password" => "mypass"})
click_button click_button
@ -155,10 +181,12 @@ describe "click_button" do
it "should send default hidden field values" do it "should send default hidden field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="hidden" /> <input id="user_email" name="user[email]" value="test@example.com" type="hidden" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"})
click_button click_button
@ -166,10 +194,12 @@ describe "click_button" do
it "should send default text field values" do it "should send default text field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"})
click_button click_button
@ -177,6 +207,7 @@ describe "click_button" do
it "should not send disabled field values" do it "should not send disabled field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input disabled id="user_email" name="user[email]" value="test@example.com" type="text" /> <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" /> <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> <label for="user_gender_female">Female</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
@ -192,10 +224,12 @@ describe "click_button" do
it "should send default checked fields" do it "should send default checked fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" checked="checked" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
click_button click_button
@ -203,6 +237,7 @@ describe "click_button" do
it "should send default radio options" do it "should send default radio options" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" /> <input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label> <label for="user_gender_male">Male</label>
@ -210,6 +245,7 @@ describe "click_button" do
<label for="user_gender_female">Female</label> <label for="user_gender_female">Female</label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "F"})
click_button click_button
@ -217,11 +253,13 @@ describe "click_button" do
it "should send correct data for rails style unchecked fields" do it "should send correct data for rails style unchecked fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" /> TOS <input name="user[tos]" type="hidden" value="0" /> TOS
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
click_button click_button
@ -229,11 +267,13 @@ describe "click_button" do
it "should send correct data for rails style checked fields" do it "should send correct data for rails style checked fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" /> <input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" /> TOS <input name="user[tos]" type="hidden" value="0" /> TOS
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
click_button click_button
@ -241,6 +281,7 @@ describe "click_button" do
it "should send default collection fields" do it "should send default collection fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="checkbox" name="options[]" value="burger" checked="checked" /> <input type="checkbox" name="options[]" value="burger" checked="checked" />
<input type="radio" name="options[]" value="fries" 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="hidden" name="response[choices][][selected]" value="two" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", webrat_session.should_receive(:post).with("/login",
"options" => ["burger", "fries", "soda", "soda", "dessert"], "options" => ["burger", "fries", "soda", "soda", "dessert"],
@ -263,10 +305,12 @@ describe "click_button" do
it "should not send default unchecked fields" do it "should not send default unchecked fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_tos" name="user[tos]" value="1" type="checkbox" /> <input id="user_tos" name="user[tos]" value="1" type="checkbox" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", {}) webrat_session.should_receive(:get).with("/login", {})
click_button click_button
@ -274,10 +318,12 @@ describe "click_button" do
it "should send default textarea values" do it "should send default textarea values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/posts"> <form method="post" action="/posts">
<textarea name="post[body]">Post body here!</textarea> <textarea name="post[body]">Post body here!</textarea>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"}) webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"})
click_button click_button
@ -285,6 +331,7 @@ describe "click_button" do
it "should send default selected option value from select" do it "should send default selected option value from select" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
<option value="1">January</option> <option value="1">January</option>
@ -292,6 +339,7 @@ describe "click_button" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "month" => "2") webrat_session.should_receive(:get).with("/login", "month" => "2")
click_button 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 it "should send default selected option inner html from select when no value attribute" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
<option>January</option> <option>January</option>
@ -306,6 +355,7 @@ describe "click_button" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "month" => "February") webrat_session.should_receive(:get).with("/login", "month" => "February")
click_button click_button
@ -313,6 +363,7 @@ describe "click_button" do
it "should send first select option value when no option selected" do it "should send first select option value when no option selected" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"> <select name="month">
<option value="1">January</option> <option value="1">January</option>
@ -320,6 +371,7 @@ describe "click_button" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "month" => "1") webrat_session.should_receive(:get).with("/login", "month" => "1")
click_button click_button
@ -327,11 +379,13 @@ describe "click_button" do
it "should handle nested properties" do it "should handle nested properties" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input type="text" id="contestant_scores_12" name="contestant[scores][1]" value="2"/> <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="text" id="contestant_scores_13" name="contestant[scores][3]" value="4"/>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) webrat_session.should_receive(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}})
click_button click_button
@ -339,10 +393,12 @@ describe "click_button" do
it "should send default empty text field values" do it "should send default empty text field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button click_button
@ -350,10 +406,12 @@ describe "click_button" do
it "should recognize button tags" do it "should recognize button tags" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
<button type="submit" /> <button type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button click_button
@ -361,9 +419,11 @@ describe "click_button" do
it "should recognize image button tags" do it "should recognize image button tags" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/"> <form action="/">
<input type="image" /> <input type="image" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button click_button
@ -371,9 +431,11 @@ describe "click_button" do
it "should find buttons by their IDs" do it "should find buttons by their IDs" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/"> <form action="/">
<input type="submit" id="my_button" /> <input type="submit" id="my_button" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button "my_button" click_button "my_button"
@ -381,9 +443,11 @@ describe "click_button" do
it "should find image buttons by their alt text" do it "should find image buttons by their alt text" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/"> <form action="/">
<input type="image" alt="Go" /> <input type="image" alt="Go" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get) webrat_session.should_receive(:get)
click_button "Go" click_button "Go"
@ -391,10 +455,12 @@ describe "click_button" do
it "should recognize button tags by content" do it "should recognize button tags by content" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<input id="user_email" name="user[email]" value="" type="text" /> <input id="user_email" name="user[email]" value="" type="text" />
<button type="submit">Login</button> <button type="submit">Login</button>
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""}) webrat_session.should_receive(:get).with("/login", "user" => {"email" => ""})
click_button "Login" click_button "Login"

View File

@ -3,7 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "click_link" do describe "click_link" do
it "should click links with ampertands" do it "should click links with ampertands" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Save &amp; go back</a> <a href="/page">Save &amp; go back</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Save & go back" click_link "Save & go back"
@ -11,7 +13,9 @@ describe "click_link" do
it "should use get by default" do it "should use get by default" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text" click_link "Link text"
@ -19,7 +23,9 @@ describe "click_link" do
it "should click get links" do it "should click get links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text", :method => :get click_link "Link text", :method => :get
@ -27,7 +33,9 @@ describe "click_link" do
it "should click link on substring" do it "should click link on substring" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "ink tex", :method => :get click_link "ink tex", :method => :get
@ -35,7 +43,9 @@ describe "click_link" do
it "should click delete links" do it "should click delete links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:delete).with("/page", {}) webrat_session.should_receive(:delete).with("/page", {})
click_link "Link text", :method => :delete click_link "Link text", :method => :delete
@ -44,7 +54,9 @@ describe "click_link" do
it "should click post links" do it "should click post links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/page", {}) webrat_session.should_receive(:post).with("/page", {})
click_link "Link text", :method => :post click_link "Link text", :method => :post
@ -52,7 +64,9 @@ describe "click_link" do
it "should click put links" do it "should click put links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:put).with("/page", {}) webrat_session.should_receive(:put).with("/page", {})
click_link "Link text", :method => :put click_link "Link text", :method => :put
@ -60,7 +74,9 @@ describe "click_link" do
it "should click links by regexp" do it "should click links by regexp" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link /link [a-z]/i click_link /link [a-z]/i
@ -68,7 +84,9 @@ describe "click_link" do
it "should click links by id" do it "should click links by id" do
with_html <<-HTML with_html <<-HTML
<html>
<a id="link_text_link" href="/page">Link text</a> <a id="link_text_link" href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "link_text_link" click_link "link_text_link"
@ -76,7 +94,9 @@ describe "click_link" do
it "should click links by id regexp" do it "should click links by id regexp" do
with_html <<-HTML with_html <<-HTML
<html>
<a id="link_text_link" href="/page">Link text</a> <a id="link_text_link" href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link /_text_/ click_link /_text_/
@ -84,6 +104,7 @@ describe "click_link" do
it "should click rails javascript links with authenticity tokens" do it "should click rails javascript links with authenticity tokens" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -96,6 +117,7 @@ describe "click_link" do
f.appendChild(s); f.appendChild(s);
f.submit(); f.submit();
return false;">Posts</a> return false;">Posts</a>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
click_link "Posts" click_link "Posts"
@ -103,6 +125,7 @@ describe "click_link" do
it "should click rails javascript delete links" do it "should click rails javascript delete links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts/1" onclick="var f = document.createElement('form'); <a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -115,6 +138,7 @@ describe "click_link" do
f.appendChild(m); f.appendChild(m);
f.submit(); f.submit();
return false;">Delete</a> return false;">Delete</a>
</html>
HTML HTML
webrat_session.should_receive(:delete).with("/posts/1", {}) webrat_session.should_receive(:delete).with("/posts/1", {})
click_link "Delete" click_link "Delete"
@ -122,6 +146,7 @@ describe "click_link" do
it "should click rails javascript post links" do it "should click rails javascript post links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -129,6 +154,7 @@ describe "click_link" do
f.action = this.href; f.action = this.href;
f.submit(); f.submit();
return false;">Posts</a> return false;">Posts</a>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/posts", {}) webrat_session.should_receive(:post).with("/posts", {})
click_link "Posts" click_link "Posts"
@ -136,6 +162,7 @@ describe "click_link" do
it "should click rails javascript post links without javascript" do it "should click rails javascript post links without javascript" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -143,6 +170,7 @@ describe "click_link" do
f.action = this.href; f.action = this.href;
f.submit(); f.submit();
return false;">Posts</a> return false;">Posts</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/posts", {}) webrat_session.should_receive(:get).with("/posts", {})
click_link "Posts", :javascript => false click_link "Posts", :javascript => false
@ -150,6 +178,7 @@ describe "click_link" do
it "should click rails javascript put links" do it "should click rails javascript put links" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts" onclick="var f = document.createElement('form'); <a href="/posts" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -162,6 +191,7 @@ describe "click_link" do
f.appendChild(m); f.appendChild(m);
f.submit(); f.submit();
return false;">Put</a></h2> return false;">Put</a></h2>
</html>
HTML HTML
webrat_session.should_receive(:put).with("/posts", {}) webrat_session.should_receive(:put).with("/posts", {})
click_link "Put" 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 it "should fail if the javascript link doesn't have a value for the _method input" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/posts/1" onclick="var f = document.createElement('form'); <a href="/posts/1" onclick="var f = document.createElement('form');
f.style.display = 'none'; f.style.display = 'none';
this.parentNode.appendChild(f); this.parentNode.appendChild(f);
@ -180,6 +211,7 @@ describe "click_link" do
f.appendChild(m); f.appendChild(m);
f.submit(); f.submit();
return false;">Link</a> return false;">Link</a>
</html>
HTML HTML
lambda { lambda {
@ -189,7 +221,9 @@ describe "click_link" do
it "should assert valid response" do it "should assert valid response" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.response_code = 501 webrat_session.response_code = 501
lambda { click_link "Link text" }.should raise_error(Webrat::PageLoadError) 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| [200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do it "should consider the #{status} status code as success" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.response_code = status webrat_session.response_code = status
lambda { click_link "Link text" }.should_not raise_error 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 it "should fail is the link doesn't exist" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
lambda { lambda {
@ -217,7 +255,9 @@ describe "click_link" do
it "should not be case sensitive" do it "should not be case sensitive" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">Link text</a> <a href="/page">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "LINK TEXT" click_link "LINK TEXT"
@ -225,7 +265,9 @@ describe "click_link" do
it "should match link substrings" do it "should match link substrings" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page">This is some cool link text, isn't it?</a> <a href="/page">This is some cool link text, isn't it?</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text" click_link "Link text"
@ -233,7 +275,9 @@ describe "click_link" do
it "should work with elements in the link" do it "should work with elements in the link" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page"><span>Link text</span></a> <a href="/page"><span>Link text</span></a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page", {}) webrat_session.should_receive(:get).with("/page", {})
click_link "Link text" click_link "Link text"
@ -241,8 +285,10 @@ describe "click_link" do
it "should match the first matching link" do it "should match the first matching link" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="/page1">Link text</a> <a href="/page1">Link text</a>
<a href="/page2">Link text</a> <a href="/page2">Link text</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page1", {}) webrat_session.should_receive(:get).with("/page1", {})
click_link "Link text" click_link "Link text"
@ -250,10 +296,10 @@ describe "click_link" do
it "should choose the shortest link text match" do it "should choose the shortest link text match" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a href="/page1">Linkerama</a> <a href="/page1">Linkerama</a>
<a href="/page2">Link</a> <a href="/page2">Link</a>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page2", {}) webrat_session.should_receive(:get).with("/page2", {})
@ -262,9 +308,9 @@ describe "click_link" do
it "should treat non-breaking spaces as spaces" do it "should treat non-breaking spaces as spaces" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a> <a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
</html> </html>
HTML HTML
webrat_session.should_receive(:get).with("/page1", {}) webrat_session.should_receive(:get).with("/page1", {})
@ -274,8 +320,10 @@ describe "click_link" do
it "should not match on non-text contents" do it "should not match on non-text contents" do
pending "needs fix" do pending "needs fix" do
with_html <<-HTML with_html <<-HTML
<a href="/page1"><span class="location">My house</span></a> <html>
<a href="/page2">Location</a> <a href="/page1"><span class="location">My house</span></a>
<a href="/page2">Location</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page2", {}) webrat_session.should_receive(:get).with("/page2", {})
@ -286,10 +334,10 @@ describe "click_link" do
it "should click link within a selector" do it "should click link within a selector" do
with_html <<-HTML with_html <<-HTML
<html> <html>
<a href="/page1">Link</a> <a href="/page1">Link</a>
<div id="container"> <div id="container">
<a href="/page2">Link</a> <a href="/page2">Link</a>
</div> </div>
</html> </html>
HTML HTML
@ -299,7 +347,9 @@ describe "click_link" do
it "should not make request when link is local anchor" do it "should not make request when link is local anchor" do
with_html <<-HTML with_html <<-HTML
<a href="#section-1">Jump to Section 1</a> <html>
<a href="#section-1">Jump to Section 1</a>
</html>
HTML HTML
# Don't know why webrat_session.should_receive(:get).never doesn't work here # 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 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 it "should follow relative links" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
with_html <<-HTML with_html <<-HTML
<html>
<a href="sub">Jump to sub page</a> <a href="sub">Jump to sub page</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page/sub", {}) webrat_session.should_receive(:get).with("/page/sub", {})
click_link "Jump to sub page" click_link "Jump to sub page"
@ -318,7 +370,9 @@ describe "click_link" do
it "should follow fully qualified local links" do it "should follow fully qualified local links" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
with_html <<-HTML with_html <<-HTML
<html>
<a href="http://subdomain.example.com/page/sub">Jump to sub page</a> <a href="http://subdomain.example.com/page/sub">Jump to sub page</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {}) webrat_session.should_receive(:get).with("http://subdomain.example.com/page/sub", {})
click_link "Jump to sub page" 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 it "should follow fully qualified local links to example.com" do
with_html <<-HTML with_html <<-HTML
<html>
<a href="http://www.example.com/page/sub">Jump to sub page</a> <a href="http://www.example.com/page/sub">Jump to sub page</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("http://www.example.com/page/sub", {}) webrat_session.should_receive(:get).with("http://www.example.com/page/sub", {})
click_link "Jump to sub page" click_link "Jump to sub page"
@ -335,7 +391,9 @@ describe "click_link" do
it "should follow query parameters" do it "should follow query parameters" do
webrat_session.stub!(:current_url => "/page") webrat_session.stub!(:current_url => "/page")
with_html <<-HTML with_html <<-HTML
<html>
<a href="?foo=bar">Jump to foo bar</a> <a href="?foo=bar">Jump to foo bar</a>
</html>
HTML HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {}) webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_link "Jump to 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 describe "fill_in" do
it "should work with textareas" do it "should work with textareas" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_text">User Text</label> <label for="user_text">User Text</label>
<textarea id="user_text" name="user[text]"></textarea> <textarea id="user_text" name="user[text]"></textarea>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"}) webrat_session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"})
fill_in "User Text", :with => "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 it "should work with password fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_text" name="user[text]" type="password" /> <input id="user_text" name="user[text]" type="password" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"text" => "pass"}) webrat_session.should_receive(:post).with("/login", "user" => {"text" => "pass"})
fill_in "user_text", :with => "pass" fill_in "user_text", :with => "pass"
@ -28,8 +32,10 @@ describe "fill_in" do
it "should fail if input not found" do it "should fail if input not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
</form> </form>
</html>
HTML HTML
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if input is disabled" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="text" disabled="disabled" /> <input id="user_email" name="user[email]" type="text" disabled="disabled" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { fill_in "Email", :with => "foo@example.com" }.should raise_error(Webrat::DisabledFieldError) 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 it "should allow overriding default form values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
fill_in "user[email]", :with => "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 it "should choose the shortest label match" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some other mail</label> <label for="user_mail1">Some other mail</label>
<input id="user_mail1" name="user[mail1]" type="text" /> <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 id="user_mail2" name="user[mail2]" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) 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 it "should choose the first label match if closest is a tie" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_mail1">Some mail one</label> <label for="user_mail1">Some mail one</label>
<input id="user_mail1" name="user[mail1]" type="text" /> <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 id="user_mail2" name="user[mail2]" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) 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 it "should anchor label matches to start of label" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Some mail</label> <label for="user_email">Some mail</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
</form> </form>
</html>
HTML HTML
lambda { fill_in "mail", :with => "value" }.should raise_error(Webrat::NotFoundError) 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 it "should anchor label matches to word boundaries" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Emailtastic</label> <label for="user_email">Emailtastic</label>
<input id="user_email" name="user[email]" value="test@example.com" type="text" /> <input id="user_email" name="user[email]" value="test@example.com" type="text" />
</form> </form>
</html>
HTML HTML
lambda { fill_in "Email", :with => "value" }.should raise_error(Webrat::NotFoundError) 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 it "should work with inputs nested in labels" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label> <label>
Email Email
@ -123,6 +142,7 @@ describe "fill_in" do
</label> </label>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
fill_in "Email", :with => "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 it "should work with full input names" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_email" name="user[email]" type="text" /> <input id="user_email" name="user[email]" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
fill_in "user[email]", :with => "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 it "should work if the input type is not set" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<input id="user_email" name="user[email]" /> <input id="user_email" name="user[email]" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
fill_in "user[email]", :with => "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 it "should work with symbols" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="user_email">Email</label> <label for="user_email">Email</label>
<input id="user_email" name="user[email]" type="text" /> <input id="user_email" name="user[email]" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) webrat_session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"})
fill_in :email, :with => "foo@example.com" fill_in :email, :with => "foo@example.com"
@ -168,11 +194,13 @@ describe "fill_in" do
it "should escape field values" do it "should escape field values" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/users"> <form method="post" action="/users">
<label for="user_phone">Phone</label> <label for="user_phone">Phone</label>
<input id="user_phone" name="user[phone]" type="text" /> <input id="user_phone" name="user[phone]" type="text" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"}) webrat_session.should_receive(:post).with("/users", "user" => {"phone" => "+1 22 33"})
fill_in 'Phone', :with => "+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 describe "finding a text field" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42">The Label</label> <label for="element_42">The Label</label>
<input type="text" id="element_42"> <input type="text" id="element_42">
</form> </form>
</html>
HTML HTML
should_return_a Webrat::TextField, :for => "The Label" should_return_a Webrat::TextField, :for => "The Label"
@ -56,10 +58,12 @@ describe "field_labeled" do
describe "finding a hidden field" do describe "finding a hidden field" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42">The Label</label> <label for="element_42">The Label</label>
<input type="hidden" id="element_42"> <input type="hidden" id="element_42">
</form> </form>
</html>
HTML HTML
should_return_a Webrat::HiddenField, :for => "The Label" should_return_a Webrat::HiddenField, :for => "The Label"
@ -69,10 +73,12 @@ describe "field_labeled" do
describe "finding a checkbox" do describe "finding a checkbox" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42">The Label</label> <label for="element_42">The Label</label>
<input type="checkbox" id="element_42"> <input type="checkbox" id="element_42">
</form> </form>
</html>
HTML HTML
should_return_a Webrat::CheckboxField, :for => "The Label" should_return_a Webrat::CheckboxField, :for => "The Label"
@ -82,10 +88,12 @@ describe "field_labeled" do
describe "finding a radio button" do describe "finding a radio button" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42">The Label</label> <label for="element_42">The Label</label>
<input type="radio" id="element_42"> <input type="radio" id="element_42">
</form> </form>
</html>
HTML HTML
should_return_a Webrat::RadioField, :for => "The Label" should_return_a Webrat::RadioField, :for => "The Label"
@ -96,10 +104,12 @@ describe "field_labeled" do
describe "finding a text area" do describe "finding a text area" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42">The Label</label> <label for="element_42">The Label</label>
<textarea id="element_42"></textarea> <textarea id="element_42"></textarea>
</form> </form>
</html>
HTML HTML
should_return_a Webrat::TextareaField, :for => "The Label" 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 describe "finding a field with it's label containing newlines" do
using_this_html <<-HTML using_this_html <<-HTML
<html>
<form> <form>
<label for="element_42"> <label for="element_42">
A label with A label with
@ -116,6 +127,7 @@ describe "field_labeled" do
</label> </label>
<input type="text" id="element_42"> <input type="text" id="element_42">
</form> </form>
</html>
HTML HTML
should_return_a Webrat::TextField, :for => "A label with a link on it's own line" 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 include Webrat::HaveTagMatcher
before(:each) do before(:each) do
@body = <<-EOF @body = <<-HTML
<div id='main'> <html>
<div class='inner'>hello, world!</div> <div id='main'>
<ul> <div class='inner'>hello, world!</div>
<li>First</li> <ul>
<li>Second</li> <li>First</li>
</ul> <li>Second</li>
</div> </ul>
EOF </div>
</html>
HTML
end end
describe "#have_xpath" do describe "#have_xpath" do

View File

@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "select_date" do describe "select_date" do
it "should send the values for each individual date component" do it "should send the values for each individual date component" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_date">Date</label><br /> <label for="appointment_date">Date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]"> <select id="appointment_date_1i" name="appointment[date(1i)]">
@ -16,6 +17,7 @@ describe "select_date" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) "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 it "should accept a date object" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_date">date</label><br /> <label for="appointment_date">date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]"> <select id="appointment_date_1i" name="appointment[date(1i)]">
@ -38,6 +41,7 @@ describe "select_date" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) "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 it "should work when no label is specified" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<select id="appointment_date_1i" name="appointment[date(1i)]"> <select id="appointment_date_1i" name="appointment[date(1i)]">
<option value="2003">2003</option> <option value="2003">2003</option>
@ -59,6 +64,7 @@ describe "select_date" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"}) "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 it "should fail if the specified label is not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/appointments"> <form method="post" action="/appointments">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { select_date "December 25, 2003", :from => "date" }.should raise_error(Webrat::NotFoundError) 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 describe "select_datetime" do
it "should send the values for each individual date and time components" do it "should send the values for each individual date and time components" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_time">Time</label><br /> <label for="appointment_time">Time</label><br />
<select id="appointment_time_1i" name="appointment[time(1i)]"> <select id="appointment_time_1i" name="appointment[time(1i)]">
@ -22,6 +23,7 @@ describe "select_datetime" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) "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 it "should accept a time object" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_time">Time</label><br /> <label for="appointment_time">Time</label><br />
<select id="appointment_time_1i" name="appointment[time(1i)]"> <select id="appointment_time_1i" name="appointment[time(1i)]">
@ -50,6 +53,7 @@ describe "select_datetime" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) "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 it "should work when no label is specified" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<select id="appointment_time_1i" name="appointment[time(1i)]"> <select id="appointment_time_1i" name="appointment[time(1i)]">
<option value="2003">2003</option> <option value="2003">2003</option>
@ -77,6 +82,7 @@ describe "select_datetime" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(1i)" => '2003', "time(2i)" => "12", "time(3i)" => "25", "time(4i)" => "09", "time(5i)" => "30"}) "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 it "should fail if the specified label is not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/appointments"> <form method="post" action="/appointments">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { select_datetime "December 25, 2003 9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError) 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 describe "select" do
it "should fail with a helpful message when option not found" do it "should fail with a helpful message when option not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
</html>
HTML HTML
lambda { select "February", :from => "month" }.should raise_error(Webrat::NotFoundError, 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 it "should fail if option not found in list specified by element name" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
<select name="year"><option value="2008">2008</option></select> <select name="year"><option value="2008">2008</option></select>
</form> </form>
</html>
HTML HTML
lambda { select "February", :from => "year" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if specified list not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="get" action="/login"> <form method="get" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
</form> </form>
</html>
HTML HTML
lambda { select "February", :from => "year" }.should raise_error(Webrat::NotFoundError) 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 it "should fail if the select is disabled" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month" disabled="disabled"><option value="1">January</option></select> <select name="month" disabled="disabled"><option value="1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { select "January", :from => "month" }.should raise_error(Webrat::DisabledFieldError) lambda { select "January", :from => "month" }.should raise_error(Webrat::DisabledFieldError)
@ -47,10 +55,12 @@ describe "select" do
it "should send value from option" do it "should send value from option" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "month" => "1") webrat_session.should_receive(:post).with("/login", "month" => "1")
select "January", :from => "month" select "January", :from => "month"
@ -59,10 +69,12 @@ describe "select" do
it "should send values with HTML encoded ampersands" do it "should send values with HTML encoded ampersands" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="encoded"><option value="A &amp; B">Encoded</option></select> <select name="encoded"><option value="A &amp; B">Encoded</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "encoded" => "A & B") webrat_session.should_receive(:post).with("/login", "encoded" => "A & B")
select "Encoded", :from => "encoded" select "Encoded", :from => "encoded"
@ -71,10 +83,12 @@ describe "select" do
it "should work with empty select lists" do it "should work with empty select lists" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"></select> <select name="month"></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", 'month' => '') webrat_session.should_receive(:post).with("/login", 'month' => '')
click_button click_button
@ -82,10 +96,12 @@ describe "select" do
it "should work without specifying the field name or label" do it "should work without specifying the field name or label" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option value="1">January</option></select> <select name="month"><option value="1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "month" => "1") webrat_session.should_receive(:post).with("/login", "month" => "1")
select "January" select "January"
@ -94,11 +110,13 @@ describe "select" do
it "should send value from option in list specified by name" do it "should send value from option in list specified by name" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="start_month"><option value="s1">January</option></select> <select name="start_month"><option value="s1">January</option></select>
<select name="end_month"><option value="e1">January</option></select> <select name="end_month"><option value="e1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
select "January", :from => "end_month" select "January", :from => "end_month"
@ -107,6 +125,7 @@ describe "select" do
it "should send value from option in list specified by label" do it "should send value from option in list specified by label" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>
<select id="start_month" name="start_month"><option value="s1">January</option></select> <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> <select id="end_month" name="end_month"><option value="e1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
select "January", :from => "End Month" select "January", :from => "End Month"
@ -122,10 +142,12 @@ describe "select" do
it "should use option text if no value" do it "should use option text if no value" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "month" => "January") webrat_session.should_receive(:post).with("/login", "month" => "January")
select "January", :from => "month" select "January", :from => "month"
@ -134,10 +156,12 @@ describe "select" do
it "should find option by regexp" do it "should find option by regexp" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "month" => "January") webrat_session.should_receive(:post).with("/login", "month" => "January")
select /jan/i select /jan/i
@ -146,10 +170,12 @@ describe "select" do
it "should fail if no option matching the regexp exists" do it "should fail if no option matching the regexp exists" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { lambda {
@ -159,6 +185,7 @@ describe "select" do
it "should find option by regexp in list specified by label" do it "should find option by regexp in list specified by label" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/login"> <form method="post" action="/login">
<label for="start_month">Start Month</label> <label for="start_month">Start Month</label>
<select id="start_month" name="start_month"><option value="s1">January</option></select> <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> <select id="end_month" name="end_month"><option value="e1">January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1") webrat_session.should_receive(:post).with("/login", "start_month" => "s1", "end_month" => "e1")
select /jan/i, :from => "End Month" 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 describe "select_time" do
it "should send the values for each individual time component" do it "should send the values for each individual time component" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_time">Time</label><br /> <label for="appointment_time">Time</label><br />
<select id="appointment_time_4i" name="appointment[time(4i)]"> <select id="appointment_time_4i" name="appointment[time(4i)]">
@ -13,6 +14,7 @@ describe "select_time" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) "appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
@ -22,6 +24,7 @@ describe "select_time" do
it "should accept a time object" do it "should accept a time object" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<label for="appointment_time">Time</label><br /> <label for="appointment_time">Time</label><br />
<select id="appointment_time_4i" name="appointment[time(4i)]"> <select id="appointment_time_4i" name="appointment[time(4i)]">
@ -32,6 +35,7 @@ describe "select_time" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) "appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
@ -41,6 +45,7 @@ describe "select_time" do
it "should work when no label is specified" do it "should work when no label is specified" do
with_html <<-HTML with_html <<-HTML
<html>
<form action="/appointments" method="post"> <form action="/appointments" method="post">
<select id="appointment_time_4i" name="appointment[time(4i)]"> <select id="appointment_time_4i" name="appointment[time(4i)]">
<option value="09">09</option> <option value="09">09</option>
@ -50,6 +55,7 @@ describe "select_time" do
</select> </select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/appointments", webrat_session.should_receive(:post).with("/appointments",
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"}) "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 it "should fail if the specified label is not found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/appointments"> <form method="post" action="/appointments">
<select name="month"><option>January</option></select> <select name="month"><option>January</option></select>
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
lambda { select_time "9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError) 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 describe "visit" do
before do before do
with_html <<-HTML with_html <<-HTML
<html>
Hello world Hello world
</html>
HTML HTML
end end
@ -33,7 +35,9 @@ describe "visit with referer" do
before do before do
webrat_session.instance_variable_set(:@current_url, "/old_url") webrat_session.instance_variable_set(:@current_url, "/old_url")
with_html <<-HTML with_html <<-HTML
<html>
Hello world Hello world
</html>
HTML HTML
end end

View File

@ -16,8 +16,15 @@ Spec::Runner.configure do |config|
include Webrat::Methods include Webrat::Methods
def with_html(html) 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 webrat_session.response_body = html
end end
def with_xml(xml)
raise "This looks like HTML" if xml =~ /^\s*<[^Hh>]*html/i
webrat_session.response_body = xml
end
end end
module Webrat module Webrat

View File

@ -9,18 +9,22 @@ describe "attach_file" do
it "should fail if no file field found" do it "should fail if no file field found" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/widgets"> <form method="post" action="/widgets">
</form> </form>
</html>
HTML HTML
lambda { attach_file("Doc", "/some/path") }.should raise_error(Webrat::NotFoundError) lambda { attach_file("Doc", "/some/path") }.should raise_error(Webrat::NotFoundError)
end end
it "should submit empty strings for blank file fields" do it "should submit empty strings for blank file fields" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/widgets"> <form method="post" action="/widgets">
<input type="file" id="widget_file" name="widget[file]" /> <input type="file" id="widget_file" name="widget[file]" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } }) webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } })
click_button click_button
@ -28,11 +32,13 @@ describe "attach_file" do
it "should submit the attached file" do it "should submit the attached file" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/widgets"> <form method="post" action="/widgets">
<label for="widget_file">Document</label> <label for="widget_file">Document</label>
<input type="file" id="widget_file" name="widget[file]" /> <input type="file" id="widget_file" name="widget[file]" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => @uploaded_file } }) webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => @uploaded_file } })
attach_file "Document", @filename attach_file "Document", @filename
@ -41,6 +47,7 @@ describe "attach_file" do
it "should support collections" do it "should support collections" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/widgets"> <form method="post" action="/widgets">
<label for="widget_file1">Document</label> <label for="widget_file1">Document</label>
<input type="file" id="widget_file1" name="widget[files][]" /> <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="file" id="widget_file2" name="widget[files][]" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
webrat_session.should_receive(:post).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } }) webrat_session.should_receive(:post).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } })
attach_file "Document", @filename attach_file "Document", @filename
@ -57,11 +65,13 @@ describe "attach_file" do
it "should allow the content type to be specified" do it "should allow the content type to be specified" do
with_html <<-HTML with_html <<-HTML
<html>
<form method="post" action="/widgets"> <form method="post" action="/widgets">
<label for="person_picture">Picture</label> <label for="person_picture">Picture</label>
<input type="file" id="person_picture" name="person[picture]" /> <input type="file" id="person_picture" name="person[picture]" />
<input type="submit" /> <input type="submit" />
</form> </form>
</html>
HTML HTML
ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times
attach_file "Picture", @filename, "image/png" attach_file "Picture", @filename, "image/png"