diabolo-webrat 0.4.4 → 0.4.4.1

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.
data/History.txt CHANGED
@@ -1,10 +1,16 @@
1
1
  == 0.4.5 / ?
2
2
 
3
+ * Major enhancements
4
+
5
+ * Improve performance (~2x) on JRuby by supporting Nokogiri
6
+
3
7
  * Minor enhancements
4
8
 
5
9
  * Added support for field_labeled_locators ending in non word characters
6
10
  lh 148 (Zach Dennis)
7
11
  * Filled in tests on click link lh 195 (diabolo)
12
+ * Added current_url to selenium session lh 215 (Luke Amdor)
13
+ * Added silence spec to selenium lh 238 (Martin Gamsjaeger aka snusnu)
8
14
 
9
15
  == 0.4.4 / 2009-04-06
10
16
 
data/Rakefile CHANGED
@@ -37,7 +37,7 @@ end
37
37
 
38
38
  Rake::GemPackageTask.new(spec) do |package|
39
39
  package.gem_spec = spec
40
- endrak
40
+ end
41
41
 
42
42
  Jeweler::Tasks.new(spec)
43
43
 
@@ -110,7 +110,7 @@ end
110
110
 
111
111
  namespace :spec do
112
112
  desc "Run the integration specs"
113
- task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
113
+ task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack"]
114
114
 
115
115
  namespace :integration do
116
116
  desc "Run the Rails integration specs"
@@ -144,7 +144,15 @@ namespace :spec do
144
144
  task :sinatra do
145
145
  Dir.chdir "spec/integration/sinatra" do
146
146
  result = system "rake test"
147
- raise "Sinatra tntegration tests failed" unless result
147
+ raise "Sinatra integration tests failed" unless result
148
+ end
149
+ end
150
+
151
+ desc "Run the Sinatra integration specs"
152
+ task :rack do
153
+ Dir.chdir "spec/integration/rack" do
154
+ result = system "rake test"
155
+ raise "Rack integration tests failed" unless result
148
156
  end
149
157
  end
150
158
  end
data/lib/webrat.rb CHANGED
@@ -10,17 +10,14 @@ module Webrat
10
10
  VERSION = '0.4.4'
11
11
 
12
12
  def self.require_xml
13
- gem "nokogiri", ">= 1.0.6"
14
-
15
13
  if on_java?
16
- # We need Nokogiri's CSS to XPath support, even if using REXML and Hpricot for parsing and searching
17
- require "nokogiri/css"
18
- require "hpricot"
19
- require "rexml/document"
14
+ gem "nokogiri", ">= 1.2.4"
20
15
  else
21
- require "nokogiri"
22
- require "webrat/core/xml/nokogiri"
16
+ gem "nokogiri", ">= 1.0.6"
23
17
  end
18
+
19
+ require "nokogiri"
20
+ require "webrat/core/xml/nokogiri"
24
21
  end
25
22
 
26
23
  def self.on_java?
@@ -60,7 +60,7 @@ module Webrat
60
60
 
61
61
  def initialize # :nodoc:
62
62
  self.open_error_files = true
63
- self.parse_with_nokogiri = !Webrat.on_java?
63
+ self.parse_with_nokogiri = true
64
64
  self.application_environment = :test
65
65
  self.application_port = 3001
66
66
  self.application_address = 'localhost'
@@ -13,7 +13,10 @@ module Webrat
13
13
  when :merb
14
14
  Merb.logger
15
15
  else
16
- nil
16
+ @logger ||= begin
17
+ require "logger"
18
+ ::Logger.new("webrat.log")
19
+ end
17
20
  end
18
21
  end
19
22
 
@@ -16,7 +16,11 @@ module Webrat
16
16
  end
17
17
 
18
18
  def webrat_session
19
- @_webrat_session ||= ::Webrat.session_class.new(self)
19
+ if Webrat.configuration.mode == :rack_test
20
+ @_webrat_session ||= ::Webrat::RackTestSession.new(rack_test_session)
21
+ else
22
+ @_webrat_session ||= ::Webrat.session_class.new(self)
23
+ end
20
24
  end
