/
webrat_test.rb
123 lines (103 loc) · 2.86 KB
/
webrat_test.rb
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require 'test_helper'
class WebratTest < ActionController::IntegrationTest
#Firefox raises a security concern under Selenium
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
test "should visit fully qualified urls" do
visit root_url(:host => "chunkybacon.example.com")
assert_equal "chunkybacon", request.subdomains.first
end
end
test "should visit pages" do
visit root_path
assert_contain("Webrat Form")
assert URI.parse(current_url).path, root_path
end
test "should submit forms" do
visit root_path
fill_in "Text field", :with => "Hello"
check "TOS"
select "January"
click_button "Test"
assert_contain "OK"
end
test "should check the value of a field" do
webrat.simulate do
visit "/"
assert field_labeled("Prefilled").value, "text"
end
end
test "should not carry params through redirects" do
visit before_redirect_form_path
fill_in "Text field", :with => "value"
click_button
automate do
selenium.wait_for_page_to_load
end
assert response.body !~ /value/
assert response.body =~ /custom_param/
end
test "should follow internal redirects" do
visit internal_redirect_path
webrat.simulate do
assert !response.redirect?
end
assert response.body.include?("OK")
end
test "should not follow external redirects" do
webrat.simulate do
visit external_redirect_path
assert response.redirect?
end
end
test "should recognize the host header to follow redirects properly" do
webrat.simulate do
header "Host", "foo.bar"
visit host_redirect_path
assert !response.redirect?
assert response.body.include?("OK")
end
end
test "should click link by text" do
visit internal_redirect_path
click_link "Test Link Text"
assert_contain("Webrat Form")
end
test "should click link by id" do
visit internal_redirect_path
click_link "link_id"
assert_contain("Webrat Form")
end
test "should be able to assert xpath" do
visit root_path
assert_have_xpath "//h1"
end
test "should be able to assert selector" do
visit root_path
assert_have_selector "h1"
end
test "should accept an Object argument to #within and translate using dom_id" do
webrat.simulate do
visit within_path
object = Object.new
def object.id
nil
end
within(object) do
click_link "Edit Object"
end
assert_contain "Webrat Form"
end
end
# Firefox detects and prevents infinite redirects under Selenium
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
test "should detect infinite redirects" do
assert_raises Webrat::InfiniteRedirectError do
visit infinite_redirect_path
end
end
end
# test "should be able to assert have tag" do
# visit root_path
# assert_have_tag "h1"
# end
end