aslakhellesoy-webrat 0.3.2.2 → 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.
Files changed (70) hide show
  1. data/History.txt +158 -19
  2. data/Rakefile +36 -11
  3. data/lib/webrat.rb +8 -11
  4. data/lib/webrat/core/configuration.rb +67 -25
  5. data/lib/webrat/core/elements/area.rb +7 -7
  6. data/lib/webrat/core/elements/element.rb +11 -11
  7. data/lib/webrat/core/elements/field.rb +70 -51
  8. data/lib/webrat/core/elements/form.rb +17 -17
  9. data/lib/webrat/core/elements/label.rb +8 -8
  10. data/lib/webrat/core/elements/link.rb +13 -11
  11. data/lib/webrat/core/elements/select_option.rb +9 -9
  12. data/lib/webrat/core/locators.rb +2 -2
  13. data/lib/webrat/core/locators/area_locator.rb +10 -10
  14. data/lib/webrat/core/locators/button_locator.rb +13 -13
  15. data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
  16. data/lib/webrat/core/locators/field_labeled_locator.rb +19 -13
  17. data/lib/webrat/core/locators/field_locator.rb +7 -7
  18. data/lib/webrat/core/locators/field_named_locator.rb +10 -10
  19. data/lib/webrat/core/locators/form_locator.rb +6 -6
  20. data/lib/webrat/core/locators/label_locator.rb +9 -9
  21. data/lib/webrat/core/locators/link_locator.rb +12 -12
  22. data/lib/webrat/core/locators/locator.rb +5 -5
  23. data/lib/webrat/core/locators/select_option_locator.rb +11 -11
  24. data/lib/webrat/core/logging.rb +7 -4
  25. data/lib/webrat/core/matchers/have_content.rb +19 -15
  26. data/lib/webrat/core/matchers/have_selector.rb +44 -22
  27. data/lib/webrat/core/matchers/have_tag.rb +11 -61
  28. data/lib/webrat/core/matchers/have_xpath.rb +89 -35
  29. data/lib/webrat/core/methods.rb +13 -11
  30. data/lib/webrat/core/mime.rb +3 -3
  31. data/lib/webrat/core/save_and_open_page.rb +9 -9
  32. data/lib/webrat/core/scope.rb +82 -62
  33. data/lib/webrat/core/session.rb +61 -18
  34. data/lib/webrat/core/xml.rb +16 -16
  35. data/lib/webrat/core/xml/hpricot.rb +3 -3
  36. data/lib/webrat/core/xml/nokogiri.rb +14 -14
  37. data/lib/webrat/core/xml/rexml.rb +3 -3
  38. data/lib/webrat/core_extensions/blank.rb +1 -1
  39. data/lib/webrat/core_extensions/deprecate.rb +1 -1
  40. data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
  41. data/lib/webrat/core_extensions/meta_class.rb +1 -1
  42. data/lib/webrat/core_extensions/tcp_socket.rb +27 -0
  43. data/lib/webrat/mechanize.rb +9 -9
  44. data/lib/webrat/merb.rb +5 -61
  45. data/lib/webrat/merb_session.rb +67 -0
  46. data/lib/webrat/rack.rb +45 -14
  47. data/lib/webrat/rails.rb +31 -11
  48. data/lib/webrat/rspec-rails.rb +2 -2
  49. data/lib/webrat/selenium.rb +27 -39
  50. data/lib/webrat/selenium/application_server_factory.rb +40 -0
  51. data/lib/webrat/selenium/application_servers.rb +5 -0
  52. data/lib/webrat/selenium/application_servers/base.rb +44 -0
  53. data/lib/webrat/selenium/application_servers/external.rb +24 -0
  54. data/lib/webrat/selenium/application_servers/merb.rb +48 -0
  55. data/lib/webrat/selenium/application_servers/rails.rb +42 -0
  56. data/lib/webrat/selenium/application_servers/sinatra.rb +35 -0
  57. data/lib/webrat/selenium/location_strategy_javascript/button.js +14 -7
  58. data/lib/webrat/selenium/location_strategy_javascript/label.js +1 -2
  59. data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +4 -1
  60. data/lib/webrat/selenium/matchers.rb +4 -108
  61. data/lib/webrat/selenium/matchers/have_content.rb +66 -0
  62. data/lib/webrat/selenium/matchers/have_selector.rb +49 -0
  63. data/lib/webrat/selenium/matchers/have_tag.rb +72 -0
  64. data/lib/webrat/selenium/matchers/have_xpath.rb +45 -0
  65. data/lib/webrat/selenium/selenium_rc_server.rb +84 -0
  66. data/lib/webrat/selenium/selenium_session.rb +86 -68
  67. data/lib/webrat/selenium/silence_stream.rb +18 -0
  68. metadata +21 -16
  69. data/lib/webrat/core_extensions/hash_with_indifferent_access.rb +0 -131
  70. data/lib/webrat/sinatra.rb +0 -29