21
25
 
22
26
  # all of these methods delegate to the @session, which should
@@ -209,8 +209,8 @@ module Webrat
209
209
  # along with the form. An optional <tt>content_type</tt> may be given.
210
210
  #
211
211
  # Example:
212
- # attaches_file "Resume", "/path/to/the/resume.txt"
213
- # attaches_file "Photo", "/path/to/the/image.png", "image/png"
212
+ # attach_file "Resume", "/path/to/the/resume.txt"
213
+ # attach_file "Photo", "/path/to/the/image.png", "image/png"
214
214
  def attach_file(field_locator, path, content_type = nil)
215
215
  locate_field(field_locator, FileField).set(path, content_type)
216
216
  end
@@ -26,6 +26,8 @@ module Webrat
26
26
  SinatraSession
27
27
  when :mechanize
28
28
  MechanizeSession
29
+ when :rack_test
30
+ RackTestSession
29
31
  else
30
32
  raise WebratError.new(<<-STR)
31
33
  Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
@@ -100,11 +102,8 @@ For example:
100
102
  h['HTTP_REFERER'] = @current_url if @current_url
101
103
 
102
104
  debug_log "REQUESTING PAGE: #{http_method.to_s.upcase} #{url} with #{data.inspect} and HTTP headers #{h.inspect}"
103
- if h.empty?
104
- send "#{http_method}", url, data || {}
105
- else
106
- send "#{http_method}", url, data || {}, h
107
- end
105
+
106
+ process_request(http_method, url, data, h)
108
107
 
109
108
  save_and_open_page if exception_caught? && Webrat.configuration.open_error_files?
110
109
  raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
@@ -259,6 +258,14 @@ For example:
259
258
 
260
259
  private
261
260
 
261
+ def process_request(http_method, url, data, headers)
262
+ if headers.empty?
263
+ send "#{http_method}", url, data || {}
264
+ else
265
+ send "#{http_method}", url, data || {}, headers
266
+ end
267
+ end
268
+
262
269
  def response_location
263
270
  response.headers["Location"]
264
271
  end
@@ -0,0 +1,32 @@
1
+ module Webrat
2
+ class RackTestSession < Session
3
+
4
+ def initialize(rack_test_session) #:nodoc:
5
+ super()
6
+ @rack_test_session = rack_test_session
7
+ end
8
+
9
+ def response_body
10
+ response.body
11
+ end
12
+
13
+ def response_code
14
+ response.status
15
+ end
16
+
17
+ def response
18
+ @rack_test_session.last_response
19
+ end
20
+
21
+ protected
22
+
23
+ def process_request(http_method, url, data = {}, headers = {})
24
+ headers ||= {}
25
+ data ||= {}
26
+
27
+ env = headers.merge(:params => data, :method => http_method.to_s.upcase)
28
+ @rack_test_session.request(url, env)
29
+ end
30
+
31
+ end
32
+ end
@@ -1,6 +1,13 @@
1
1
  require "webrat"
2
2
  gem "selenium-client", ">=1.2.14"
3
3
  require "selenium/client"
4
+
5
+ # active_support already defines silence_stream, no need to do that again if it's already present.
6
+ # http://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/kernel/reporting.rb
7
+ unless Kernel.respond_to?(:silence_stream)
8
+ require "webrat/selenium/silence_stream"
9
+ end
10
+
4
11
  require "webrat/selenium/selenium_session"
5
12
  require "webrat/selenium/matchers"
6
13
  require "webrat/core_extensions/tcp_socket"
@@ -2,6 +2,8 @@ module Webrat
2
2
  module Selenium
3
3
 
4
4
  class ApplicationServer
5
+
6
+ include Webrat::Selenium::SilenceStream
5
7
 
6
8
  def self.boot
7
9
  case Webrat.configuration.application_framework
@@ -2,6 +2,8 @@ module Webrat
2
2
  module Selenium
