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
@@ -4,7 +4,7 @@ module Webrat
4
4
  class SelectOption < Element #:nodoc:
5
5
 
6
6
  def self.xpath_search
7
- ".//option"
7
+ [".//option"]
8
8
  end
9
9
 
10
10
  def choose
@@ -28,7 +28,7 @@ module Webrat
28
28
  end
29
29
 
30
30
  def value
31
- Webrat::XML.attribute(@element, "value") || Webrat::XML.inner_html(@element)
31
+ @element["value"] || @element.inner_html
32
32
  end
33
33
 
34
34
  end
@@ -13,7 +13,7 @@ module Webrat
13
13
  module Locators
14
14
 
15
15
  def field_by_xpath(xpath)
16
- Field.load(@session, Webrat::XML.xpath_at(dom, xpath))
16
+ Field.load(@session, dom.xpath(xpath).first)
17
17
  end
18
18
 
19
19
  end
@@ -11,8 +11,8 @@ module Webrat
11
11
 
12
12
  def area_element
13
13
  area_elements.detect do |area_element|
14
- Webrat::XML.attribute(area_element, "title") =~ matcher ||
15
- Webrat::XML.attribute(area_element, "id") =~ matcher
14
+ area_element["title"] =~ matcher ||
15
+ area_element["id"] =~ matcher
16
16
  end
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ module Webrat
21
21
  end
22
22
 
23
23
  def area_elements
24
- Webrat::XML.xpath_search(@dom, Area.xpath_search)
24
+ @dom.xpath(*Area.xpath_search)
25
25
  end
26
26
 
27
27
  def error_message
@@ -20,24 +20,24 @@ module Webrat
20
20
  end
21
21
 
22
22
  def matches_id?(element)