@@ -2,14 +2,14 @@ require "mechanize"
2
2
 
3
3
  module Webrat #:nodoc:
4
4
  class MechanizeSession < Session #:nodoc:
5
-
5
+
6
6
  attr_accessor :response
7
7
  alias :page :response
8
-
8
+
9
9
  def request_page(url, http_method, data) #:nodoc:
10
10
  super(absolute_url(url), http_method, data)
11
11
  end
12
-
12
+
13
13
  def get(url, data, headers_argument_not_used = nil)
14
14
  @response = mechanize.get(url, data)
15
15
  end
@@ -26,7 +26,7 @@ module Webrat #:nodoc:
26
26
  end
27
27
  @response = mechanize.post(url, post_data)
28
28
  end
29
-
29
+
30
30
  def response_body
31
31
  @response.content
32
32
  end
@@ -34,13 +34,13 @@ module Webrat #:nodoc:
34
34
  def response_code
35
35
  @response.code.to_i
36
36
  end
37
-
37
+
38
38
  def mechanize
39
- @mechanize = WWW::Mechanize.new
39
+ @mechanize ||= WWW::Mechanize.new
40
40
  end
41
41
 
42
42
  def_delegators :mechanize, :basic_auth
43
-
43
+
44
44
  def absolute_url(url) #:nodoc:
45
45
  current_host, current_path = split_current_url
46
46
  if url =~ Regexp.new('^https?://')
@@ -53,13 +53,13 @@ module Webrat #:nodoc:
53
53
  url
54
54
  end
55
55
  end
56
-
56
+
57
57
  private
58
58
  def split_current_url
59
59
  current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
60
60
  [Regexp.last_match(1), Regexp.last_match(2)]
61
61
  end
62
-
62
+
63
63
  def absolute_path(current_path, url)
64
64
  levels_up = url.split('/').find_all { |x| x == '..' }.size
65
65
  ancestor = if current_path.nil?
@@ -1,65 +1,9 @@
1
1
  require "webrat"
2
2
 
3
- require "cgi"
4
- gem "extlib"
5
- require "extlib"
6
- require "merb-core"
3
+ # This is a temporary hack to support backwards compatibility
4
+ # with Merb 1.0.8 until it's updated to use the new Webrat.configure
5
+ # syntax
7
6
 
