davidtrogers-webrat 0.4.4.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/.gitignore +3 -1
  2. data/Gemfile +19 -0
  3. data/History.txt +99 -9
  4. data/Rakefile +141 -207
  5. data/Thorfile +118 -0
  6. data/lib/webrat.rb +10 -23
  7. data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +6 -2
  8. data/lib/webrat/adapters/merb.rb +11 -0
  9. data/lib/webrat/adapters/rack.rb +25 -0
  10. data/lib/webrat/{rails.rb → adapters/rails.rb} +5 -37
  11. data/lib/webrat/adapters/sinatra.rb +9 -0
  12. data/lib/webrat/core.rb +0 -1
  13. data/lib/webrat/core/configuration.rb +22 -18
  14. data/lib/webrat/core/elements/area.rb +2 -2
  15. data/lib/webrat/core/elements/element.rb +3 -3
  16. data/lib/webrat/core/elements/field.rb +113 -31
  17. data/lib/webrat/core/elements/form.rb +4 -4
  18. data/lib/webrat/core/elements/label.rb +4 -4
  19. data/lib/webrat/core/elements/link.rb +8 -7
  20. data/lib/webrat/core/elements/select_option.rb +15 -2
  21. data/lib/webrat/core/locators.rb +1 -1
  22. data/lib/webrat/core/locators/area_locator.rb +3 -3
  23. data/lib/webrat/core/locators/button_locator.rb +6 -6
  24. data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
  25. data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
  26. data/lib/webrat/core/locators/field_named_locator.rb +3 -3
  27. data/lib/webrat/core/locators/form_locator.rb +1 -1
  28. data/lib/webrat/core/locators/label_locator.rb +2 -2
  29. data/lib/webrat/core/locators/link_locator.rb +16 -8
  30. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  31. data/lib/webrat/core/logging.rb +4 -5
  32. data/lib/webrat/core/matchers/have_content.rb +3 -8
  33. data/lib/webrat/core/matchers/have_xpath.rb +3 -28
  34. data/lib/webrat/core/methods.rb +5 -4
  35. data/lib/webrat/core/mime.rb +11 -22
  36. data/lib/webrat/core/save_and_open_page.rb +7 -29
  37. data/lib/webrat/core/scope.rb +17 -2
  38. data/lib/webrat/core/session.rb +31 -19
  39. data/lib/webrat/core/xml.rb +41 -84
  40. data/lib/webrat/integrations/merb.rb +10 -0
  41. data/lib/webrat/integrations/rails.rb +25 -0
  42. data/lib/webrat/integrations/rspec-rails.rb +11 -0
  43. data/lib/webrat/integrations/selenium.rb +11 -0
  44. data/lib/webrat/rspec-rails.rb +2 -13
  45. data/lib/webrat/selenium.rb +0 -11
  46. data/lib/webrat/selenium/application_server_factory.rb +40 -0
  47. data/lib/webrat/selenium/application_servers.rb +5 -0
  48. data/lib/webrat/selenium/application_servers/base.rb +46 -0
  49. data/lib/webrat/selenium/application_servers/external.rb +26 -0
  50. data/lib/webrat/selenium/application_servers/merb.rb +50 -0
  51. data/lib/webrat/selenium/application_servers/rails.rb +44 -0
  52. data/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
  53. data/lib/webrat/selenium/location_strategy_javascript/label.js +30 -3
  54. data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
  55. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
  56. data/lib/webrat/selenium/matchers/have_content.rb +22 -10
  57. data/lib/webrat/selenium/matchers/have_selector.rb +8 -0
  58. data/lib/webrat/selenium/matchers/have_xpath.rb +8 -0
  59. data/lib/webrat/selenium/selenium_rc_server.rb +8 -6
  60. data/lib/webrat/selenium/selenium_session.rb +43 -14
  61. data/lib/webrat/selenium/silence_stream.rb +2 -2
  62. data/spec/fakes/{test_session.rb → test_adapter.rb} +4 -5
  63. data/spec/integration/mechanize/Rakefile +7 -0
  64. data/spec/integration/mechanize/config.ru +2 -0
  65. data/spec/integration/mechanize/sample_app.rb +20 -0
  66. data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
  67. data/spec/integration/mechanize/spec/spec_helper.rb +29 -0
  68. data/spec/integration/merb/app/controllers/testing.rb +9 -0
  69. data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  70. data/spec/integration/merb/config/router.rb +1 -0
  71. data/spec/integration/merb/spec/spec_helper.rb +2 -0
  72. data/spec/integration/merb/spec/webrat_spec.rb +7 -0
  73. data/spec/integration/rack/app.rb +89 -0
  74. data/spec/integration/rack/test/helper.rb +21 -0
  75. data/spec/integration/rack/test/webrat_rack_test.rb +57 -51
  76. data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
  77. data/spec/integration/rails/app/controllers/webrat_controller.rb +16 -9
  78. data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
  79. data/spec/integration/rails/app/views/links/show.html.erb +2 -1
  80. data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
  81. data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
  82. data/spec/integration/rails/config/environment.rb +1 -1
  83. data/spec/integration/rails/config/routes.rb +2 -0
  84. data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
  85. data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
  86. data/spec/integration/rails/test/integration/link_click_test.rb +8 -2
  87. data/spec/integration/rails/test/integration/webrat_test.rb +53 -5
  88. data/spec/integration/rails/test/test_helper.rb +7 -5
  89. data/spec/integration/sinatra/test/test_helper.rb +3 -2
  90. data/spec/private/core/configuration_spec.rb +8 -27
  91. data/spec/private/core/field_spec.rb +14 -16
  92. data/spec/private/core/link_spec.rb +1 -1
  93. data/spec/private/core/session_spec.rb +23 -26
  94. data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -12
  95. data/spec/private/nokogiri_spec.rb +2 -2
  96. data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +11 -42
  97. data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
  98. data/spec/public/basic_auth_spec.rb +13 -2
  99. data/spec/public/click_button_spec.rb +10 -12
  100. data/spec/public/click_link_spec.rb +21 -0
  101. data/spec/public/fill_in_spec.rb +15 -0
  102. data/spec/public/matchers/contain_spec.rb +12 -19
  103. data/spec/public/matchers/have_selector_spec.rb +6 -2
  104. data/spec/public/matchers/have_xpath_spec.rb +3 -3
  105. data/spec/public/save_and_open_spec.rb +15 -17
  106. data/spec/public/select_spec.rb +232 -26
  107. data/spec/public/selenium/application_server_factory_spec.rb +49 -0
  108. data/spec/public/selenium/application_servers/external_spec.rb +12 -0
  109. data/spec/public/selenium/selenium_session_spec.rb +37 -0
  110. data/spec/spec_helper.rb +5 -1
  111. data/vendor/selenium-server.jar +0 -0
  112. metadata +119 -69
  113. data/.dotest/0001 +0 -34
  114. data/.dotest/0002 +0 -34
  115. data/.dotest/binary +0 -1
  116. data/.dotest/final-commit +0 -1
  117. data/.dotest/head-name +0 -1
  118. data/.dotest/info +0 -5
  119. data/.dotest/keep +0 -1
  120. data/.dotest/last +0 -1
  121. data/.dotest/msg +0 -0
  122. data/.dotest/msg-clean +0 -0
  123. data/.dotest/next +0 -1
  124. data/.dotest/onto +0 -1
  125. data/.dotest/orig-head +0 -1
  126. data/.dotest/patch +0 -29
  127. data/.dotest/sign +0 -1
  128. data/.dotest/utf8 +0 -1
  129. data/.dotest/whitespace +0 -1
  130. data/VERSION +0 -1
  131. data/lib/webrat/core/xml/hpricot.rb +0 -19
  132. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  133. data/lib/webrat/core/xml/rexml.rb +0 -24
  134. data/lib/webrat/merb_session.rb +0 -65
  135. data/lib/webrat/rack.rb +0 -24
  136. data/lib/webrat/rack_test.rb +0 -32
  137. data/lib/webrat/selenium/application_server.rb +0 -73
  138. data/lib/webrat/selenium/merb_application_server.rb +0 -48
  139. data/lib/webrat/selenium/rails_application_server.rb +0 -42
  140. data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
  141. data/lib/webrat/sinatra.rb +0 -44
  142. data/spec/integration/rack/rack_app.rb +0 -16
  143. data/spec/integration/rack/test/test_helper.rb +0 -20
  144. data/spec/private/core/logging_spec.rb +0 -10
  145. data/spec/private/merb/merb_session_spec.rb +0 -42
