jwilger-webrat 0.4.2.5 → 0.4.3.2

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.
@@ -1,3 +1,20 @@
1
+ == 0.4.3 / 2009-03-17
2
+
3
+ * Minor enhancements
4
+
5
+ * Support Rails 2.3. Use Rack::Utils to parse params (Matthew Ford)
6
+ * Support for "modular" Sinatra app style (Simon Rozet)
7
+ * Initial Merb and Sinatra compatibility for Selenium mode (Corey Donohoe)
8
+ * When faced with a label with no for attribute, that contains a hidden field
9
+ and another field, as can be the case in Rails 2.3's checkbox view,
10
+ webrat now locates the non-hidden field. (Luke Melia)
11
+ * Add application_framework config for Selenium mode to determine how to
12
+ start and stop the app server (Corey Donohoe)
13
+
14
+ * Bug fixes
15
+
16
+ * Fix following of absolute redirect URL in Sinatra (Simon Rozet)
17
+
1
18
  == 0.4.2 / 2009-02-24
2
19
 
3
20
  * Major enhancements
@@ -7,7 +7,7 @@ module Webrat
7
7
  class WebratError < StandardError
8
8
  end
9
9
 
10
- VERSION = '0.4.2.5'
10
+ VERSION = '0.4.3.2'
11
11
 
12
12
  def self.require_xml
13
13
  gem "nokogiri", ">= 1.0.6"
@@ -39,6 +39,9 @@ module Webrat
39
39
  webrat_deprecate :selenium_port, :application_port
40
40
  webrat_deprecate :selenium_port=, :application_port=
41
41
 
42
+ # Which underlying app framework we're testing with selenium
43
+ attr_accessor :application_framework
44
+
42
45
  # Which server the application is running on for selenium testing? Defaults to localhost
43
46
  attr_accessor :application_address
44
47
 
@@ -54,6 +57,9 @@ module Webrat
54
57
  # Set the timeout argument for the Selenium jar
55
58
  attr_accessor :selenium_server_timeout
56
59
 
60
+ # Set the timeout argument for the Selenium server startup
61
+ attr_accessor :selenium_server_startup_timeout
62
+
57
63
  # Set any additional arguments (as a string) to pass to the Selenium RC jar
58
64
  attr_accessor :selenium_server_args
59
65
 
@@ -67,10 +73,12 @@ module Webrat
67
73
  self.application_environment = :selenium
68
74
  self.application_port = 3001
69
75
  self.application_address = 'localhost'
76
+ self.application_framework = 'rails'
70
77
  self.selenium_server_port = 4444
71
78
  self.infinite_redirect_limit = 10
72
79
  self.selenium_browser_key = '*firefox'
73
80
  self.selenium_server_timeout = 5
81
+ self.selenium_server_startup_timeout = 120
74
82
  end
75
83
 
76
84
  def parse_with_nokogiri? #:nodoc:
@@ -97,4 +105,5 @@ module Webrat
97
105
  end
98
106
 
99
107
  end
108
+
100
109
  end
@@ -15,6 +15,10 @@ module Webrat
15
15
  def self.xpath_search
16
16
  [".//button", ".//input", ".//textarea", ".//select"]
17
17
  end
18
+
19
+ def self.xpath_search_excluding_hidden
20
+ [".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
21
+ end
18
22
 
19
23
  def self.field_classes
20
24
  @field_classes || []
@@ -80,7 +84,7 @@ module Webrat
80
84
 
81
85
  case Webrat.configuration.mode
82
86
  when :rails
83
- rails_request_parser.parse_query_parameters("#{name}=#{escaped_value}")
87
+ parse_rails_request_params("#{name}=#{escaped_value}")
84
88
  when :merb
85
89
  ::Merb::Parse.query("#{name}=#{escaped_value}")
86
90
  else
@@ -98,12 +102,15 @@ module Webrat
98
102
 
99
103
  protected
100
104
 
101
- def rails_request_parser
105
+ def parse_rails_request_params(params)
102
106
  if defined?(ActionController::AbstractRequest)
103
- ActionController::AbstractRequest
104
- else
107
+ ActionController::AbstractRequest.parse_query_parameters(params)
108
+ elsif defined?(ActionController::UrlEncodedPairParser)
105
109
  # For Rails > 2.2
106
- ActionController::UrlEncodedPairParser
110
+ ActionController::UrlEncodedPairParser.parse_query_parameters(params)
111
+ else
112
+ # For Rails > 2.3
113
+ Rack::Utils.parse_nested_query(params)
107
114
  end
108
115
  end
109
116
 
@@ -21,7 +21,7 @@ module Webrat
21
21
 
22
22
  def field_element
23
23
  if for_id.blank?
24
- Webrat::XML.xpath_at(@element, *Field.xpath_search)
24
+ Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden)
25
25
  else