8
- HashWithIndifferentAccess = Mash
9
-
10
- module Webrat
11
- class MerbSession < Session #:nodoc:
12
- include Merb::Test::MakeRequest
13
-
14
- attr_accessor :response
15
-
16
- def get(url, data, headers = nil)
17
- do_request(url, data, headers, "GET")
18
- end
19
-
20
- def post(url, data, headers = nil)
21
- do_request(url, data, headers, "POST")
22
- end
23
-
24
- def put(url, data, headers = nil)
25
- do_request(url, data, headers, "PUT")
26
- end
27
-
28
- def delete(url, data, headers = nil)
29
- do_request(url, data, headers, "DELETE")
30
- end
31
-
32
- def response_body
33
- @response.body.to_s
34
- end
35
-
36
- def response_code
37
- @response.status
38
- end
39
-
40
- def do_request(url, data, headers, method)
41
- @response = request(url,
42
- :params => (data && data.any?) ? data : nil,
43
- :headers => headers,
44
- :method => method)
45
- end
46
-
47
- end
48
- end
49
-
50
- module Merb #:nodoc:
51
- module Test #:nodoc:
52
- module RequestHelper #:nodoc:
53
- def request(uri, env = {})
54
- @_webrat_session ||= Webrat::MerbSession.new
55
- @_webrat_session.response = @_webrat_session.request(uri, env)
56
- end
57
- end
58
- end
59
- end
60
-
61
- class Merb::Test::RspecStory #:nodoc:
62
- def browser
63
- @browser ||= Webrat::MerbSession.new
64
- end
7
+ Webrat.configure do |config|
8
+ config.mode = :merb
65
9
  end
@@ -0,0 +1,67 @@
1
+ require "webrat"
2
+
3
+ require "cgi"
4
+ gem "extlib"
5
+ require "extlib"
6
+ require "merb-core"
7
+
8
+ # HashWithIndifferentAccess = Mash
9
+
10
+ module Webrat
11
+ class MerbSession #:nodoc:
12
+ include Merb::Test::MakeRequest
13
+
14
+ attr_accessor :response
15
+
16
+ def initialize(context=nil); end
17
+
18
+ def get(url, data, headers = nil)
19
+ do_request(url, data, headers, "GET")
20
+ end
21
+
22
+ def post(url, data, headers = nil)
23
+ do_request(url, data, headers, "POST")
24
+ end
25
+
26
+ def put(url, data, headers = nil)
27
+ do_request(url, data, headers, "PUT")
28
+ end
29
+
30
+ def delete(url, data, headers = nil)
31
+ do_request(url, data, headers, "DELETE")
32
+ end
33
+
34
+ def response_body
35
+ @response.body.to_s
36
+ end
37
+
38
+ def response_code
39
+ @response.status
40
+ end
41
+
42
+ def do_request(url, data, headers, method)
43
+ @response = request(url,
44
+ :params => (data && data.any?) ? data : nil,
45
+ :headers => headers,
46
+ :method => method)
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ module Merb #:nodoc:
53
+ module Test #:nodoc:
54
+ module RequestHelper #:nodoc:
55
+ def request(uri, env = {})
56
+ @_webrat_session ||= Webrat::MerbSession.new
57
+ @_webrat_session.response = @_webrat_session.request(uri, env)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ class Merb::Test::RspecStory #:nodoc:
64
+ def browser
65
+ @browser ||= Webrat::MerbSession.new
66
+ end
67
+ end
@@ -1,24 +1,55 @@
1
- require 'webrat'
1
+ require "rack/test"
2
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]
3
+ module Webrat
4
+ class RackSession
5
+ def initialize(context) #:nodoc:
6
+ @session = Rack::Test::Session.new(context.app, "www.example.com")
7
+ end
8
+
9
+ def get(url, data = {}, headers = {})
10
+ process_request(:get, url, data, headers)
11
+ end
12
+
13
+ def post(url, data = {}, headers = {})
14
+ process_request(:post, url, data, headers)
15
+ end
16
+
17
+ def put(url, data = {}, headers = {})
18
+ process_request(:put, url, data, headers)
19
+ end
20
+
21
+ def delete(url, data = {}, headers = {})
22
+ process_request(:delete, url, data, headers)
9
23
  end
10
- hash
11
- end
12
- end
13
24
 
14
- module Webrat
15
- class RackSession < Session #:nodoc:
16
25
  def response_body
17
- @response.body
26
+ response.body
18
27
  end
19
28
 