3
3
 
4
4
  class SeleniumRCServer
5
+
6
+ include Webrat::Selenium::SilenceStream
5
7
 
6
8
  def self.boot
7
9
  new.boot
@@ -22,6 +22,7 @@ module Webrat
22
22
 
23
23
  class SeleniumSession
24
24
  include Webrat::SaveAndOpenPage
25
+ include Webrat::Selenium::SilenceStream
25
26
 
26
27
  def initialize(*args) # :nodoc:
27
28
  end
@@ -55,6 +56,10 @@ module Webrat
55
56
  selenium.get_html_source
56
57
  end
57
58
 
59
+ def current_url
60
+ selenium.location
61
+ end
62
+
58
63
  def click_button(button_text_or_regexp = nil, options = {})
59
64
  if button_text_or_regexp.is_a?(Hash) && options == {}
60
65
  pattern, options = nil, button_text_or_regexp
@@ -182,15 +187,6 @@ module Webrat
182
187
 
183
188
  protected
184
189
 
185
- def silence_stream(stream)
186
- old_stream = stream.dup
187
- stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
188
- stream.sync = true
189
- yield
190
- ensure
191
- stream.reopen(old_stream)
192
- end
193
-
194
190
  def setup #:nodoc:
195
191
  Webrat::Selenium::SeleniumRCServer.boot
196
192
  Webrat::Selenium::ApplicationServer.boot
@@ -0,0 +1,14 @@
1
+ module Webrat
2
+ module Selenium
3
+ module SilenceStream
4
+ def silence_stream(stream)
5
+ old_stream = stream.dup
6
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
7
+ stream.sync = true
8
+ yield
9
+ ensure
10
+ stream.reopen(old_stream)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "sinatra/base"
3
+
4
+ class RackApp < Sinatra::Default
5
+ get "/" do
6
+ "Hello World"
7
+ end
8
+
9
+ get "/redirect_absolute_url" do
10
+ redirect URI.join(request.url, "foo").to_s
11
+ end
12
+
13
+ get "/foo" do
14
+ "spam"
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "rack/test"
4
+ require "redgreen"
5
+
6
+ require File.dirname(__FILE__) + "/../../../../lib/webrat"
7
+
8
+ Webrat.configure do |config|
9
+ config.mode = :rack_test
10
+ end
11
+
12
+ class Test::Unit::TestCase
13
+ include Rack::Test::Methods
14
+ include Webrat::Methods
15
+ include Webrat::Matchers
16
+
17
+ def app
18
+ RackApp.new
19
+ end
20
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+ require File.dirname(__FILE__) + "/../rack_app"
3
+
4
+ class WebratRackTest < Test::Unit::TestCase
5
+ def test_visit_returns_response
6
+ response = visit "/"
7
+ assert response.ok?
8
+ end
9
+
10
+ def test_last_response_is_available
11
+ visit "/"
12
+ assert last_response.ok?
13
+ end
14
+
15
+ def test_last_request_is_available
16
+ visit "/"
17
+ assert_equal "/", last_request.env["PATH_INFO"]
18
+ end
19
+
20
+ def test_redirects
21
+ visit "/redirect_absolute_url"
22
+ assert_equal "spam", response_body
23
+ end
24
+
25
+ def test_assertions_after_visit
26
+ visit "/"
27
+ assert_contain "Hello World"
28
+ end
29
+
30
+ def test_assertions_after_visit
31
+ get "/"
32
+ assert_contain "Hello World"
33
+ end
34
+
35
+ # def test_visits_pages
36
+ # visit "/"
37
+ # assert response_body.include?("visit")
38
+ #
39
+ # click_link "there"
40
+ # assert response_body.include?('<form method="post" action="/go">')
41
+ # end
42
+ #
43
+ # def test_submits_form
44
+ # visit "/go"
45
+ # fill_in "Name", :with => "World"
46
+ # fill_in "Email", :with => "world@example.org"
47
+ # click_button "Submit"
48
+ #
49
+ # assert response_body.include?("Hello, World")
50
+ # assert response_body.include?("Your email is: world@example.org")
51
+ # end
52
+ #
53
+ # def test_check_value_of_field
54
+ # visit "/"
55
+ # assert field_labeled("Prefilled").value, "text"
56
+ # end
57
+ #
58
+ # def test_follows_internal_redirects
59
+ # visit "/internal_redirect"
60
+ # assert response_body.include?("visit")
61
+ # end
62
+ #
63
+ # def test_does_not_follow_external_redirects
64
+ # visit "/external_redirect"
65
+ # assert response_code == 302
66
+ # end
67
+ end
@@ -10,6 +10,7 @@ class WebratTest < ActionController::IntegrationTest
10
10
  test "should visit pages" do