26
26
  Webrat::XML.css_search(@session.current_dom, "#" + for_id).first
27
27
  end
@@ -16,7 +16,7 @@ module Webrat
16
16
  unless Webrat.configuration.selenium_server_address
17
17
  remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0",
18
18
  Webrat.configuration.selenium_server_port,
19
- Webrat.configuration.selenium_server_timeout)
19
+ Webrat.configuration.selenium_server_startup_timeout)
20
20
  remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
21
21
  remote_control.additional_args = Webrat.configuration.selenium_server_args
22
22
  remote_control.start :background => true
@@ -29,15 +29,55 @@ module Webrat
29
29
  ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", Webrat.configuration.selenium_server_port, 5).stop unless Webrat.configuration.selenium_server_address
30
30
  end
31
31
 
32
- def self.start_app_server #:nodoc:
33
- pid_file = prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
34
- system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
32
+ def self.pid_file
33
+ if File.exists?('config.ru')
34
+ prepare_pid_file(Dir.pwd, 'rack.pid')
35
+ else
36
+ prepare_pid_file("#{RAILS_ROOT}/tmp/pids", "mongrel_selenium.pid")
37
+ end
38
+ end
39
+ # Start the appserver for the underlying framework to test
40
+ #
41
+ # Sinatra: requires a config.ru in the root of your sinatra app to use this
42
+ # Merb: Attempts to use bin/merb and falls back to the system merb
43
+ # Rails: Calls mongrel_rails to startup the appserver
44
+ def self.start_app_server
45
+ case Webrat.configuration.application_framework
46
+ when :sinatra
47
+ fork do
48
+ File.open('rack.pid', 'w') { |fp| fp.write Process.pid }
49
+ exec 'rackup', File.expand_path(Dir.pwd + '/config.ru'), '-p', Webrat.configuration.application_port.to_s
50
+ end
51
+ when :merb
52
+ cmd = 'merb'
53
+ if File.exist?('bin/merb')
54
+ cmd = 'bin/merb'
55
+ end
56
+ system("#{cmd} -d -p #{Webrat.configuration.application_port} -e #{Webrat.configuration.application_environment}")
57
+ else # rails
58
+ system("mongrel_rails start -d --chdir='#{RAILS_ROOT}' --port=#{Webrat.configuration.application_port} --environment=#{Webrat.configuration.application_environment} --pid #{pid_file} &")
59
+ end
35
60
  TCPSocket.wait_for_service :host => Webrat.configuration.application_address, :port => Webrat.configuration.application_port.to_i
36
61
  end
37
62
 
38
- def self.stop_app_server #:nodoc:
39
- pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
40
- system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
63
+ # Stop the appserver for the underlying framework under test
64
+ #
65
+ # Sinatra: Reads and kills the pid from the pid file created on startup
66
+ # Merb: Reads and kills the pid from the pid file created on startup
67
+ # Rails: Calls mongrel_rails stop to kill the appserver
68
+ def self.stop_app_server
69
+ case Webrat.configuration.application_framework
70
+ when :sinatra
71
+ pid = File.read('rack.pid')
72
+ system("kill -9 #{pid}")
73
+ FileUtils.rm_f 'rack.pid'
74
+ when :merb
75
+ pid = File.read("log/merb.#{Webrat.configuration.application_port}.pid")
76
+ system("kill -9 #{pid}")
77
+ FileUtils.rm_f "log/merb.#{Webrat.configuration.application_port}.pid"
78
+ else # rails
79
+ system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
80
+ end
41
81
  end
