2008-10-22 02:35:12 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
2008-11-05 23:30:14 +00:00
|
|
|
describe "click_area" do
|
2008-10-22 02:35:12 +00:00
|
|
|
it "should use get by default" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:37:26 +00:00
|
|
|
webrat_session.should_receive(:get).with("http://www.example.com/page", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should assert valid response" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
|
|
|
webrat_session.response_code = 501
|
|
|
|
lambda { click_area "Berlin" }.should raise_error(Webrat::PageLoadError)
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-25 16:30:30 +00:00
|
|
|
[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
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-25 16:30:30 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2008-12-30 03:45:55 +00:00
|
|
|
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
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|
|
|
|
end
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
it "should fail if the area doesn't exist" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
lambda {
|
2008-11-23 05:22:49 +00:00
|
|
|
click_area "Missing area"
|
|
|
|
}.should raise_error(Webrat::NotFoundError)
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
it "should not be case sensitive" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:37:26 +00:00
|
|
|
webrat_session.should_receive(:get).with("http://www.example.com/page", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
click_area "berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
|
|
|
|
it "should follow relative links" do
|
2009-04-08 00:37:26 +00:00
|
|
|
webrat_session.stub!(:current_url => "http://www.example.com/page")
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:37:26 +00:00
|
|
|
webrat_session.should_receive(:get).with("http://www.example.com/page/sub", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
2008-12-30 03:45:55 +00:00
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
it "should follow fully qualified local links" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<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>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
|
|
|
webrat_session.should_receive(:get).with("http://www.example.com/page", {})
|
|
|
|
click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should follow query parameters" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-10-22 02:35:12 +00:00
|
|
|
<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>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:37:26 +00:00
|
|
|
webrat_session.should_receive(:get).with("http://www.example.com/page?foo=bar", {})
|
2008-11-23 05:22:49 +00:00
|
|
|
click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
end
|