@@ -2,11 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  describe Webrat::Session do
4
4
 
5
- it "should not have a doc_root" do
6
- session = Webrat::Session.new
7
- session.doc_root.should be_nil
8
- end
9
-
10
5
  it "should expose the current_dom" do
11
6
  session = Webrat::Session.new
12
7
 
@@ -21,27 +16,6 @@ describe Webrat::Session do
21
16
  session.should respond_to(:current_dom)
22
17
  end
23
18
 
24
- it "should open the page in the browser in MacOSX" do
25
- session = Webrat::Session.new
26
- session.stub!(:ruby_platform => 'darwin')
27
- session.should_receive(:`).with("open path")
28
- session.open_in_browser("path")
29
- end
30
-
31
- it "should open the page in the browser in cygwin" do
32
- session = Webrat::Session.new
33
- session.stub!(:ruby_platform => 'i386-cygwin')
34
- session.should_receive(:`).with("rundll32 url.dll,FileProtocolHandler path\\to\\file")
35
- session.open_in_browser("path/to/file")
36
- end
37
-
38
- it "should open the page in the browser in Win32" do
39
- session = Webrat::Session.new
40
- session.stub!(:ruby_platform => 'win32')
41
- session.should_receive(:`).with("rundll32 url.dll,FileProtocolHandler path\\to\\file")
42
- session.open_in_browser("path/to/file")
43
- end
44
-
45
19
  it "should provide a current_page for backwards compatibility" do
46
20
  session = Webrat::Session.new
47
21
  current_page = session.current_page
@@ -83,6 +57,11 @@ describe Webrat::Session do
83
57
  it "should raise an error if a symbol Mime type is passed that does not exist" do
84
58
  lambda { webrat_session.http_accept(:oogabooga) }.should raise_error(ArgumentError)
85
59
  end
60
+
61
+ it "should recognize a couple of webrat-specific formats" do
62
+ webrat_session.http_accept(:multipart_form).should == "multipart/form-data"
63
+ webrat_session.http_accept(:url_encoded_form).should == "application/x-www-form-urlencoded"
64
+ end
86
65
  end
87
66
 
88
67
  describe "#request_page" do
@@ -127,6 +106,24 @@ describe Webrat::Session do
127
106
  webrat_session = Webrat::Session.new
128
107
  end
129
108
 
109
+ it "should return true if the last response was a redirect and Fixnum#/ returns a Rational" do
110
+ # This happens if the ruby-units gem has been required
111
+ Fixnum.class_eval do
112
+ alias_method :original_divide, "/".to_sym
113
+
114
+ def /(other)
115
+ Rational(self, other)
116
+ end
117
+ end
118
+
119
+ webrat_session.stub!(:response_code => 301)
120
+ webrat_session.redirect?.should be_true
121
+
122
+ Fixnum.class_eval do
123
+ alias_method "/".to_sym, :original_divide
124
+ end
125
+ end
126
+
130
127
  it "should return true if the last response was a redirect" do
131
128
  webrat_session.stub!(:response_code => 301)
132
129
  webrat_session.redirect?.should be_true
@@ -1,20 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- require "webrat/mechanize"
4
-
5
- describe Webrat::MechanizeSession do
3
+ describe Webrat::MechanizeAdapter do
6
4
  before :each do
7
5
  Webrat.configuration.mode = :mechanize
8
6
  end
9
7
 
10
8
  before(:each) do
11
- @mech = Webrat::MechanizeSession.new
12
- end
13
-
14
- describe "headers method" do
15
- it "should return empty headers for a newly initialized session" do
16
- @mech.headers.should == {}
17
- end
9
+ @mech = Webrat::MechanizeAdapter.new
18
10
  end
19
11
 
20
12
  describe "post" do
@@ -34,13 +26,13 @@ describe Webrat::MechanizeSession do
34
26
  mechanize = mock(:mechanize)
35
27
  WWW::Mechanize.stub!(:new => mechanize)
36
28
  mechanize.should_receive(:post).with(url, flattened_data)
37
- Webrat::MechanizeSession.new.post(url, data)
29
+ Webrat::MechanizeAdapter.new.post(url, data)
38
30
  end
39
31
  end
40
32
 
41
33
  describe "#absolute_url" do
42
34
  before(:each) do
43
- @session = Webrat::MechanizeSession.new
35
+ @session = Webrat::MechanizeAdapter.new
44
36
  @session.stub!(:current_url).and_return(absolute_url)
45
37
  end
46
38
 
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
3
+ # if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
4
4
  describe "Nokogiri Extension" do
5
5
  include Webrat::Matchers
6
6
 
@@ -74,4 +74,4 @@ if defined?(Nokogiri::XML) && Webrat.configuration.parse_with_nokogiri?
74
74
  end
75
75
  end
76
76
  end
77
- end
77
+ # end
@@ -1,8 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
- require "webrat/rails"
4
-
5
- describe Webrat::RailsSession do
3
+ describe Webrat::RailsAdapter do
6
4
  before :each do
7
5
  Webrat.configuration.mode = :rails
8
6
  @integration_session = mock("integration_session")
@@ -10,35 +8,35 @@ describe Webrat::RailsSession do
10
8
 
11
9
  it "should delegate response_body to the session response body" do
12
10
  @integration_session.stub!(:response => mock("response", :body => "<html>"))
13
- Webrat::RailsSession.new(@integration_session).response_body.should == "<html>"
11
+ Webrat::RailsAdapter.new(@integration_session).response_body.should == "<html>"
14
12
  end
15
13
 
16
14
  it "should delegate response_code to the session response code" do
17
15
  @integration_session.stub!(:response => mock("response", :code => "42"))
18
- Webrat::RailsSession.new(@integration_session).response_code.should == 42
16
+ Webrat::RailsAdapter.new(@integration_session).response_code.should == 42
19
17
  end
20
18
 
21
19
  it "should delegate get to the integration session" do
22
20
  @integration_session.should_receive(:get).with("url", "data", "headers")
23
- rails_session = Webrat::RailsSession.new(@integration_session)
21
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
24
22
  rails_session.get("url", "data", "headers")
25
23
  end
26
24
 
27
25
  it "should delegate post to the integration session" do
28
26
  @integration_session.should_receive(:post).with("url", "data", "headers")
29
- rails_session = Webrat::RailsSession.new(@integration_session)
27
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
30
28
  rails_session.post("url", "data", "headers")
31
29
  end
32
30
 
33
31
  it "should delegate put to the integration session" do
34
32
  @integration_session.should_receive(:put).with("url", "data", "headers")
35
- rails_session = Webrat::RailsSession.new(@integration_session)
33
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
36
34
  rails_session.put("url", "data", "headers")
37
35
  end
38
36
 
39
37
  it "should delegate delete to the integration session" do
40
38
  @integration_session.should_receive(:delete).with("url", "data", "headers")
41
- rails_session = Webrat::RailsSession.new(@integration_session)
39
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
42
40
  rails_session.delete("url", "data", "headers")
43
41
  end
44
42
 
@@ -46,7 +44,7 @@ describe Webrat::RailsSession do
46
44
  it "should pass the full url" do
47
45
  @integration_session.stub!(:https!)
48
46
  @integration_session.should_receive(:get).with("http://www.example.com/url", "data", "headers")
49
- rails_session = Webrat::RailsSession.new(@integration_session)
47
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
50
48
  rails_session.get("http://www.example.com/url", "data", "headers")
51
49
  end
52
50
  end
@@ -55,7 +53,7 @@ describe Webrat::RailsSession do
55
53
  it "should call #https! with true before the request before passing along the full url" do
56
54
  @integration_session.should_receive(:https!).with(true)
57
55
  @integration_session.should_receive(:get).with("https://www.example.com/url", "data", "headers")
58
- rails_session = Webrat::RailsSession.new(@integration_session)
56
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
59
57
  rails_session.get("https://www.example.com/url", "data", "headers")
60
58
  end
61
59
  end
@@ -64,7 +62,7 @@ describe Webrat::RailsSession do
64
62
  it "should call #https! with true before the request" do
65
63
  @integration_session.stub!(:get)
66
64
  @integration_session.should_receive(:https!).with(false)
67
- rails_session = Webrat::RailsSession.new(@integration_session)
65
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
68
66
  rails_session.get("http://www.example.com/url", "data", "headers")
69
67
  end
70
68
  end
@@ -73,38 +71,9 @@ describe Webrat::RailsSession do
73
71
  it "should strip out the anchor" do
74
72
  @integration_session.should_receive(:https!).with(false)
75
73
  @integration_session.should_receive(:get).with("http://www.example.com/url", "data", "headers")
76
- rails_session = Webrat::RailsSession.new(@integration_session)
74
+ rails_session = Webrat::RailsAdapter.new(@integration_session)
77
75
  rails_session.get("http://www.example.com/url#foo", "data", "headers")
78
76
  end
79
77
  end
80
78
 
81
- it "should provide a saved_page_dir" do
82
- Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
83
- end
84
-
85
- it "should provide a doc_root" do
86
- Webrat::RailsSession.new(mock("integration session")).should respond_to(:doc_root)
87
- end
88
-
89
- it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
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::RailsSession.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
79
  end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+ require "webrat/selenium/application_servers/rails"
3
+
4
+ RAILS_ROOT = "." unless defined?(RAILS_ROOT)
5
+
6
+ describe Webrat::Selenium::ApplicationServers::Rails do
7
+ include Webrat::Selenium::SilenceStream
8
+
9
+ before do
10
+ @server = Webrat::Selenium::ApplicationServers::Rails.new
11
+ # require "rubygems"; require "ruby-debug"; Debugger.start; debugger
12
+ @server.stub!(:system)
13
+ @server.stub!(:at_exit)
14
+ end
15
+
16
+ describe "boot" do
17
+ it "should wait for the server to start on 0.0.0.0" do
18
+ TCPSocket.should_receive(:wait_for_service_with_timeout).
19
+ with(hash_including(:host => "0.0.0.0"))
20
+
21
+ silence_stream(STDERR) do
22
+ @server.boot
23
+ end
24
+ end
25
+ end
26
+ 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
@@ -331,18 +331,16 @@ describe "click_button" do
331
331
  end
332
332
 
333
333
  it "should properly handle HTML entities in textarea default values" do
334
- pending "needs bug fix" do
335
- with_html <<-HTML
336
- <html>
337
- <form method="post" action="/posts">
338
- <textarea name="post[body]">Peanut butter &amp; jelly</textarea>
339
- <input type="submit" />
340
- </form>
341
- </html>
342
- HTML
343
- webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
344
- click_button
345
- end
334
+ with_html <<-HTML
335
+ <html>
336
+ <form method="post" action="/posts">
337
+ <textarea name="post[body]">Peanut butter &amp; jelly</textarea>
338
+ <input type="submit" />
339
+ </form>
340
+ </html>
341
+ HTML
342
+ webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
343
+ click_button
346
344
  end
347
345
 
348
346
  it "should send default selected option value from select" do
@@ -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>
@@ -16,6 +16,21 @@ describe "fill_in" do
16
16
  click_button
17
17
  end
18
18
 
19
+ it "should support multiline values" do
20
+ with_html <<-HTML
21
+ <html>
22
+ <form method="post" action="/login">
23
+ <label for="user_text">User Text</label>
24
+ <textarea id="user_text" name="user[text]"></textarea>
25
+ <input type="submit" />
26
+ </form>
27
+ </html>
28
+ HTML
29
+ webrat_session.should_receive(:post).with("/login", "user" => {"text" => "One\nTwo"})
30
+ fill_in "User Text", :with => "One\nTwo"
31
+ click_button
32
+ end
33
+
19
34
  it "should work with password fields" do
20
35
  with_html <<-HTML
21
36
  <html>
@@ -3,21 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
3
3
  describe "contain" do
4
4
  include Webrat::Matchers
5
5
 
6
- before(:each) do
7
- @body = <<-HTML
8
- <div id='main'>
9
- <div class='inner'>hello, world!</div>
10
- <h2>Welcome "Bryan"</h2>
11
- <h3>Welcome 'Bryan'</h3>
12
- <h4>Welcome 'Bryan"</h4>
13
- <ul>
14
- <li>First</li>
15
- <li>Second</li>
16
- </ul>
17
- </div>
18
- HTML
19
- end
20
-
21
6
  before(:each) do
22
7
  @body = <<-EOF
23
8
  <div id='main'>
@@ -34,6 +19,14 @@ describe "contain" do
34
19
  it "should call element#matches? when the argument is a regular expression" do
35
20
  @body.should contain(/hello, world/)
36
21
  end
22
+
23
+ it "should treat newlines as spaces" do
24
+ "<div>it takes\ndifferent strokes</div>".should contain("it takes different strokes")
25
+ end
26
+
27
+ it "should multiple spaces as a single space" do
28
+ "<div>it takes different strokes</div>".should contain("it takes different strokes")
29
+ end
37
30
  end
38
31
 
39
32
  describe "asserts for contains," do
@@ -56,13 +49,13 @@ describe "contain" do
56
49
  it "should throw an exception when the body doesnt contain the text" do
57
50
  lambda {
58
51
  assert_contain("monkeys")
59
- }.should raise_error(Test::Unit::AssertionFailedError)
52
+ }.should raise_error(AssertionFailedError)
60
53
  end
61
54
 
62
55
  it "should throw an exception when the body doesnt contain the regexp" do
63
56
  lambda {
64
57
  assert_contain(/monkeys/)
65
- }.should raise_error(Test::Unit::AssertionFailedError)
58
+ }.should raise_error(AssertionFailedError)
66
59
  end
67
60
  end
68
61
 
@@ -78,13 +71,13 @@ describe "contain" do
78
71
  it "should throw an exception when the body does contain the text" do
79
72
  lambda {
80
73
  assert_not_contain("hello, world")
81
- }.should raise_error(Test::Unit::AssertionFailedError)
74
+ }.should raise_error(AssertionFailedError)
82
75
  end
83
76
 
84
77
  it "should throw an exception when the body does contain the regexp" do
85
78
  lambda {
86
79
  assert_not_contain(/hello, world/)
87
- }.should raise_error(Test::Unit::AssertionFailedError)
80
+ }.should raise_error(AssertionFailedError)
88
81
  end
89
82
  end
90
83
  end