webrat/spec/public/click_area_spec.rb

107 lines
3.1 KiB
Ruby
Raw Permalink Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2008-11-05 23:30:14 +00:00
describe "click_area" do
it "should use get by default" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.should_receive(:get).with("/page", {})
2008-11-23 05:22:49 +00:00
click_area "Berlin"
end
it "should assert valid response" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.response_code = 501
lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError)
end
[200, 300, 400, 499].each do |status|
2008-10-25 21:17:00 +00:00
it "should consider the #{status} status code as success" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.stub!(:redirect? => false)
2008-11-23 05:22:49 +00:00
webrat_session.response_code = status
lambda { click_area "Berlin" }.should_not raise_error
end
end
it "should fail if the area doesn't exist" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
lambda {
2008-11-23 05:22:49 +00:00
click_area "Missing area"
}.should raise_error(Webrat::NotFoundError)
end
it "should not be case sensitive" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.should_receive(:get).with("/page", {})
2008-11-23 05:22:49 +00:00
click_area "berlin"
end
it "should follow relative links" do
webrat_session.stub!(:current_url => "/page")
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.should_receive(:get).with("/page/sub", {})
2008-11-23 05:22:49 +00:00
click_area "Berlin"
end
it "should follow fully qualified local links" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.should_receive(:get).with("http://www.example.com/page", {})
click_area "Berlin"
end
it "should follow query parameters" do
2008-11-23 05:22:49 +00:00
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>
2008-11-23 05:22:49 +00:00
HTML
webrat_session.should_receive(:get).with("/page?foo=bar", {})
2008-11-23 05:22:49 +00:00
click_area "Berlin"
end
end