11
11
  visit root_path
12
12
  assert_contain("Webrat Form")
13
+ assert URI.parse(current_url).path, root_path
13
14
  end
14
15
 
15
16
  test "should submit forms" do
@@ -9,17 +9,10 @@ describe Webrat::Configuration do
9
9
  end
10
10
 
11
11
  it "should use Nokogiri as the parser by default" do
12
- Webrat.stub!(:on_java? => false)
13
12
  config = Webrat::Configuration.new
14
13
  config.should parse_with_nokogiri
15
14
  end
16
15
 
17
- it "should not use Nokogiri as the parser when on JRuby" do
18
- Webrat.stub!(:on_java? => true)
19
- config = Webrat::Configuration.new
20
- config.should_not parse_with_nokogiri
21
- end
22
-
23
16
  it "should open error files by default" do
24
17
  config = Webrat::Configuration.new
25
18
  config.should open_error_files
@@ -2,16 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  module Webrat
4
4
  describe Field do
5
- it "should have nice inspect output" do
6
- html = <<-HTML
7
- <html>
8
- <input type='checkbox' checked='checked' />
9
- </html>
10
- HTML
5
+ unless Webrat.on_java?
6
+ it "should have nice inspect output" do
7
+ html = <<-HTML
8
+ <html>
9
+ <input type='checkbox' checked='checked' />
10
+ </html>
11
+ HTML
11
12
 
12
- element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
13
- checkbox = CheckboxField.new(nil, element)
14
- checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
13
+ element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
14
+ checkbox = CheckboxField.new(nil, element)
15
+ checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -331,7 +331,7 @@ describe "click_button" do
331
331
  end
332
332
 
333
333
  it "should properly handle HTML entities in textarea default values" do
334
- spec = lambda do
334
+ pending "needs bug fix" do
335
335
  with_html <<-HTML
336
336
  <html>
337
337
  <form method="post" action="/posts">
@@ -343,12 +343,6 @@ describe "click_button" do
343
343
  webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
344
344
  click_button
345
345
  end
346
-
347
- if Webrat.on_java?
348
- spec.call
349
- else
350
- pending("needs bug fix", &spec)
351
- end
352
346
  end
353
347
 
354
348
  it "should send default selected option value from select" do
@@ -101,7 +101,7 @@ describe "click_link" do
101
101
  webrat_session.should_receive(:get).with("/page", {})
102
102
  click_link /_text_/
103
103
  end
104
-
104
+
105
105
  it "should click links by title" do
106
106
  with_html <<-HTML
107
107
  <html>
@@ -111,7 +111,7 @@ describe "click_link" do
111
111
  webrat_session.should_receive(:get).with("/page", {})
112
112
  click_link 'piddle'
113
113
  end
114
-
114
+
115
115
  it "should click links by title regex" do
116
116
  with_html <<-HTML
117
117
  <html>
@@ -153,7 +153,7 @@ describe "field_labeled" do
153
153
  should_return_a Webrat::TextField, :for => "The Label"
154
154
  with_an_id_of "element_42", :for => "The Label"
155
155
  end
156
-
156
+
157
157
  describe "finding a field whose label ends with an non word character" do
158
158
  using_this_html <<-HTML
