Skip to content

Commit

Permalink
Ensure all example HTML is wrapped in <html> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Nov 28, 2008
1 parent 3744009 commit 31aa659
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 23 deletions.
2 changes: 2 additions & 0 deletions spec/api/basic_auth_spec.rb
Expand Up @@ -12,9 +12,11 @@

it "should be present in form submits" do
with_html <<-HTML
<html>
<form method="post" action="/form1">
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"})
click_button
Expand Down
12 changes: 12 additions & 0 deletions spec/api/check_spec.rb
Expand Up @@ -26,12 +26,14 @@

it "should check rails style checkboxes" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
</html>
HTML

webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
Expand Down Expand Up @@ -86,41 +88,49 @@
describe "uncheck" do
it "should fail if no checkbox found" do
with_html <<-HTML
<html>
<form method="post" action="/login">
</form>
</html>
HTML

lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError)
end

it "should fail if input is not a checkbox" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
</html>
HTML

lambda { uncheck "remember_me" }.should raise_error(Webrat::NotFoundError)
end

it "should fail if the checkbox is disabled" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="checkbox" name="remember_me" checked="checked" disabled="disabled" />
<input type="submit" />
</form>
</html>
HTML
lambda { uncheck "remember_me" }.should raise_error(Webrat::DisabledFieldError)
end

it "should uncheck rails style checkboxes" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
check "TOS"
Expand All @@ -130,10 +140,12 @@

it "should result in value not being posted" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", {})
uncheck "remember_me"
Expand Down
16 changes: 16 additions & 0 deletions spec/api/choose_spec.rb
Expand Up @@ -3,32 +3,38 @@
describe "choose" do
it "should fail if no radio buttons found" do
with_html <<-HTML
<html>
<form method="post" action="/login">
</form>
</html>
HTML

lambda { choose "first option" }.should raise_error(Webrat::NotFoundError)
end

it "should fail if input is not a radio button" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="text" name="first_option" />
</form>
</html>
HTML

lambda { choose "first_option" }.should raise_error(Webrat::NotFoundError)
end

it "should check rails style radio buttons" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
choose "Male"
Expand All @@ -37,13 +43,15 @@

it "should only submit last chosen value" do
with_html <<-HTML
<html>
<form method="get" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
choose "Female"
Expand All @@ -53,21 +61,25 @@

it "should fail if the radio button is disabled" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="radio" name="first_option" disabled="disabled" />
<input type="submit" />
</form>
</html>
HTML

lambda { choose "first_option" }.should raise_error(Webrat::DisabledFieldError)
end

it "should result in the value on being posted if not specified" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="radio" name="first_option" />
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "first_option" => "on")
choose "first_option"
Expand All @@ -76,24 +88,28 @@

it "should result in the value on being posted if not specified and checked by default" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input type="radio" name="first_option" checked="checked"/>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "first_option" => "on")
click_button
end

it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" checked="checked" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/login", "user" => {"gender" => "M"})
choose "Male"
Expand Down
16 changes: 16 additions & 0 deletions spec/api/click_area_spec.rb
Expand Up @@ -3,19 +3,23 @@
describe "click_area" do
it "should use get by default" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("/page", {})
click_area "Berlin"
end

it "should assert valid response" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.response_code = 501
lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError)
Expand All @@ -24,9 +28,11 @@
[200, 300, 400, 499].each do |status|
it "should consider the #{status} status code as success" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.response_code = status
lambda { click_area "Berlin" }.should_not raise_error
Expand All @@ -35,9 +41,11 @@

it "should fail if the area doesn't exist" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML

lambda {
Expand All @@ -47,9 +55,11 @@

it "should not be case sensitive" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("/page", {})
click_area "berlin"
Expand All @@ -59,29 +69,35 @@
it "should follow relative links" do
webrat_session.stub!(:current_url => "/page")
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("/page/sub", {})
click_area "Berlin"
end

it "should follow fully qualified local links" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="http://www.example.com/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("http://www.example.com/page", {})
click_area "Berlin"
end

it "should follow query parameters" do
with_html <<-HTML
<html>
<map name="map_de" id="map_de">
<area href="/page?foo=bar" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
</map>
</html>
HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {})
click_area "Berlin"
Expand Down

0 comments on commit 31aa659

Please sign in to comment.