diabolo-webrat 0.4.4.2 → 0.5.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.
Files changed (148) hide show
  1. data/.document +4 -0
  2. data/.gitignore +15 -0
  3. data/History.txt +60 -9
  4. data/Rakefile +90 -75
  5. data/VERSION +1 -0
  6. data/lib/webrat.rb +8 -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} +9 -18
  11. data/lib/webrat/adapters/sinatra.rb +9 -0
  12. data/lib/webrat/core.rb +0 -1
  13. data/lib/webrat/core/configuration.rb +7 -17
  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 +33 -30
  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 +7 -6
  20. data/lib/webrat/core/elements/select_option.rb +2 -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 +20 -12
  30. data/lib/webrat/core/locators/select_option_locator.rb +5 -5
  31. data/lib/webrat/core/logging.rb +1 -1
  32. data/lib/webrat/core/matchers/have_content.rb +2 -7
  33. data/lib/webrat/core/matchers/have_xpath.rb +2 -27
  34. data/lib/webrat/core/methods.rb +4 -4
  35. data/lib/webrat/core/mime.rb +11 -22
  36. data/lib/webrat/core/save_and_open_page.rb +5 -7
  37. data/lib/webrat/core/scope.rb +2 -2
  38. data/lib/webrat/core/session.rb +30 -14
  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 +9 -0
  42. data/lib/webrat/integrations/rspec-rails.rb +10 -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 +2 -1
  54. data/lib/webrat/selenium/selenium_rc_server.rb +7 -5
  55. data/lib/webrat/selenium/selenium_session.rb +20 -7
  56. data/lib/webrat/selenium/silence_stream.rb +1 -1
  57. data/spec/fakes/{test_session.rb → test_adapter.rb} +6 -3
  58. data/spec/integration/mechanize/Rakefile +7 -0
  59. data/spec/integration/mechanize/config.ru +2 -0
  60. data/spec/integration/mechanize/sample_app.rb +20 -0
  61. data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
  62. data/spec/integration/mechanize/spec/spec_helper.rb +27 -0
  63. data/spec/integration/merb/.gitignore +21 -0
  64. data/spec/integration/merb/Rakefile +35 -0
  65. data/spec/integration/merb/app/controllers/testing.rb +9 -0
  66. data/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  67. data/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
  68. data/spec/integration/merb/app/views/layout/application.html.erb +12 -0
  69. data/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
  70. data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  71. data/spec/integration/merb/config/router.rb +1 -0
  72. data/spec/integration/merb/spec/spec.opts +1 -0
  73. data/spec/integration/merb/spec/spec_helper.rb +2 -0
  74. data/spec/integration/merb/spec/webrat_spec.rb +7 -0
  75. data/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
  76. data/spec/integration/rack/Rakefile +5 -0
  77. data/spec/integration/rack/app.rb +89 -0
  78. data/spec/integration/rack/test/helper.rb +21 -0
  79. data/spec/integration/rack/test/webrat_rack_test.rb +57 -51
  80. data/spec/integration/rails/.gitignore +3 -0
  81. data/spec/integration/rails/Rakefile +30 -0
  82. data/spec/integration/rails/app/controllers/webrat_controller.rb +13 -9
  83. data/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
  84. data/spec/integration/rails/app/views/fields/show.html.erb +9 -0
  85. data/spec/integration/rails/app/views/links/show.html.erb +5 -0
  86. data/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
  87. data/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
  88. data/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
  89. data/spec/integration/rails/config/locales/en.yml +5 -0
  90. data/spec/integration/rails/config/routes.rb +1 -0
  91. data/spec/integration/rails/public/404.html +30 -0
  92. data/spec/integration/rails/public/422.html +30 -0
  93. data/spec/integration/rails/public/500.html +33 -0
  94. data/spec/integration/rails/script/about +4 -0
  95. data/spec/integration/rails/script/console +3 -0
  96. data/spec/integration/rails/script/dbconsole +3 -0
  97. data/spec/integration/rails/script/destroy +3 -0
  98. data/spec/integration/rails/script/generate +3 -0
  99. data/spec/integration/rails/script/performance/benchmarker +3 -0
  100. data/spec/integration/rails/script/performance/profiler +3 -0
  101. data/spec/integration/rails/script/performance/request +3 -0
  102. data/spec/integration/rails/script/plugin +3 -0
  103. data/spec/integration/rails/script/process/inspector +3 -0
  104. data/spec/integration/rails/script/process/reaper +3 -0
  105. data/spec/integration/rails/script/process/spawner +3 -0
  106. data/spec/integration/rails/script/runner +3 -0
  107. data/spec/integration/rails/script/server +3 -0
  108. data/spec/integration/rails/test/integration/button_click_test.rb +2 -2
  109. data/spec/integration/rails/test/integration/link_click_test.rb +7 -1
  110. data/spec/integration/rails/test/integration/webrat_test.rb +22 -0
  111. data/spec/integration/rails/test/test_helper.rb +6 -5
  112. data/spec/integration/sinatra/Rakefile +5 -0
  113. data/spec/integration/sinatra/test/test_helper.rb +3 -2
  114. data/spec/private/core/configuration_spec.rb +8 -27
  115. data/spec/private/core/field_spec.rb +7 -7
  116. data/spec/private/core/link_spec.rb +1 -1
  117. data/spec/private/core/session_spec.rb +23 -21
  118. data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -12
  119. data/spec/private/nokogiri_spec.rb +2 -2
  120. data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +16 -16
  121. data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
  122. data/spec/public/matchers/contain_spec.rb +4 -4
  123. data/spec/public/matchers/have_selector_spec.rb +2 -2
  124. data/spec/public/matchers/have_xpath_spec.rb +3 -3
  125. data/spec/public/save_and_open_spec.rb +25 -6
  126. data/spec/public/selenium/application_server_factory_spec.rb +49 -0
  127. data/spec/public/selenium/application_servers/external_spec.rb +12 -0
  128. data/spec/public/selenium/selenium_session_spec.rb +37 -0
  129. data/spec/rcov.opts +1 -0
  130. data/spec/spec.opts +2 -0
  131. data/spec/spec_helper.rb +5 -1
  132. data/vendor/selenium-server.jar +0 -0
  133. data/webrat.gemspec +348 -0
  134. metadata +176 -23
  135. data/lib/webrat/core/xml/hpricot.rb +0 -19
  136. data/lib/webrat/core/xml/nokogiri.rb +0 -76
  137. data/lib/webrat/core/xml/rexml.rb +0 -24
  138. data/lib/webrat/merb_session.rb +0 -65
  139. data/lib/webrat/rack.rb +0 -24
  140. data/lib/webrat/rack_test.rb +0 -32
  141. data/lib/webrat/selenium/application_server.rb +0 -73
  142. data/lib/webrat/selenium/merb_application_server.rb +0 -48
  143. data/lib/webrat/selenium/rails_application_server.rb +0 -42
  144. data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
  145. data/lib/webrat/sinatra.rb +0 -44
  146. data/spec/integration/rack/rack_app.rb +0 -16
  147. data/spec/integration/rack/test/test_helper.rb +0 -20
  148. data/spec/private/merb/merb_session_spec.rb +0 -42
