kbaum-webrat 0.5.1 → 0.6.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/.gitignore +4 -1
  2. data/Gemfile +19 -0
  3. data/History.txt +11 -1
  4. data/Rakefile +25 -66
  5. data/Thorfile +117 -0
  6. data/lib/webrat/adapters/rails.rb +1 -16
  7. data/lib/webrat/core/elements/link.rb +1 -1
  8. data/lib/webrat/core/session.rb +1 -1
  9. data/lib/webrat/integrations/merb.rb +1 -1
  10. data/lib/webrat/integrations/rails.rb +16 -0
  11. data/lib/webrat/integrations/rspec-rails.rb +2 -1
  12. data/lib/webrat/integrations/selenium.rb +1 -1
  13. data/lib/webrat/rspec-rails.rb +1 -1
  14. data/lib/webrat/selenium/application_servers/external.rb +1 -1
  15. data/lib/webrat/selenium/application_servers.rb +1 -1
  16. data/lib/webrat/selenium/location_strategy_javascript/label.js +31 -13
  17. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  18. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  19. data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
  20. data/lib/webrat/selenium/selenium_session.rb +19 -2
  21. data/lib/webrat/selenium/silence_stream.rb +1 -1
  22. data/lib/webrat.rb +1 -1
  23. data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
  24. data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
  25. data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
  26. data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
  27. data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
  28. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  29. data/spec/integration/rails/config/environment.rb +1 -1
  30. data/spec/integration/rails/config/routes.rb +1 -0
  31. data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
  32. data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
  33. data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
  34. data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
  35. data/spec/integration/rails/test/test_helper.rb +1 -0
  36. data/spec/private/core/field_spec.rb +9 -11
  37. data/spec/private/rails/rails_adapter_spec.rb +0 -24
  38. data/spec/public/basic_auth_spec.rb +13 -2
  39. data/spec/public/click_link_spec.rb +21 -0
  40. data/spec/public/fill_in_spec.rb +1 -1
  41. data/spec/public/matchers/have_selector_spec.rb +1 -1
  42. data/webrat.gemspec +307 -315
  43. metadata +13 -42
  44. data/VERSION +0 -1
  45. 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
- end
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
@@ -21,4 +21,4 @@ class FillInTest < ActionController::IntegrationTest
21
21
  visit fields_path
22
22
  fill_in "[Field]:", :with => "value"
23
23
  end
24
- end
24
+ end
@@ -24,4 +24,4 @@ class LinkClickTest < ActionController::IntegrationTest
24
24
  click_link "Link With (parens)"
25
25
  assert_contain("Link:link_with_parens")
26
26
  end
27
- end
27
+ 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
- visit "/"
29
- assert field_labeled("Prefilled").value, "text"
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
- assert !response.redirect?
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
- visit external_redirect_path
52
- assert response.redirect?
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
- header "Host", "foo.bar"
57
- visit host_redirect_path
58
- assert !response.redirect?
59
- assert response.body.include?("OK")
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
@@ -12,6 +12,7 @@ require "webrat"
12
12
 
13
13
  Webrat.configure do |config|
14
14
  config.mode = ENV['WEBRAT_INTEGRATION_MODE'].to_sym
15
+ config.selenium_browser_key = '*safari'
15
16
  end
16
17
 
17
18
  ActionController::Base.class_eval 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
- unless RUBY_PLATFORM =~ /java/
6
- it "should have nice inspect output" do
7
- html = <<-HTML
8
- <html>
9
- <input type='checkbox' checked='checked' />
10
- </html>
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
- element = Webrat::XML.document(html).css("input").first
14
- checkbox = CheckboxField.new(nil, element)
15
- checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
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=\n"})
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=\n"})
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>
@@ -15,7 +15,7 @@ describe "fill_in" do
15
15
  fill_in "User Text", :with => "filling text area"
16
16
  click_button
17
17
  end
18
-
18
+
19
19
  it "should support multiline values" do
20
20
  with_html <<-HTML
21
21
  <html>
@@ -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