public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
commit  b4dd15025018421956da7f1f94a284baec950e9a
tree    edd79c4ff55dbd8e10f8af821f121c9a725a2681
parent  828857f88ebb3045ecf27bf8ab659db6f3a9d136
webrat / spec / public / click_area_spec.rb
100644 106 lines (95 sloc) 3.106 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
 
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)
  end
  
  [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
    end
  end
  
  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 {
      click_area "Missing area"
    }.should raise_error(Webrat::NotFoundError)
  end
  
  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"
  end
  
 
  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"
  end
end