data/lib/webrat/rack.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'webrat'
2
-
3
- class CGIMethods #:nodoc:
4
- def self.parse_query_parameters(params)
5
- hash = {}
6
- params.split('&').each do |p|
7
- pair = p.split('=')
8
- hash[pair[0]] = pair[1]
9
- end
10
- hash
11
- end
12
- end
13
-
14
- module Webrat
15
- class RackSession < Session #:nodoc:
16
- def response_body
17
- @response.body
18
- end
19
-
20
- def response_code
21
- @response.status
22
- end
23
- end
24
- end
@@ -1,32 +0,0 @@
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,73 +0,0 @@
1
- module Webrat
2
- module Selenium
3
-
4
- class ApplicationServer
5
-
6
- include Webrat::Selenium::SilenceStream
7
-
8
- def self.boot
9
- case Webrat.configuration.application_framework
10
- when :sinatra
11
- require "webrat/selenium/sinatra_application_server"
12
- SinatraApplicationServer.new.boot
13
- when :merb
14
- require "webrat/selenium/merb_application_server"
15
- MerbApplicationServer.new.boot
16
- when :rails
17
- require "webrat/selenium/rails_application_server"
18
- RailsApplicationServer.new.boot
19
- else
20
- raise WebratError.new(<<-STR)
21
- Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect}
22
-
23
- Please ensure you have a Webrat configuration block that specifies an application_framework
24
- in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
25
-
26
- For example:
27
-
28
- Webrat.configure do |config|
29
- # ...
30
- config.application_framework = :rails
31
- end
32
- STR
33
- end
34
- end
35
-
36
- def boot
37
- start
38
- wait
39
- stop_at_exit
40
- end
41
-
42
- def stop_at_exit
43
- at_exit do
44
- stop
45
- end
46
- end
47
-
48
- def wait
49
- $stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
50
- wait_for_socket
51
- $stderr.print "Ready!\n"
52
- end
53
-
54
- def wait_for_socket
55
- silence_stream(STDOUT) do
56
- TCPSocket.wait_for_service_with_timeout \
57
- :host => Webrat.configuration.application_address,
58
- :port => Webrat.configuration.application_port.to_i,
59
- :timeout => 30 # seconds
60
- end
61
- rescue SocketError
62
- fail
63
- end
64
-
65
- def prepare_pid_file(file_path, pid_file_name)
66
- FileUtils.mkdir_p File.expand_path(file_path)
67
- File.expand_path("#{file_path}/#{pid_file_name}")
68
- end
69
-
70
- end
71
-
72
- end
73
- end
@@ -1,48 +0,0 @@
1
- module Webrat
2
- module Selenium
3
-
4
- class MerbApplicationServer < ApplicationServer
5
-
6
- def start
7
- system start_command
8
- end
9
-
10
- def stop
11
- silence_stream(STDOUT) do
12
- pid = File.read(pid_file)
13
- system("kill -9 #{pid}")
14
- FileUtils.rm_f pid_file
15
- end
16
- end
17
-
18
- def fail
19
- $stderr.puts
20
- $stderr.puts
21
- $stderr.puts "==> Failed to boot the Merb application server... exiting!"
22
- $stderr.puts
23
- $stderr.puts "Verify you can start a Merb server on port #{Webrat.configuration.application_port} with the following command:"
24
- $stderr.puts
25
- $stderr.puts " #{start_command}"
26
- exit
27
- end
28
-
29
- def pid_file
30
- "log/merb.#{Webrat.configuration.application_port}.pid"
31
- end
32
-
33
- def start_command
34
- "#{merb_command} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}"
35
- end
36
-
37
- def merb_command
38
- if File.exist?('bin/merb')
39
- merb_cmd = 'bin/merb'
40
- else
41
- merb_cmd = 'merb'
42
- end
43
- end
44
-
45
- end
46
-
47
- end
48
- end
@@ -1,42 +0,0 @@
1
- module Webrat
2
- module Selenium
3
-
4
- class RailsApplicationServer < ApplicationServer
5
-
6
- def start
7
- system start_command
8
- end
9
-
10
- def stop
11
- silence_stream(STDOUT) do
12
- system stop_command
13
- end
14
- end
15
-
16
- def fail
17
- $stderr.puts
18
- $stderr.puts
19
- $stderr.puts "==> Failed to boot the Rails application server... exiting!"
20
- $stderr.puts
21
- $stderr.puts "Verify you can start a Rails server on port #{Webrat.configuration.application_port} with the following command:"
22
- $stderr.puts
23
- $stderr.puts " #{start_command}"
24
- exit
25
- end
26
-
27
- def pid_file
28
- prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
29
- end
30
-
31
- def start_command
32
- "mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &"
33
- end
34
-
35
- def stop_command
36
- "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
37
- end
38
-
39
- end
40
-
41
- end
42
- end
@@ -1,35 +0,0 @@
1
- module Webrat
2
- module Selenium
3
-
4
- class SinatraApplicationServer < ApplicationServer
5
-
6
- def start
7
- fork do
8
- File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
9
- exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
10
- end
11
- end
12
-
13
- def stop
14
- silence_stream(STDOUT) do
15
- pid = File.read(pid_file)
16
- system("kill -9 #{pid}")
17
- FileUtils.rm_f pid_file
18
- end
19
- end
20
-
21
- def fail
22
- $stderr.puts
23
- $stderr.puts
24
- $stderr.puts "==> Failed to boot the Sinatra application server... exiting!"
25
- exit
26
- end
27
-
28
- def pid_file
29
- prepare_pid_file(Dir.pwd, 'rack.pid')
30
- end
31
-
32
- end
33
-
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- require "webrat/rack"
2
- require "sinatra/test"
3
-
4
- module Webrat
5
- class SinatraSession < RackSession
6
- include Sinatra::Test
7
-
8
- attr_reader :request, :response
9
-
10
- def initialize(context = nil)
11
- super(context)
12
-
13
- app = context.respond_to?(:app) ? context.app : Sinatra::Application
14
- @browser = Sinatra::TestHarness.new(app)
15
- end
16
-
17
- %w(get head post put delete).each do |verb|
18
- class_eval <<-RUBY
19
- def #{verb}(path, data, headers = {})
20
- params = data.inject({}) do |data, (key,value)|
21
- data[key] = Rack::Utils.unescape(value)
22
- data
23
- end
24
- headers["HTTP_HOST"] = "www.example.com"
25
- @browser.#{verb}(path, params, headers)
26
- end
27
- RUBY
28
- end
29
-
30
- def response_body
31
- @browser.body
32
- end
33
-
34
- def response_code
35
- @browser.status
36
- end
37
-
38
- private
39
-
40
- def response
41
- @browser.response
42
- end
43
- end
44
- end
@@ -1,16 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,42 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- require "webrat/merb"
4
-
5
- describe Webrat::MerbSession do
6
- it "should not pass empty params if data is and empty hash" do
7
- session = Webrat::MerbSession.new
8
- response = OpenStruct.new
9
- response.status = 200
10
- session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
11
- session.get('url', {}, nil)
12
- end
13
-
14
- %w{post put delete}.each do |request_method|
15
- it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
16
- session = Webrat::MerbSession.new
17
- response = OpenStruct.new
18
- response.status = 200
19
-
20
- session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
21
- session.send(request_method, 'url', {}, nil)
22
- end
23
- end
24
-
25
- context "a session with a response" do
26
- before do
27
- @session = Webrat::MerbSession.new
28
- @response = OpenStruct.new
29
- @response.status = 200
30
- @response.body = 'test response'
31
- @session.instance_variable_set(:@response, @response)
32
- end
33
-
34
- it "should return body of a request as a response_body" do
35
- @session.response_body.should == @response.body
36
- end
37
-
38
- it "should return status of a request as a response_code" do
39
- @session.response_code.should == @response.status
40
- end
41
- end
42
- end