20
29
  def response_code
21
- @response.status
30
+ response.status
31
+ end
32
+
33
+ def response
34
+ @session.last_response
35
+ end
36
+
37
+ def request
38
+ @session.last_request
39
+ end
40
+
41
+ protected
42
+
43
+ def process_request(http_method, url, data = {}, headers = {})
44
+ headers ||= {}
45
+ data ||= {}
46
+
47
+ params = data.inject({}) { |acc, (k,v)|
48
+ acc.update(k => Rack::Utils.unescape(v))
49
+ }
50
+
51
+ env = headers.merge(:params => params, :method => http_method.to_s.upcase)
52
+ @session.request(url, env)
22
53
  end
23
54
  end
24
55
  end
@@ -2,9 +2,32 @@ require "webrat"
2
2
 
3
3
  require "action_controller"
4
4
  require "action_controller/integration"
5
+ require "action_controller/record_identifier"
5
6
 
6
7
  module Webrat
7
- class RailsSession < Session #:nodoc:
8
+ class RailsSession #:nodoc:
9
+ include ActionController::RecordIdentifier
10
+
11
+ attr_reader :integration_session
12
+
13
+ def initialize(session)
14
+ @integration_session = session
15
+ end
16
+
17
+ # The Rails version of within supports passing in a model and Webrat
18
+ # will apply a scope based on Rails' dom_id for that model.
19
+ #
20
+ # Example:
21
+ # within User.last do
22
+ # click_link "Delete"
23
+ # end
24
+ def within(selector_or_object, &block)
25
+ if selector_or_object.is_a?(String)
26
+ super
27
+ else
28
+ super('#' + dom_id(selector_or_object), &block)
29
+ end
30
+ end
8
31
 
9
32
  def doc_root
10
33
  File.expand_path(File.join(RAILS_ROOT, 'public'))
@@ -44,10 +67,6 @@ module Webrat
44
67
 
45
68
  protected
46
69
 
47
- def integration_session
48
- @context
49
- end
50
-
51
70
  def do_request(http_method, url, data, headers) #:nodoc:
52
71
  update_protocol(url)
53
72
  integration_session.send(http_method, normalize_url(url), data, headers)
@@ -56,11 +75,13 @@ module Webrat
56
75
  # remove protocol, host and anchor
57
76
  def normalize_url(href) #:nodoc:
58
77
  uri = URI.parse(href)
59
- normalized_url = uri.path
60
- if uri.query
61
- normalized_url += "?" + uri.query
62
- end
63
- normalized_url
78
+ normalized_url = []
79
+ normalized_url << "#{uri.scheme}://" if uri.scheme
80
+ normalized_url << uri.host if uri.host
81
+ normalized_url << ":#{uri.port}" if uri.port && ![80,443].include?(uri.port)
82
+ normalized_url << uri.path if uri.path
83
+ normalized_url << "?#{uri.query}" if uri.query
84
+ normalized_url.join
64
85
  end
65
86
 
66
87
  def update_protocol(href) #:nodoc:
@@ -74,7 +95,6 @@ module Webrat
74
95
  def response #:nodoc:
75
96
  integration_session.response
76
97
  end
77
-
78
98
  end
79
99
  end
80
100
 
@@ -1,6 +1,6 @@
1
1
  # Supports using the matchers in controller, helper, and view specs if you're
2
2
  # using rspec-rails. Just add a require statement to spec/spec_helper.rb or env.rb:
3
- #
3
+ #
4
4
  # require 'webrat/rspec-rails'
5
5
  #
6
6
  require "webrat/core/matchers"
@@ -10,4 +10,4 @@ Spec::Runner.configure do |config|
10
10
  config.include(Webrat::Matchers, :type => :controller)
11
11
  config.include(Webrat::Matchers, :type => :helper)
12
12
  config.include(Webrat::Matchers, :type => :view)
13
- end
13
+ end
@@ -1,45 +1,17 @@
1
1
  require "webrat"
