kbaum-webrat 0.5.1 → 0.6.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +19 -0
- data/History.txt +11 -1
- data/Rakefile +25 -66
- data/Thorfile +117 -0
- data/lib/webrat/adapters/rails.rb +1 -16
- data/lib/webrat/core/elements/link.rb +1 -1
- data/lib/webrat/core/session.rb +1 -1
- data/lib/webrat/integrations/merb.rb +1 -1
- data/lib/webrat/integrations/rails.rb +16 -0
- data/lib/webrat/integrations/rspec-rails.rb +2 -1
- data/lib/webrat/integrations/selenium.rb +1 -1
- data/lib/webrat/rspec-rails.rb +1 -1
- data/lib/webrat/selenium/application_servers/external.rb +1 -1
- data/lib/webrat/selenium/application_servers.rb +1 -1
- data/lib/webrat/selenium/location_strategy_javascript/label.js +31 -13
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
- data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
- data/lib/webrat/selenium/selenium_session.rb +19 -2
- data/lib/webrat/selenium/silence_stream.rb +1 -1
- data/lib/webrat.rb +1 -1
- data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
- data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
- data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
- data/spec/integration/rails/config/environment.rb +1 -1
- data/spec/integration/rails/config/routes.rb +1 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
- data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
- data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
- data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
- data/spec/integration/rails/test/test_helper.rb +1 -0
- data/spec/private/core/field_spec.rb +9 -11
- data/spec/private/rails/rails_adapter_spec.rb +0 -24
- data/spec/public/basic_auth_spec.rb +13 -2
- data/spec/public/click_link_spec.rb +21 -0
- data/spec/public/fill_in_spec.rb +1 -1
- data/spec/public/matchers/have_selector_spec.rb +1 -1
- data/webrat.gemspec +307 -315
- metadata +13 -42
- data/VERSION +0 -1
- data/selenium_rc_server.patch +0 -20
@@ -1,80 +1,66 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ButtonClickTest < ActionController::IntegrationTest
|
4
|
-
# <button type="button" ...>
|
5
|
-
test "should click button with type button by id" do
|
6
|
-
visit buttons_path
|
7
|
-
click_button "button_button_id"
|
8
|
-
end
|
9
|
-
test "should click button with type button by value" do
|
10
|
-
visit buttons_path
|
11
|
-
click_button "button_button_value"
|
12
|
-
end
|
13
|
-
test "should click button with type button by html" do
|
14
|
-
visit buttons_path
|
15
|
-
click_button "button_button_text"
|
16
|
-
end
|
17
|
-
|
18
4
|
# <button type="submit" ...>
|
19
5
|
test "should click button with type submit by id" do
|
20
6
|
visit buttons_path
|
21
7
|
click_button "button_submit_id"
|
8
|
+
assert_contain "success"
|
22
9
|
end
|
23
10
|
test "should click button with type submit by value" do
|
24
11
|
visit buttons_path
|
25
12
|
click_button "button_submit_value"
|
13
|
+
assert_contain "success"
|
26
14
|
end
|
27
15
|
test "should click button with type submit by html" do
|
28
16
|
visit buttons_path
|
29
17
|
click_button "button_submit_text"
|
18
|
+
assert_contain "success"
|
30
19
|
end
|
31
20
|
|
32
21
|
# <button type="image" ...>
|
33
22
|
test "should click button with type image by id" do
|
34
23
|
visit buttons_path
|
35
24
|
click_button "button_image_id"
|
25
|
+
assert_contain "success"
|
36
26
|
end
|
37
27
|
test "should click button with type image by value" do
|
38
28
|
visit buttons_path
|
39
29
|
click_button "button_image_value"
|
30
|
+
assert_contain "success"
|
40
31
|
end
|
41
32
|
test "should click button with type image by html" do
|
42
33
|
visit buttons_path
|
43
34
|
click_button "button_image_text"
|
44
|
-
|
45
|
-
|
46
|
-
# <input type="button" ...>
|
47
|
-
test "should click image with type button by id" do
|
48
|
-
visit buttons_path
|
49
|
-
click_button "input_button_id"
|
50
|
-
end
|
51
|
-
test "should click input with type button by value" do
|
52
|
-
visit buttons_path
|
53
|
-
click_button "input_button_value"
|
35
|
+
assert_contain "success"
|
54
36
|
end
|
55
37
|
|
56
38
|
# <input type="submit" ...>
|
57
39
|
test "should click input with type submit by id" do
|
58
40
|
visit buttons_path
|
59
41
|
click_button "input_submit_id"
|
42
|
+
assert_contain "success"
|
60
43
|
end
|
61
44
|
test "should click input with type submit by value" do
|
62
45
|
visit buttons_path
|
63
46
|
click_button "input_submit_value"
|
47
|
+
assert_contain "success"
|
64
48
|
end
|
65
49
|
|
66
50
|
# <input type="image" ...>
|
67
51
|
test "should click input with type image by id" do
|
68
52
|
visit buttons_path
|
69
53
|
click_button "input_image_id"
|
54
|
+
assert_contain "success"
|
70
55
|
end
|
71
56
|
test "should click input with type image by value" do
|
72
57
|
visit buttons_path
|
73
58
|
click_button "input_image_value"
|
59
|
+
assert_contain "success"
|
74
60
|
end
|
75
61
|
test "should click input with type image by alt" do
|
76
62
|
visit buttons_path
|
77
63
|
click_button "input_image_alt"
|
64
|
+
assert_contain "success"
|
78
65
|
end
|
79
|
-
|
80
|
-
end
|
66
|
+
end
|
@@ -22,11 +22,14 @@ class WebratTest < ActionController::IntegrationTest
|
|
22
22
|
check "TOS"
|
23
23
|
select "January"
|
24
24
|
click_button "Test"
|
25
|
+
assert_contain "OK"
|
25
26
|
end
|
26
27
|
|
27
28
|
test "should check the value of a field" do
|
28
|
-
|
29
|
-
|
29
|
+
webrat.simulate do
|
30
|
+
visit "/"
|
31
|
+
assert field_labeled("Prefilled").value, "text"
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
test "should not carry params through redirects" do
|
@@ -43,20 +46,26 @@ class WebratTest < ActionController::IntegrationTest
|
|
43
46
|
|
44
47
|
test "should follow internal redirects" do
|
45
48
|
visit internal_redirect_path
|
46
|
-
|
49
|
+
webrat.simulate do
|
50
|
+
assert !response.redirect?
|
51
|
+
end
|
47
52
|
assert response.body.include?("OK")
|
48
53
|
end
|
49
54
|
|
50
55
|
test "should not follow external redirects" do
|
51
|
-
|
52
|
-
|
56
|
+
webrat.simulate do
|
57
|
+
visit external_redirect_path
|
58
|
+
assert response.redirect?
|
59
|
+
end
|
53
60
|
end
|
54
61
|
|
55
62
|
test "should recognize the host header to follow redirects properly" do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
webrat.simulate do
|
64
|
+
header "Host", "foo.bar"
|
65
|
+
visit host_redirect_path
|
66
|
+
assert !response.redirect?
|
67
|
+
assert response.body.include?("OK")
|
68
|
+
end
|
60
69
|
end
|
61
70
|
|
62
71
|
test "should click link by text" do
|
@@ -81,6 +90,23 @@ class WebratTest < ActionController::IntegrationTest
|
|
81
90
|
assert_have_selector "h1"
|
82
91
|
end
|
83
92
|
|
93
|
+
test "should accept an Object argument to #within and translate using dom_id" do
|
94
|
+
webrat.simulate do
|
95
|
+
visit within_path
|
96
|
+
|
97
|
+
object = Object.new
|
98
|
+
def object.id
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
within(object) do
|
103
|
+
click_link "Edit Object"
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_contain "Webrat Form"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
84
110
|
# Firefox detects and prevents infinite redirects under Selenium
|
85
111
|
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
|
86
112
|
test "should detect infinite redirects" do
|
@@ -2,18 +2,16 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|
2
2
|
|
3
3
|
module Webrat
|
4
4
|
describe Field do
|
5
|
-
|
6
|
-
|
7
|
-
html
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
HTML
|
5
|
+
it "should have nice inspect output" do
|
6
|
+
html = <<-HTML
|
7
|
+
<html>
|
8
|
+
<input type='checkbox' checked='checked' />
|
9
|
+
</html>
|
10
|
+
HTML
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
element = Webrat::XML.document(html).css("input").first
|
13
|
+
checkbox = CheckboxField.new(nil, element)
|
14
|
+
checkbox.inspect.should =~ /^#<Webrat::CheckboxField @element=/
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
@@ -83,28 +83,4 @@ describe Webrat::RailsAdapter do
|
|
83
83
|
it "should provide a doc_root" do
|
84
84
|
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
|
85
85
|
end
|
86
|
-
|
87
|
-
it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
|
88
|
-
pending "Move this to spec/public/within_spec.rb"
|
89
|
-
|
90
|
-
body = <<-HTML
|
91
|
-
<a href="/page1">Edit</a>
|
92
|
-
<div id="new_object">
|
93
|
-
<a href="/page2">Edit</a>
|
94
|
-
</div>
|
95
|
-
HTML
|
96
|
-
|
97
|
-
response = mock("response", :body => body, :headers => {}, :code => 200)
|
98
|
-
@integration_session.stub!(:response => response)
|
99
|
-
@integration_session.should_receive(:get).with("/page2", {}, nil)
|
100
|
-
|
101
|
-
rails_session = Webrat::RailsAdapter.new(@integration_session)
|
102
|
-
|
103
|
-
object = Object.new
|
104
|
-
object.stub!(:id => nil)
|
105
|
-
|
106
|
-
rails_session.within(object) do
|
107
|
-
rails_session.click_link 'Edit'
|
108
|
-
end
|
109
|
-
end
|
110
86
|
end
|
@@ -6,7 +6,7 @@ describe "Basic Auth HTTP headers" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should be present in visit" do
|
9
|
-
webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ
|
9
|
+
webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="})
|
10
10
|
visit("/")
|
11
11
|
end
|
12
12
|
|
@@ -18,7 +18,18 @@ describe "Basic Auth HTTP headers" do
|
|
18
18
|
</form>
|
19
19
|
</html>
|
20
20
|
HTML
|
21
|
-
webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ
|
21
|
+
webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="})
|
22
22
|
click_button
|
23
23
|
end
|
24
|
+
|
25
|
+
context "with long username and password combination" do
|
26
|
+
before do
|
27
|
+
basic_auth('user', 'secret1234567890123456789012345678901234567890123456789012345678901234567890')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be present, without new lines, in visit" do
|
31
|
+
webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkw"})
|
32
|
+
visit("/")
|
33
|
+
end
|
34
|
+
end
|
24
35
|
end
|
@@ -144,6 +144,27 @@ describe "click_link" do
|
|
144
144
|
click_link "Posts"
|
145
145
|
end
|
146
146
|
|
147
|
+
it "should click rails 2.3.4 javascript links with authenticity tokens" do
|
148
|
+
with_html <<-HTML
|
149
|
+
<html>
|
150
|
+
<a href="/posts" onclick="var f = document.createElement('form');
|
151
|
+
f.style.display = 'none';
|
152
|
+
this.parentNode.appendChild(f);
|
153
|
+
f.method = 'POST';
|
154
|
+
f.action = this.href;
|
155
|
+
var s = document.createElement('input');
|
156
|
+
s.setAttribute('type', 'hidden');
|
157
|
+
s.setAttribute('name', 'authenticity_token');
|
158
|
+
s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a');
|
159
|
+
f.appendChild(s);
|
160
|
+
f.submit();
|
161
|
+
return false;">Posts</a>
|
162
|
+
</html>
|
163
|
+
HTML
|
164
|
+
webrat_session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62=/$a")
|
165
|
+
click_link "Posts"
|
166
|
+
end
|
167
|
+
|
147
168
|
it "should click rails javascript delete links" do
|
148
169
|
with_html <<-HTML
|
149
170
|
<html>
|
data/spec/public/fill_in_spec.rb
CHANGED
@@ -61,7 +61,7 @@ describe "have_selector" do
|
|
61
61
|
@body.should have_selector("li", :count => 4)
|
62
62
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "should convert a string to an integer for count" do
|
66
66
|
@body.should have_selector("li", :count => "3")
|
67
67
|
end
|