23
- (@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
24
- (!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
23
+ (@value.is_a?(Regexp) && element["id"] =~ @value) ||
24
+ (!@value.is_a?(Regexp) && element["id"] == @value.to_s)
25
25
  end
26
26
 
27
27
  def matches_value?(element)
28
- Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
28
+ element["value"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
29
29
  end
30
30
 
31
31
  def matches_html?(element)
32
- Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
32
+ element.inner_html =~ /#{Regexp.escape(@value.to_s)}/i
33
33
  end
34
34
 
35
35
  def matches_alt?(element)
36
- Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
36
+ element["alt"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
37
37
  end
38
38
 
39
39
  def button_elements
40
- Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
40
+ @dom.xpath(*ButtonField.xpath_search)
41
41
  end
42
42
 
43
43
  def error_message
@@ -12,15 +12,15 @@ module Webrat
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
14
  if @value.is_a?(Regexp)
15
- Webrat::XML.attribute(field_element, "id") =~ @value
15
+ field_element["id"] =~ @value
16
16
  else
17
- Webrat::XML.attribute(field_element, "id") == @value.to_s
17
+ field_element["id"] == @value.to_s
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
22
  def field_elements
23
- Webrat::XML.xpath_search(@dom, *Field.xpath_search)
23
+ @dom.xpath(*Field.xpath_search)
24
24
  end
25
25
 
26
26
  def error_message
@@ -25,7 +25,7 @@ module Webrat
25
25
  end
26
26
 
27
27
  def label_elements
28
- Webrat::XML.xpath_search(@dom, Label.xpath_search)
28
+ @dom.xpath(*Label.xpath_search)
29
29
  end
30
30
 
31
31
  def error_message
@@ -33,7 +33,7 @@ module Webrat
33
33
  end
34
34
 
35
35
  def text(element)
36
- str = Webrat::XML.all_inner_text(element)
36
+ str = element.inner_text
37
37
  str.gsub!("\n","")
38
38
  str.strip!
39
39
  str.squeeze!(" ")
@@ -11,19 +11,19 @@ module Webrat
11
11
 
12
12
  def field_element
13
13
  field_elements.detect do |field_element|
14
- Webrat::XML.attribute(field_element, "name") == @value.to_s
14
+ field_element["name"] == @value.to_s
15
15
  end
16
16
  end
17
17
 
18
18
  def field_elements
19
- Webrat::XML.xpath_search(@dom, *xpath_searches)
19
+ @dom.xpath(*xpath_searches)
20
20
  end
21
21
 
22
22
  def xpath_searches
23
23
  if @field_types.any?
24
24
  @field_types.map { |field_type| field_type.xpath_search }.flatten
25
25
  else
26
- Array(Field.xpath_search)
26
+ Field.xpath_search
27
27
  end
28
28
  end
29
29
 
@@ -10,7 +10,7 @@ module Webrat
10
10
  end
11
11
 
12
12
  def form_element
13
- Webrat::XML.css_at(@dom, "#" + @value)
13
+ @dom.css("#" + @value).first
14
14
  end
15
15
 
16
16
  end
@@ -17,11 +17,11 @@ module Webrat
17
17
  end
18
18
 
19
19
  def label_elements
20
- Webrat::XML.xpath_search(@dom, Label.xpath_search)
20
+ @dom.xpath(*Label.xpath_search)
21
21
  end
22
22
 
23
23
  def text(label_element)
24
- str = Webrat::XML.all_inner_text(label_element)
24
+ str = label_element.inner_text
25
25
  str.gsub!("\n","")
26
26
  str.strip!
27
27
  str.squeeze!(" ")
@@ -10,7 +10,7 @@ module Webrat
10
10
  end
11
11
 
12
12
  def link_element
13
- matching_links.min { |a, b| Webrat::XML.all_inner_text(a).length <=> Webrat::XML.all_inner_text(b).length }
13
+ matching_links.min { |a, b| a.inner_text.length <=> b.inner_text.length }
14
14
  end
15
15
 
16
16
  def matching_links
@@ -28,33 +28,41 @@ module Webrat
28
28
  matcher = /#{Regexp.escape(@value.to_s)}/i
29
29
  end
30
30
 
31
- replace_nbsp(Webrat::XML.all_inner_text(link)) =~ matcher ||
32
- replace_nbsp_ref(Webrat::XML.inner_html(link)) =~ matcher ||
33
- Webrat::XML.attribute(link, "title")=~ matcher
31
+ replace_nbsp(link.inner_text) =~ matcher ||
32
+ replace_nbsp_ref(link.inner_html) =~ matcher ||
33
+ link["title"] =~ matcher
34
34
  end
35
35
 
36
36
  def matches_id?(link)
37
37
  if @value.is_a?(Regexp)
38
- (Webrat::XML.attribute(link, "id") =~ @value) ? true : false
38
+ link["id"] =~ @value ? true : false
39
39
  else
40
- (Webrat::XML.attribute(link, "id") == @value) ? true : false
40
+ link["id"] == @value ? true : false
41
41
  end
42
42
  end
43
-
43
+
44
44
  def matches_class?(link)
45
45
  if @value.is_a?(Regexp)
46
- (Webrat::XML.attribute(link, "class") =~ @value) ? true : false
46
+ link["class"] =~ @value ? true : false
47
47
  else
48
- Webrat::XML.attribute(link, "class").split(%r{\s}).include?(@value) unless Webrat::XML.attribute(link, "class").nil?
48
+ link["class"].split(%r{\s}).include?(@value) unless link["class"].nil?
49
49
  end
50
50
  end
51
-
51
+
52
52
  def link_elements
53
- Webrat::XML.xpath_search(@dom, *Link.xpath_search)
53
+ @dom.xpath(*Link.xpath_search)
54
54
  end
55
55
 
56
56
  def replace_nbsp(str)
57
- str.gsub([0xA0].pack('U'), ' ')
57
+ if str.respond_to?(:valid_encoding?)
58
+ if str.valid_encoding?
59
+ str.gsub(/\xc2\xa0/u, ' ')
60
+ else
61
+ str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
62
+ end
63
+ else
64
+ str.gsub(/\xc2\xa0/u, ' ')
65
+ end
58
66
  end
59
67
 
60
68
  def replace_nbsp_ref(str)
@@ -19,17 +19,17 @@ module Webrat
19
19
 
20
20
  field.options.detect do |o|
21
21
  if @option_text.is_a?(Regexp)
22
- Webrat::XML.inner_html(o.element) =~ @option_text
22
+ o.element.inner_html =~ @option_text
23
23
  else
24
- Webrat::XML.inner_html(o.element) == @option_text.to_s
24
+ o.element.inner_html == @option_text.to_s
25
25
  end
26
26
  end
27
27
  else
28
28
  option_element = option_elements.detect do |o|
29
29
  if @option_text.is_a?(Regexp)
30
- Webrat::XML.inner_html(o) =~ @option_text
30
+ o.inner_html =~ @option_text
31
31
  else
32
- Webrat::XML.inner_html(o) == @option_text.to_s
32
+ o.inner_html == @option_text.to_s
33
33
  end
34
34
  end
35
35
 
@@ -38,7 +38,7 @@ module Webrat
38
38
  end
39
39
 
40
40
  def option_elements
41
- Webrat::XML.xpath_search(@dom, *SelectOption.xpath_search)
41
+ @dom.xpath(*SelectOption.xpath_search)
42
42
  end
43
43
 
44
44
  def error_message
@@ -11,7 +11,7 @@ module Webrat
11
11
  when :rails
12
12
  defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : nil
13
13
  when :merb
14
- Merb.logger
14
+ ::Merb.logger
15
15
  else
16
16
  @logger ||= begin
17
17
  require "logger"
@@ -7,13 +7,8 @@ module Webrat
7
7
  end
8
8
 
9
9
  def matches?(stringlike)
10
- if Webrat.configuration.parse_with_nokogiri?
11
- @document = Webrat.nokogiri_document(stringlike)
12
- else
13
- @document = Webrat.hpricot_document(stringlike)
14
- end
15
-
16
- @element = Webrat::XML.inner_text(@document)
10
+ @document = Webrat::XML.document(stringlike)
11
+ @element = @document.inner_text
17
12
 
18
13
  case @content
19
14
  when String
@@ -1,5 +1,4 @@
1
- require "webrat/core/xml/nokogiri"
2
- require "webrat/core/xml/rexml"
1
+ require "webrat/core/xml"
3
2
 
4
3
  module Webrat
5
4
  module Matchers
@@ -23,31 +22,7 @@ module Webrat
23
22
  end
24
23
 
25
24
  def matches(stringlike)
26
- if Webrat.configuration.parse_with_nokogiri?
27
- nokogiri_matches(stringlike)
28
- else
29
- rexml_matches(stringlike)
30
- end
31
- end
32
-
33
- def rexml_matches(stringlike)
34
- if REXML::Node === stringlike || Array === stringlike
35
- @query = query.map { |q| q.gsub(%r'^//', './/') }
36
- else
37
- @query = query
38
- end
39
-
40
- add_options_conditions_to(@query)
41
-
42
- @document = Webrat.rexml_document(stringlike)
43
-
44
- @query.map do |q|
45
- if @document.is_a?(Array)
46
- @document.map { |d| REXML::XPath.match(d, q) }
47
- else
48
- REXML::XPath.match(@document, q)
49
- end
50
- end.flatten.compact
25
+ nokogiri_matches(stringlike)
51
26
  end
52
27
 
53
28
  def nokogiri_matches(stringlike)
@@ -16,10 +16,10 @@ module Webrat
16
16
  end
17
17
 
18
18
  def webrat_session
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)
19
+ @_webrat_session ||= begin
20
+ session = Webrat.session_class.new
21
+ session.adapter = Webrat.adapter_class.new(self) if session.respond_to?(:adapter=)
22
+ session
23
23
  end
24
24
  end
25
25
 
@@ -1,29 +1,18 @@
1
1
  module Webrat #:nodoc:
2
2
  module MIME #:nodoc:
3
+ MIME_TYPES = Rack::Mime::MIME_TYPES.dup.merge(
4
+ ".multipart_form" => "multipart/form-data",
5
+ ".url_encoded_form" => "application/x-www-form-urlencoded"
6
+ ).freeze
3
7
 
4
- def self.mime_type(string_or_symbol) #:nodoc:
5
- if string_or_symbol.is_a?(String)
6
- string_or_symbol
7
- else
8
- case string_or_symbol
9
- when :text then "text/plain"
10
- when :html then "text/html"
11
- when :js then "text/javascript"
12
- when :css then "text/css"
13
- when :ics then "text/calendar"
14
- when :csv then "text/csv"
15
- when :xml then "application/xml"
16
- when :rss then "application/rss+xml"
17
- when :atom then "application/atom+xml"
18
- when :yaml then "application/x-yaml"
19
- when :multipart_form then "multipart/form-data"
20
- when :url_encoded_form then "application/x-www-form-urlencoded"
21
- when :json then "application/json"
22
- else
23
- raise ArgumentError.new("Invalid Mime type: #{string_or_symbol.inspect}")
24
- end
25
- end
8
+ def mime_type(type)
9
+ return type if type.nil? || type.to_s.include?("/")
10
+ type = ".#{type}" unless type.to_s[0] == ?.
11
+ MIME_TYPES.fetch(type) { |type|
12
+ raise ArgumentError.new("Invalid Mime type: #{type}")
13
+ }
26
14
  end
27
15
 
16
+ module_function :mime_type
28
17
  end
29
18
  end
@@ -18,17 +18,15 @@ module Webrat
18
18
  end
19
19
 
20
20
  def open_in_browser(path) # :nodoc
21
- platform = ruby_platform
22
- if platform =~ /cygwin/ || platform =~ /win32/
23
- `rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
24
- elsif platform =~ /darwin/
25
- `open #{path}`
26
- end
21
+ require "launchy"
22
+ Launchy::Browser.run(path)
23
+ rescue LoadError
24
+ warn "Sorry, you need to install launchy to open pages: `gem install launchy`"
27
25
  end
28
26
 
29
27
  def rewrite_css_and_image_references(response_html) # :nodoc:
30
28
  return response_html unless doc_root
31
- response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
29
+ response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + doc_root + '/\2')
32
30
  end
33
31
 
34
32
  def saved_page_dir #:nodoc:
@@ -312,12 +312,12 @@ module Webrat
312
312
  dom = Webrat::XML.html_document(@response_body)
313
313
  end
314
314
 
315
- Webrat.define_dom_method(@response, dom)
315
+ Webrat::XML.define_dom_method(@response, dom)
316
316
  return dom
317
317
  end
318
318
 
319
319
  def scoped_dom
320
- Webrat::XML.css_at(@scope.dom, @selector)
320
+ @scope.dom.css(@selector).first
321
321
  end
322
322
 
323
323
  def locate_field(field_locator, *field_types) #:nodoc:
@@ -13,21 +13,30 @@ module Webrat
13
13
  end
14
14
 
15
15
  def self.session_class
16
+ if Webrat.configuration.mode == :selenium
17
+ SeleniumSession
18
+ else
19
+ Session
20
+ end
21
+ end
22
+
23
+ def self.adapter_class
16
24
  case Webrat.configuration.mode
17
25
  when :rails
18
- RailsSession
26
+ RailsAdapter
19
27
  when :merb
20
- MerbSession
21
- when :selenium
22
- SeleniumSession
28
+ MerbAdapter
23
29
  when :rack
24
- RackSession
30
+ RackAdapter
31
+ when :rack_test
32
+ warn("The :rack_test mode is deprecated. Please use :rack instead")
33
+ require "webrat/rack"
34
+ RackAdapter
25
35
  when :sinatra
26
- SinatraSession
36
+ warn("The :sinatra mode is deprecated. Please use :rack instead")
37
+ SinatraAdapter
27
38
  when :mechanize
28
- MechanizeSession
29
- when :rack_test
30
- RackTestSession
39
+ MechanizeAdapter
31
40
  else
32
41
  raise WebratError.new(<<-STR)
33
42
  Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
@@ -50,16 +59,22 @@ For example:
50
59
  extend Forwardable
51
60
  include Logging
52
61
  include SaveAndOpenPage
62
+
63
+ attr_accessor :adapter
64
+
53
65
  attr_reader :current_url
54
66
  attr_reader :elements
55
67
 
56
- def initialize(context = nil) #:nodoc:
68
+ def_delegators :@adapter, :response, :response_code, :response_body,
69
+ :response_body=, :response_code=,
70
+ :get, :post, :put, :delete
71
+
72
+ def initialize(adapter = nil)
73
+ @adapter = adapter
57
74
  @http_method = :get
58
75
  @data = {}
59
76
  @default_headers = {}
60
77
  @custom_headers = {}
61
- @context = context
62
-
63
78
  reset
64
79
  end
65
80
 
@@ -69,6 +84,7 @@ For example:
69
84
 
70
85
  # For backwards compatibility -- removing in 1.0
71
86
  def current_page #:nodoc:
87
+ warn "current_page is deprecated and will be going away in the next release. Use current_url instead."
72
88
  page = OpenStruct.new
73
89
  page.url = @current_url
74
90
  page.http_method = @http_method
@@ -143,7 +159,7 @@ For example:
143
159
  end
144
160
 
145
161
  def redirect? #:nodoc:
146
- response_code / 100 == 3
162
+ (response_code / 100).to_i == 3
147
163
  end
148
164
 
149
165
  def internal_redirect?
@@ -272,7 +288,7 @@ For example:
272
288
  end
273
289
 
274
290
  def current_host
275
- URI.parse(current_url).host || "www.example.com"
291
+ URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
276
292
  end
277
293
 
278
294
  def response_location_host