2
- gem "selenium-client", ">=1.2.9"
2
+ gem "selenium-client", ">=1.2.14"
3
3
  require "selenium/client"
4
+ require "webrat/selenium/silence_stream"
4
5
  require "webrat/selenium/selenium_session"
5
6
  require "webrat/selenium/matchers"
7
+ require "webrat/core_extensions/tcp_socket"
6
8
 
7
9
  module Webrat
8
-
9
- def self.with_selenium_server #:nodoc:
10
- start_selenium_server
11
- yield
12
- stop_selenium_server
13
- end
14
-
15
- def self.start_selenium_server #:nodoc:
16
- remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
17
- remote_control.jar_file = File.expand_path(__FILE__ + "../../../../vendor/selenium-server.jar")
18
- remote_control.start :background => true
19
- TCPSocket.wait_for_service :host => "0.0.0.0", :port => 4444
20
- end
21
-
22
- def self.stop_selenium_server #:nodoc:
23
- remote_control = ::Selenium::RemoteControl::RemoteControl.new("0.0.0.0", 4444, 5)
24
- remote_control.stop
25
- end
26
-
27
- def self.start_app_server #:nodoc:
28
- pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
29
- system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.selenium_port} --environment=#{Webrat.configuration.selenium_environment} --pid #{pid_file} &")
30
- TCPSocket.wait_for_service :host => "0.0.0.0", :port => Webrat.configuration.selenium_port.to_i
31
- end
32
-
33
- def self.stop_app_server #:nodoc:
34
- pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
35
- system "mongrel_rails stop -c #{RAILS_ROOT} --pid #{pid_file}"
36
- end
37
-
38
10
  # To use Webrat's Selenium support, you'll need the selenium-client gem installed.
39
11
  # Activate it with (for example, in your <tt>env.rb</tt>):
40
12
  #
41
13
  # require "webrat"
42
- #
14
+ #
43
15
  # Webrat.configure do |config|
44
16
  # config.mode = :selenium
45
17
  # end
@@ -54,11 +26,25 @@ module Webrat
54
26
  # selenium.dragdrop("id=photo_123", "+350, 0")
55
27
  # end
56
28
  #
57
- # == Auto-starting of the mongrel and java server
29
+ # == Choosing the underlying framework to test
30
+ #
31
+ # Webrat assumes you're using rails by default but it can also work with sinatra
32
+ # and merb. To take advantage of this you can use the configuration block to
33
+ # set the application_framework variable.
34
+ # require "webrat"
35
+ #
36
+ # Webrat.configure do |config|
37
+ # config.mode = :selenium
38
+ # config.application_port = 4567
39
+ # config.application_framework = :sinatra # could also be :merb
40
+ # end
41
+ #
42
+ # == Auto-starting of the appserver and java server
58
43
  #
59
44
  # Webrat will automatically start the Selenium Java server process and an instance
60
45
  # of Mongrel when a test is run. The Mongrel will run in the "selenium" environment
61
- # instead of "test", so ensure you've got that defined, and will run on port 3001.
46
+ # instead of "test", so ensure you've got that defined, and will run on port
47
+ # Webrat.configuration.application_port.
62
48
  #
63
49
  # == Waiting
64
50
  #
@@ -84,10 +70,12 @@ module Webrat
84
70
  end
85
71
  end
86
72
 
87
- module ActionController #:nodoc:
88
- IntegrationTest.class_eval do
89
- include Webrat::Methods
90
- include Webrat::Selenium::Methods
91
- include Webrat::Selenium::Matchers
73
+ if defined?(ActionController::IntegrationTest)
74
+ module ActionController #:nodoc:
75
+ IntegrationTest.class_eval do
76
+ include Webrat::Methods
77
+ include Webrat::Selenium::Methods
78
+ include Webrat::Selenium::Matchers
79
+ end
92
80
  end
93
81
  end