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
|
|
|
before do
|
|
|
|
@session = Webrat::TestSession.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should use get by default" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
|
|
|
@session.should_receive(:get).with("/page", {})
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should assert valid response" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
2008-10-25 16:30:30 +00:00
|
|
|
@session.response_code = 501
|
2008-11-05 23:30:14 +00:00
|
|
|
lambda { @session.click_area "Berlin" }.should raise_error
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
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-10-25 16:30:30 +00:00
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
|
|
|
@session.response_code = status
|
2008-11-05 23:30:14 +00:00
|
|
|
lambda { @session.click_area "Berlin" }.should_not raise_error
|
2008-10-25 16:30:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-22 02:35:12 +00:00
|
|
|
it "should fail if the area doesn't exist" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
lambda {
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "Missing area"
|
2008-10-22 02:35:12 +00:00
|
|
|
}.should raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be case sensitive" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="/page" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
|
|
|
@session.should_receive(:get).with("/page", {})
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it "should follow relative links" do
|
|
|
|
@session.stub!(:current_url).and_return("/page")
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<map name="map_de" id="map_de">
|
|
|
|
<area href="sub" title="Berlin" id="berlin" shape="poly" alt="Berlin" coords="180,89,180" />
|
|
|
|
</map>
|
|
|
|
EOS
|
|
|
|
@session.should_receive(:get).with("/page/sub", {})
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should follow fully qualified local links" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<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>
|
|
|
|
EOS
|
|
|
|
@session.should_receive(:get).with("http://www.example.com/page", {})
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should follow query parameters" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<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>
|
|
|
|
EOS
|
|
|
|
@session.should_receive(:get).with("/page?foo=bar", {})
|
2008-11-05 23:30:14 +00:00
|
|
|
@session.click_area "Berlin"
|
2008-10-22 02:35:12 +00:00
|
|
|
end
|
|
|
|
end
|