159
159
  <html>
@@ -163,7 +163,7 @@ describe "field_labeled" do
163
163
  </form>
164
164
  </html>
165
165
  HTML
166
-
166
+
167
167
  should_return_a Webrat::TextField, :for => "License #"
168
168
  with_an_id_of "element_42", :for => "License #"
169
169
  should_raise_error_matching /Could not find .* "Other License #"/, :for => "Other License #"
@@ -71,7 +71,7 @@ describe "select_date" do
71
71
  select_date "December 25, 2003"
72
72
  click_button
73
73
  end
74
-
74
+
75
75
  it "should work when the label ends in a non word character" do
76
76
  with_html <<-HTML
77
77
  <html>
@@ -201,7 +201,7 @@ describe "select" do
201
201
  end
202
202
 
203
203
  it "should properly handle submitting HTML entities in select values" do
204
- spec = lambda do
204
+ pending "needs bug fix" do
205
205
  with_html <<-HTML
206
206
  <html>
207
207
  <form method="post" action="/login">
@@ -213,16 +213,10 @@ describe "select" do
213
213
  webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
214
214
  click_button
215
215
  end
216
-
217
- if Webrat.on_java?
218
- spec.call
219
- else
220
- pending("needs bug fix", &spec)
221
- end
222
216
  end
223
217
 
224
218
  it "should properly handle locating with HTML entities in select values" do
225
- spec = lambda do
219
+ pending "needs bug fix" do
226
220
  with_html <<-HTML
227
221
  <html>
228
222
  <form method="post" action="/login">
@@ -236,14 +230,8 @@ describe "select" do
236
230
  select "Peanut butter & jelly"
237
231
  }.should_not raise_error(Webrat::NotFoundError)
238
232
  end
239
-
240
- if Webrat.on_java?
241
- spec.call
242
- else
243
- pending("needs bug fix", &spec)
244
- end
245
233
  end
246
-
234
+
247
235
  it "should submit duplicates selected options as a single value" do
248
236
  with_html <<-HTML
249
237
  <html>
@@ -253,9 +241,9 @@ describe "select" do
253
241
  </form>
254
242
  </html>
255
243
  HTML
256
-
244
+
257
245
  webrat_session.should_receive(:post).with("/login", "clothes" => "pants")
258
246
  click_button
259
247
  end
260
-
248
+
261
249
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diabolo-webrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-24 00:00:00 -07:00
12
+ date: 2009-05-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ files:
84
84
  - lib/webrat/merb.rb
85
85
  - lib/webrat/merb_session.rb
86
86
  - lib/webrat/rack.rb
87
+ - lib/webrat/rack_test.rb
87
88
  - lib/webrat/rails.rb
88
89
  - lib/webrat/rspec-rails.rb
89
90
  - lib/webrat/selenium.rb
@@ -104,6 +105,7 @@ files:
104
105
  - lib/webrat/selenium/selenium_extensions.js
105
106
  - lib/webrat/selenium/selenium_rc_server.rb
106
107
  - lib/webrat/selenium/selenium_session.rb
108
+ - lib/webrat/selenium/silence_stream.rb
107
109
  - lib/webrat/selenium/sinatra_application_server.rb
108
110
  - lib/webrat/sinatra.rb
109
111
  - vendor/selenium-server.jar
@@ -151,6 +153,9 @@ test_files:
151
153
  - spec/integration/merb/tasks/merb.thor/gem_ext.rb
152
154
  - spec/integration/merb/tasks/merb.thor/ops.rb
153
155
  - spec/integration/merb/tasks/merb.thor/utils.rb
156
+ - spec/integration/rack/rack_app.rb
157
+ - spec/integration/rack/test/test_helper.rb
158
+ - spec/integration/rack/test/webrat_rack_test.rb
154
159
  - spec/integration/rails/app/controllers/application.rb
155
160
  - spec/integration/rails/app/controllers/webrat_controller.rb
156
161
  - spec/integration/rails/config/boot.rb