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
webrat / spec / public / select_date_spec.rb
100644 89 lines (82 sloc) 3.105 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
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
 
describe "select_date" do
  it "should send the values for each individual date component" do
    with_html <<-HTML
<html>
<form action="/appointments" method="post">
<label for="appointment_date">Date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]">
<option value="2003">2003</option>
</select>
<select id="appointment_date_2i" name="appointment[date(2i)]">
<option value="12">December</option>
</select>
<select id="appointment_date_3i" name="appointment[date(3i)]">
<option value="25">25</option>
</select>
<input type="submit" />
</form>
</html>
HTML
    webrat_session.should_receive(:post).with("/appointments",
      "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
    select_date "December 25, 2003", :from => "Date"
    click_button
  end
  
  it "should accept a date object" do
    with_html <<-HTML
<html>
<form action="/appointments" method="post">
<label for="appointment_date">date</label><br />
<select id="appointment_date_1i" name="appointment[date(1i)]">
<option value="2003">2003</option>
</select>
<select id="appointment_date_2i" name="appointment[date(2i)]">
<option value="12">December</option>
</select>
<select id="appointment_date_3i" name="appointment[date(3i)]">
<option value="25">25</option>
</select>
<input type="submit" />
</form>
</html>
HTML
    webrat_session.should_receive(:post).with("/appointments",
      "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
    select_date Date.parse("December 25, 2003"), :from => "date"
    click_button
  end
 
  it "should work when no label is specified" do
    with_html <<-HTML
<html>
<form action="/appointments" method="post">
<select id="appointment_date_1i" name="appointment[date(1i)]">
<option value="2003">2003</option>
</select>
<select id="appointment_date_2i" name="appointment[date(2i)]">
<option value="12">December</option>
</select>
<select id="appointment_date_3i" name="appointment[date(3i)]">
<option value="25">25</option>
</select>
<input type="submit" />
</form>
</html>
HTML
    webrat_session.should_receive(:post).with("/appointments",
      "appointment" => {"date(1i)" => '2003', "date(2i)" => "12", "date(3i)" => "25"})
    select_date "December 25, 2003"
    click_button
  end
 
  it "should fail if the specified label is not found" do
    with_html <<-HTML
<html>
<form method="post" action="/appointments">
<select name="month"><option>January</option></select>
<input type="submit" />
</form>
</html>
HTML
    
    lambda { select_date "December 25, 2003", :from => "date" }.should raise_error(Webrat::NotFoundError)
  end
 
end