42
82
 
43
83
  def self.prepare_pid_file(file_path, pid_file_name)
@@ -64,11 +104,25 @@ module Webrat
64
104
  # selenium.dragdrop("id=photo_123", "+350, 0")
65
105
  # end
66
106
  #
67
- # == Auto-starting of the mongrel and java server
107
+ # == Choosing the underlying framework to test
108
+ #
109
+ # Webrat assumes you're using rails by default but it can also work with sinatra
110
+ # and merb. To take advantage of this you can use the configuration block to
111
+ # set the application_framework variable.
112
+ # require "webrat"
113
+ #
114
+ # Webrat.configure do |config|
115
+ # config.mode = :selenium
116
+ # config.application_port = 4567
117
+ # config.application_framework = :sinatra # could also be :merb
118
+ # end
119
+ #
120
+ # == Auto-starting of the appserver and java server
68
121
  #
69
122
  # Webrat will automatically start the Selenium Java server process and an instance
70
123
  # of Mongrel when a test is run. The Mongrel will run in the "selenium" environment
71
- # instead of "test", so ensure you've got that defined, and will run on port 3001.
124
+ # instead of "test", so ensure you've got that defined, and will run on port
125
+ # Webrat.configuration.application_port.
72
126
  #
73
127
  # == Waiting
74
128
  #
@@ -93,11 +147,12 @@ module Webrat
93
147
  end
94
148
  end
95
149
  end
96
-
97
- module ActionController #:nodoc:
98
- IntegrationTest.class_eval do
99
- include Webrat::Methods
100
- include Webrat::Selenium::Methods
101
- include Webrat::Selenium::Matchers
150
+ if defined?(ActionController::IntegrationTest)
151
+ module ActionController #:nodoc:
152
+ IntegrationTest.class_eval do
153
+ include Webrat::Methods
154
+ include Webrat::Selenium::Methods
155
+ include Webrat::Selenium::Matchers
156
+ end
102
157
  end
103
158
  end
@@ -180,11 +180,21 @@ module Webrat
180
180
  end
181
181
 
182
182
  protected
183
+ def silence_stream(stream)
184
+ old_stream = stream.dup
185
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
186
+ stream.sync = true
187
+ yield
188
+ ensure
189
+ stream.reopen(old_stream)
190
+ end
183
191
 
184
192
  def setup #:nodoc:
185
193
  silence_stream(STDOUT) do
186
- Webrat.start_selenium_server
187
- Webrat.start_app_server
194
+ silence_stream(STDERR) do
195
+ Webrat.start_selenium_server
196
+ Webrat.start_app_server
197
+ end
188
198
  end
189
199
 
190
200
  create_browser
@@ -1,30 +1,44 @@
1
- require 'webrat/rack'
2
- require 'sinatra'
3
- require 'sinatra/test'
4
-
5
- class Sinatra::Application
6
- # Override this to prevent Sinatra from barfing on the options passed from RSpec
7
- def self.load_default_options_from_command_line!
8
- end
9
- end
10
-
11
- disable :run
12
- disable :reload
1
+ require "webrat/rack"
2
+ require "sinatra/test"
13
3
 
14
4
  module Webrat
15
- class SinatraSession < RackSession #:nodoc:
5
+ class SinatraSession < RackSession
16
6
  include Sinatra::Test
17
7
 
18
8
  attr_reader :request, :response
19
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
+
20
17
  %w(get head post put delete).each do |verb|
21
- alias_method "orig_#{verb}", verb
22
- define_method(verb) do |*args| # (path, data, headers = nil)
23
- path, data, headers = *args
24
- data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
25
- params = data.merge(:env => headers || {})
26
- self.__send__("orig_#{verb}", path, params)
27
- end
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
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
29
43
  end
30
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwilger-webrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.5
4
+ version: 0.4.3.2
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-03-02 00:00:00 -08:00
12
+ date: 2009-03-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency