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.
- data/.document +4 -0
- data/.gitignore +15 -0
- data/History.txt +60 -9
- data/Rakefile +90 -75
- data/VERSION +1 -0
- data/lib/webrat.rb +8 -23
- data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +6 -2
- data/lib/webrat/adapters/merb.rb +11 -0
- data/lib/webrat/adapters/rack.rb +25 -0
- data/lib/webrat/{rails.rb → adapters/rails.rb} +9 -18
- data/lib/webrat/adapters/sinatra.rb +9 -0
- data/lib/webrat/core.rb +0 -1
- data/lib/webrat/core/configuration.rb +7 -17
- data/lib/webrat/core/elements/area.rb +2 -2
- data/lib/webrat/core/elements/element.rb +3 -3
- data/lib/webrat/core/elements/field.rb +33 -30
- data/lib/webrat/core/elements/form.rb +4 -4
- data/lib/webrat/core/elements/label.rb +4 -4
- data/lib/webrat/core/elements/link.rb +7 -6
- data/lib/webrat/core/elements/select_option.rb +2 -2
- data/lib/webrat/core/locators.rb +1 -1
- data/lib/webrat/core/locators/area_locator.rb +3 -3
- data/lib/webrat/core/locators/button_locator.rb +6 -6
- data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
- data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
- data/lib/webrat/core/locators/field_named_locator.rb +3 -3
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +2 -2
- data/lib/webrat/core/locators/link_locator.rb +20 -12
- data/lib/webrat/core/locators/select_option_locator.rb +5 -5
- data/lib/webrat/core/logging.rb +1 -1
- data/lib/webrat/core/matchers/have_content.rb +2 -7
- data/lib/webrat/core/matchers/have_xpath.rb +2 -27
- data/lib/webrat/core/methods.rb +4 -4
- data/lib/webrat/core/mime.rb +11 -22
- data/lib/webrat/core/save_and_open_page.rb +5 -7
- data/lib/webrat/core/scope.rb +2 -2
- data/lib/webrat/core/session.rb +30 -14
- data/lib/webrat/core/xml.rb +41 -84
- data/lib/webrat/integrations/merb.rb +10 -0
- data/lib/webrat/integrations/rails.rb +9 -0
- data/lib/webrat/integrations/rspec-rails.rb +10 -0
- data/lib/webrat/integrations/selenium.rb +11 -0
- data/lib/webrat/rspec-rails.rb +2 -13
- data/lib/webrat/selenium.rb +0 -11
- data/lib/webrat/selenium/application_server_factory.rb +40 -0
- data/lib/webrat/selenium/application_servers.rb +5 -0
- data/lib/webrat/selenium/application_servers/base.rb +46 -0
- data/lib/webrat/selenium/application_servers/external.rb +26 -0
- data/lib/webrat/selenium/application_servers/merb.rb +50 -0
- data/lib/webrat/selenium/application_servers/rails.rb +44 -0
- data/lib/webrat/selenium/application_servers/sinatra.rb +37 -0
- data/lib/webrat/selenium/location_strategy_javascript/label.js +2 -1
- data/lib/webrat/selenium/selenium_rc_server.rb +7 -5
- data/lib/webrat/selenium/selenium_session.rb +20 -7
- data/lib/webrat/selenium/silence_stream.rb +1 -1
- data/spec/fakes/{test_session.rb → test_adapter.rb} +6 -3
- data/spec/integration/mechanize/Rakefile +7 -0
- data/spec/integration/mechanize/config.ru +2 -0
- data/spec/integration/mechanize/sample_app.rb +20 -0
- data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
- data/spec/integration/mechanize/spec/spec_helper.rb +27 -0
- data/spec/integration/merb/.gitignore +21 -0
- data/spec/integration/merb/Rakefile +35 -0
- data/spec/integration/merb/app/controllers/testing.rb +9 -0
- data/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
- data/spec/integration/merb/app/views/layout/application.html.erb +12 -0
- data/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
- data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
- data/spec/integration/merb/config/router.rb +1 -0
- data/spec/integration/merb/spec/spec.opts +1 -0
- data/spec/integration/merb/spec/spec_helper.rb +2 -0
- data/spec/integration/merb/spec/webrat_spec.rb +7 -0
- data/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
- data/spec/integration/rack/Rakefile +5 -0
- data/spec/integration/rack/app.rb +89 -0
- data/spec/integration/rack/test/helper.rb +21 -0
- data/spec/integration/rack/test/webrat_rack_test.rb +57 -51
- data/spec/integration/rails/.gitignore +3 -0
- data/spec/integration/rails/Rakefile +30 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +13 -9
- data/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
- data/spec/integration/rails/app/views/fields/show.html.erb +9 -0
- data/spec/integration/rails/app/views/links/show.html.erb +5 -0
- data/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
- data/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
- data/spec/integration/rails/config/locales/en.yml +5 -0
- data/spec/integration/rails/config/routes.rb +1 -0
- data/spec/integration/rails/public/404.html +30 -0
- data/spec/integration/rails/public/422.html +30 -0
- data/spec/integration/rails/public/500.html +33 -0
- data/spec/integration/rails/script/about +4 -0
- data/spec/integration/rails/script/console +3 -0
- data/spec/integration/rails/script/dbconsole +3 -0
- data/spec/integration/rails/script/destroy +3 -0
- data/spec/integration/rails/script/generate +3 -0
- data/spec/integration/rails/script/performance/benchmarker +3 -0
- data/spec/integration/rails/script/performance/profiler +3 -0
- data/spec/integration/rails/script/performance/request +3 -0
- data/spec/integration/rails/script/plugin +3 -0
- data/spec/integration/rails/script/process/inspector +3 -0
- data/spec/integration/rails/script/process/reaper +3 -0
- data/spec/integration/rails/script/process/spawner +3 -0
- data/spec/integration/rails/script/runner +3 -0
- data/spec/integration/rails/script/server +3 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +2 -2
- data/spec/integration/rails/test/integration/link_click_test.rb +7 -1
- data/spec/integration/rails/test/integration/webrat_test.rb +22 -0
- data/spec/integration/rails/test/test_helper.rb +6 -5
- data/spec/integration/sinatra/Rakefile +5 -0
- data/spec/integration/sinatra/test/test_helper.rb +3 -2
- data/spec/private/core/configuration_spec.rb +8 -27
- data/spec/private/core/field_spec.rb +7 -7
- data/spec/private/core/link_spec.rb +1 -1
- data/spec/private/core/session_spec.rb +23 -21
- data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -12
- data/spec/private/nokogiri_spec.rb +2 -2
- data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +16 -16
- data/spec/private/selenium/application_servers/rails_spec.rb +26 -0
- data/spec/public/matchers/contain_spec.rb +4 -4
- data/spec/public/matchers/have_selector_spec.rb +2 -2
- data/spec/public/matchers/have_xpath_spec.rb +3 -3
- data/spec/public/save_and_open_spec.rb +25 -6
- data/spec/public/selenium/application_server_factory_spec.rb +49 -0
- data/spec/public/selenium/application_servers/external_spec.rb +12 -0
- data/spec/public/selenium/selenium_session_spec.rb +37 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +5 -1
- data/vendor/selenium-server.jar +0 -0
- data/webrat.gemspec +348 -0
- metadata +176 -23
- data/lib/webrat/core/xml/hpricot.rb +0 -19
- data/lib/webrat/core/xml/nokogiri.rb +0 -76
- data/lib/webrat/core/xml/rexml.rb +0 -24
- data/lib/webrat/merb_session.rb +0 -65
- data/lib/webrat/rack.rb +0 -24
- data/lib/webrat/rack_test.rb +0 -32
- data/lib/webrat/selenium/application_server.rb +0 -73
- data/lib/webrat/selenium/merb_application_server.rb +0 -48
- data/lib/webrat/selenium/rails_application_server.rb +0 -42
- data/lib/webrat/selenium/sinatra_application_server.rb +0 -35
- data/lib/webrat/sinatra.rb +0 -44
- data/spec/integration/rack/rack_app.rb +0 -16
- data/spec/integration/rack/test/test_helper.rb +0 -20
- 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
|
-
|
|
31
|
+
@element["value"] || @element.inner_html
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
end
|
data/lib/webrat/core/locators.rb
CHANGED
|
@@ -11,8 +11,8 @@ module Webrat
|
|
|
11
11
|
|
|
12
12
|
def area_element
|
|
13
13
|
area_elements.detect do |area_element|
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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) &&
|
|
24
|
-
(!@value.is_a?(Regexp) &&
|
|
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
|
-
|
|
28
|
+
element["value"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def matches_html?(element)
|
|
32
|
-
|
|
32
|
+
element.inner_html =~ /#{Regexp.escape(@value.to_s)}/i
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def matches_alt?(element)
|
|
36
|
-
|
|
36
|
+
element["alt"] =~ /^\W*#{Regexp.escape(@value.to_s)}/i
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def button_elements
|
|
40
|
-
|
|
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
|
-
|
|
15
|
+
field_element["id"] =~ @value
|
|
16
16
|
else
|
|
17
|
-
|
|
17
|
+
field_element["id"] == @value.to_s
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def field_elements
|
|
23
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
14
|
+
field_element["name"] == @value.to_s
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def field_elements
|
|
19
|
-
|
|
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
|
-
|
|
26
|
+
Field.xpath_search
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -17,11 +17,11 @@ module Webrat
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def label_elements
|
|
20
|
-
|
|
20
|
+
@dom.xpath(*Label.xpath_search)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def text(label_element)
|
|
24
|
-
str =
|
|
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|
|
|
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(
|
|
32
|
-
replace_nbsp_ref(
|
|
33
|
-
|
|
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
|
-
|
|
38
|
+
link["id"] =~ @value ? true : false
|
|
39
39
|
else
|
|
40
|
-
|
|
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
|
-
|
|
46
|
+
link["class"] =~ @value ? true : false
|
|
47
47
|
else
|
|
48
|
-
|
|
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
|
-
|
|
53
|
+
@dom.xpath(*Link.xpath_search)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def replace_nbsp(str)
|
|
57
|
-
str.
|
|
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
|
-
|
|
22
|
+
o.element.inner_html =~ @option_text
|
|
23
23
|
else
|
|
24
|
-
|
|
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
|
-
|
|
30
|
+
o.inner_html =~ @option_text
|
|
31
31
|
else
|
|
32
|
-
|
|
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
|
-
|
|
41
|
+
@dom.xpath(*SelectOption.xpath_search)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def error_message
|
data/lib/webrat/core/logging.rb
CHANGED
|
@@ -7,13 +7,8 @@ module Webrat
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def matches?(stringlike)
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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
|
-
|
|
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)
|
data/lib/webrat/core/methods.rb
CHANGED
|
@@ -16,10 +16,10 @@ module Webrat
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def webrat_session
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
data/lib/webrat/core/mime.rb
CHANGED
|
@@ -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
|
|
5
|
-
if
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 + '/\
|
|
29
|
+
response_html.gsub(/("|')\/(stylesheets|images)/, '\1' + doc_root + '/\2')
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def saved_page_dir #:nodoc:
|
data/lib/webrat/core/scope.rb
CHANGED
|
@@ -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
|
-
|
|
320
|
+
@scope.dom.css(@selector).first
|
|
321
321
|
end
|
|
322
322
|
|
|
323
323
|
def locate_field(field_locator, *field_types) #:nodoc:
|
data/lib/webrat/core/session.rb
CHANGED
|
@@ -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
|
-
|
|
26
|
+
RailsAdapter
|
|
19
27
|
when :merb
|
|
20
|
-
|
|
21
|
-
when :selenium
|
|
22
|
-
SeleniumSession
|
|
28
|
+
MerbAdapter
|
|
23
29
|
when :rack
|
|
24
|
-
|
|
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
|
-
|
|
36
|
+
warn("The :sinatra mode is deprecated. Please use :rack instead")
|
|
37
|
+
SinatraAdapter
|
|
27
38
|
when :mechanize
|
|
28
|
-
|
|
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
|
-
|
|
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
|