diabolo-webrat 0.4.2 → 0.4.3
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/History.txt +22 -3
- data/Rakefile +6 -1
- data/lib/webrat/core/configuration.rb +4 -4
- data/lib/webrat/core/elements/area.rb +7 -7
- data/lib/webrat/core/elements/element.rb +11 -11
- data/lib/webrat/core/elements/field.rb +50 -50
- data/lib/webrat/core/elements/form.rb +17 -17
- data/lib/webrat/core/elements/label.rb +6 -6
- data/lib/webrat/core/elements/link.rb +13 -11
- data/lib/webrat/core/elements/select_option.rb +9 -9
- data/lib/webrat/core/locators/area_locator.rb +10 -10
- data/lib/webrat/core/locators/button_locator.rb +13 -13
- data/lib/webrat/core/locators/field_by_id_locator.rb +8 -8
- data/lib/webrat/core/locators/field_labeled_locator.rb +10 -10
- data/lib/webrat/core/locators/field_locator.rb +7 -7
- data/lib/webrat/core/locators/field_named_locator.rb +10 -10
- data/lib/webrat/core/locators/form_locator.rb +6 -6
- data/lib/webrat/core/locators/label_locator.rb +8 -8
- data/lib/webrat/core/locators/link_locator.rb +11 -12
- data/lib/webrat/core/locators/locator.rb +5 -5
- data/lib/webrat/core/locators/select_option_locator.rb +11 -11
- data/lib/webrat/core/locators.rb +2 -2
- data/lib/webrat/core/logging.rb +3 -3
- data/lib/webrat/core/matchers/have_content.rb +12 -12
- data/lib/webrat/core/matchers/have_selector.rb +9 -9
- data/lib/webrat/core/matchers/have_tag.rb +4 -4
- data/lib/webrat/core/matchers/have_xpath.rb +24 -24
- data/lib/webrat/core/methods.rb +9 -9
- data/lib/webrat/core/mime.rb +3 -3
- data/lib/webrat/core/save_and_open_page.rb +9 -9
- data/lib/webrat/core/scope.rb +51 -51
- data/lib/webrat/core/session.rb +7 -7
- data/lib/webrat/core/xml/hpricot.rb +3 -3
- data/lib/webrat/core/xml/nokogiri.rb +11 -11
- data/lib/webrat/core/xml/rexml.rb +3 -3
- data/lib/webrat/core/xml.rb +16 -16
- data/lib/webrat/core_extensions/blank.rb +1 -1
- data/lib/webrat/core_extensions/deprecate.rb +1 -1
- data/lib/webrat/core_extensions/detect_mapped.rb +4 -4
- data/lib/webrat/core_extensions/meta_class.rb +1 -1
- data/lib/webrat/mechanize.rb +9 -9
- data/lib/webrat/merb.rb +1 -1
- data/lib/webrat/merb_session.rb +10 -10
- data/lib/webrat/rails.rb +2 -2
- data/lib/webrat/rspec-rails.rb +2 -2
- data/lib/webrat/selenium/matchers/have_content.rb +4 -4
- data/lib/webrat/selenium/matchers/have_selector.rb +4 -4
- data/lib/webrat/selenium/matchers/have_tag.rb +16 -16
- data/lib/webrat/selenium/matchers/have_xpath.rb +4 -4
- data/lib/webrat/selenium/matchers.rb +1 -1
- data/lib/webrat/selenium/selenium_session.rb +12 -18
- data/lib/webrat/selenium.rb +3 -77
- data/lib/webrat.rb +4 -4
- metadata +1 -1
data/lib/webrat/core/session.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Webrat
|
|
|
11
11
|
|
|
12
12
|
class InfiniteRedirectError < WebratError
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
def self.session_class
|
|
16
16
|
case Webrat.configuration.mode
|
|
17
17
|
when :rails
|
|
@@ -77,7 +77,7 @@ For example:
|
|
|
77
77
|
def doc_root #:nodoc:
|
|
78
78
|
nil
|
|
79
79
|
end
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
def header(key, value)
|
|
82
82
|
@custom_headers[key] = value
|
|
83
83
|
end
|
|
@@ -122,13 +122,13 @@ For example:
|
|
|
122
122
|
|
|
123
123
|
return response
|
|
124
124
|
end
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
def check_for_infinite_redirects
|
|
127
127
|
if current_url == response_location
|
|
128
128
|
@_identical_redirect_count ||= 0
|
|
129
129
|
@_identical_redirect_count += 1
|
|
130
130
|
end
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
if infinite_redirect_limit_exceeded?
|
|
133
133
|
raise InfiniteRedirectError.new("#{Webrat.configuration.infinite_redirect_limit} redirects to the same URL (#{current_url.inspect})")
|
|
134
134
|
end
|
|
@@ -138,7 +138,7 @@ For example:
|
|
|
138
138
|
Webrat.configuration.infinite_redirect_limit &&
|
|
139
139
|
(@_identical_redirect_count || 0) > Webrat.configuration.infinite_redirect_limit
|
|
140
140
|
end
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
def success_code? #:nodoc:
|
|
143
143
|
(200..499).include?(response_code)
|
|
144
144
|
end
|
|
@@ -154,7 +154,7 @@ For example:
|
|
|
154
154
|
response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host
|
|
155
155
|
current_host_domain == response_location_host_domain
|
|
156
156
|
end
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
#easy helper to pull out where we were redirected to
|
|
159
159
|
def redirected_to
|
|
160
160
|
redirect? ? response_location : nil
|
|
@@ -276,6 +276,6 @@ For example:
|
|
|
276
276
|
@_scopes = nil
|
|
277
277
|
@_page_scope = nil
|
|
278
278
|
end
|
|
279
|
-
|
|
279
|
+
|
|
280
280
|
end
|
|
281
281
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require "webrat/core_extensions/meta_class"
|
|
2
2
|
|
|
3
3
|
module Webrat
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
def self.nokogiri_document(stringlike) #:nodoc:
|
|
6
6
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
if Nokogiri::HTML::Document === stringlike
|
|
9
9
|
stringlike
|
|
10
10
|
elsif Nokogiri::XML::NodeSet === stringlike
|
|
@@ -17,10 +17,10 @@ module Webrat
|
|
|
17
17
|
Nokogiri::HTML(stringlike.to_s)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
def self.html_nokogiri_document(stringlike) #:nodoc:
|
|
22
22
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
if Nokogiri::HTML::Document === stringlike
|
|
25
25
|
stringlike
|
|
26
26
|
elsif Nokogiri::XML::NodeSet === stringlike
|
|
@@ -33,10 +33,10 @@ module Webrat
|
|
|
33
33
|
Nokogiri::HTML(stringlike.to_s)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
def self.xml_nokogiri_document(stringlike) #:nodoc:
|
|
38
38
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
if Nokogiri::HTML::Document === stringlike
|
|
41
41
|
stringlike
|
|
42
42
|
elsif Nokogiri::XML::NodeSet === stringlike
|
|
@@ -49,20 +49,20 @@ module Webrat
|
|
|
49
49
|
Nokogiri::XML(stringlike.to_s)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
def self.define_dom_method(object, dom) #:nodoc:
|
|
54
54
|
object.meta_class.send(:define_method, :dom) do
|
|
55
55
|
dom
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
module Nokogiri #:nodoc:
|
|
63
63
|
module CSS #:nodoc:
|
|
64
64
|
class XPathVisitor #:nodoc:
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
def visit_pseudo_class_text(node) #:nodoc:
|
|
67
67
|
"@type='text'"
|
|
68
68
|
end
|
|
@@ -70,7 +70,7 @@ module Nokogiri #:nodoc:
|
|
|
70
70
|
def visit_pseudo_class_password(node) #:nodoc:
|
|
71
71
|
"@type='password'"
|
|
72
72
|
end
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
-
end
|
|
76
|
+
end
|
data/lib/webrat/core/xml.rb
CHANGED
|
@@ -4,7 +4,7 @@ require "webrat/core/xml/rexml"
|
|
|
4
4
|
|
|
5
5
|
module Webrat #:nodoc:
|
|
6
6
|
module XML #:nodoc:
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
def self.document(stringlike) #:nodoc:
|
|
9
9
|
if Webrat.configuration.parse_with_nokogiri?
|
|
10
10
|
Webrat.nokogiri_document(stringlike)
|
|
@@ -12,7 +12,7 @@ module Webrat #:nodoc:
|
|
|
12
12
|
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def self.html_document(stringlike) #:nodoc:
|
|
17
17
|
if Webrat.configuration.parse_with_nokogiri?
|
|
18
18
|
Webrat.html_nokogiri_document(stringlike)
|
|
@@ -20,7 +20,7 @@ module Webrat #:nodoc:
|
|
|
20
20
|
Webrat.rexml_document(Webrat.hpricot_document(stringlike).to_html)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def self.xml_document(stringlike) #:nodoc:
|
|
25
25
|
if Webrat.configuration.parse_with_nokogiri?
|
|
26
26
|
Webrat.xml_nokogiri_document(stringlike)
|
|
@@ -36,7 +36,7 @@ module Webrat #:nodoc:
|
|
|
36
36
|
element.to_s
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
def self.inner_html(element)
|
|
41
41
|
if Webrat.configuration.parse_with_nokogiri?
|
|
42
42
|
element.inner_html
|
|
@@ -44,7 +44,7 @@ module Webrat #:nodoc:
|
|
|
44
44
|
element.text
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
def self.all_inner_text(element)
|
|
49
49
|
if Webrat.configuration.parse_with_nokogiri?
|
|
50
50
|
element.inner_text
|
|
@@ -52,7 +52,7 @@ module Webrat #:nodoc:
|
|
|
52
52
|
Hpricot(element.to_s).children.first.inner_text
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
def self.inner_text(element)
|
|
57
57
|
if Webrat.configuration.parse_with_nokogiri?
|
|
58
58
|
element.inner_text
|
|
@@ -64,7 +64,7 @@ module Webrat #:nodoc:
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
|
-
|
|
67
|
+
|
|
68
68
|
def self.xpath_to(element)
|
|
69
69
|
if Webrat.configuration.parse_with_nokogiri?
|
|
70
70
|
element.path
|
|
@@ -72,25 +72,25 @@ module Webrat #:nodoc:
|
|
|
72
72
|
element.xpath
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
def self.attribute(element, attribute_name)
|
|
77
77
|
return element[attribute_name] if element.is_a?(Hash)
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
if Webrat.configuration.parse_with_nokogiri?
|
|
80
80
|
element[attribute_name]
|
|
81
81
|
else
|
|
82
82
|
element.attributes[attribute_name]
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
def self.xpath_at(*args)
|
|
87
87
|
xpath_search(*args).first
|
|
88
88
|
end
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
def self.css_at(*args)
|
|
91
91
|
css_search(*args).first
|
|
92
92
|
end
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
def self.xpath_search(element, *searches)
|
|
95
95
|
searches.flatten.map do |search|
|
|
96
96
|
if Webrat.configuration.parse_with_nokogiri?
|
|
@@ -100,16 +100,16 @@ module Webrat #:nodoc:
|
|
|
100
100
|
end
|
|
101
101
|
end.flatten.compact
|
|
102
102
|
end
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
def self.css_search(element, *searches) #:nodoc:
|
|
105
105
|
xpath_search(element, css_to_xpath(*searches))
|
|
106
106
|
end
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
def self.css_to_xpath(*selectors)
|
|
109
109
|
selectors.map do |rule|
|
|
110
110
|
Nokogiri::CSS.xpath_for(rule, :prefix => ".//")
|
|
111
111
|
end.flatten.uniq
|
|
112
112
|
end
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
end
|
|
115
|
-
end
|
|
115
|
+
end
|
data/lib/webrat/mechanize.rb
CHANGED
|
@@ -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
|
|
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?
|
data/lib/webrat/merb.rb
CHANGED
data/lib/webrat/merb_session.rb
CHANGED
|
@@ -10,36 +10,36 @@ require "merb-core"
|
|
|
10
10
|
module Webrat
|
|
11
11
|
class MerbSession < Session #:nodoc:
|
|
12
12
|
include Merb::Test::MakeRequest
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
attr_accessor :response
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
def get(url, data, headers = nil)
|
|
17
17
|
do_request(url, data, headers, "GET")
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
def post(url, data, headers = nil)
|
|
21
21
|
do_request(url, data, headers, "POST")
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
def put(url, data, headers = nil)
|
|
25
25
|
do_request(url, data, headers, "PUT")
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
def delete(url, data, headers = nil)
|
|
29
29
|
do_request(url, data, headers, "DELETE")
|
|
30
30
|
end
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
def response_body
|
|
33
33
|
@response.body.to_s
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
def response_code
|
|
37
37
|
@response.status
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
def do_request(url, data, headers, method)
|
|
41
|
-
@response = request(url,
|
|
42
|
-
:params => (data && data.any?) ? data : nil,
|
|
41
|
+
@response = request(url,
|
|
42
|
+
:params => (data && data.any?) ? data : nil,
|
|
43
43
|
:headers => headers,
|
|
44
44
|
:method => method)
|
|
45
45
|
end
|
data/lib/webrat/rails.rb
CHANGED
|
@@ -7,7 +7,7 @@ require "action_controller/record_identifier"
|
|
|
7
7
|
module Webrat
|
|
8
8
|
class RailsSession < Session #:nodoc:
|
|
9
9
|
include ActionController::RecordIdentifier
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
# The Rails version of within supports passing in a model and Webrat
|
|
12
12
|
# will apply a scope based on Rails' dom_id for that model.
|
|
13
13
|
#
|
|
@@ -22,7 +22,7 @@ module Webrat
|
|
|
22
22
|
super('#' + dom_id(selector_or_object), &block)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def doc_root
|
|
27
27
|
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
|
28
28
|
end
|
data/lib/webrat/rspec-rails.rb
CHANGED
|
@@ -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
|
|
@@ -5,14 +5,14 @@ module Webrat
|
|
|
5
5
|
def initialize(content)
|
|
6
6
|
@content = content
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
def matches?(response)
|
|
10
10
|
if @content.is_a?(Regexp)
|
|
11
11
|
text_finder = "regexp:#{@content.source}"
|
|
12
12
|
else
|
|
13
13
|
text_finder = @content
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
response.session.wait_for do
|
|
17
17
|
response.selenium.is_text_present(text_finder)
|
|
18
18
|
end
|
|
@@ -47,7 +47,7 @@ module Webrat
|
|
|
47
47
|
def contain(content)
|
|
48
48
|
HasContent.new(content)
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
# Asserts that the body of the response contain
|
|
52
52
|
# the supplied string or regexp
|
|
53
53
|
def assert_contain(content)
|
|
@@ -63,4 +63,4 @@ module Webrat
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
|
-
end
|
|
66
|
+
end
|
|
@@ -5,7 +5,7 @@ module Webrat
|
|
|
5
5
|
def initialize(expected)
|
|
6
6
|
@expected = expected
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
def matches?(response)
|
|
10
10
|
response.session.wait_for do
|
|
11
11
|
response.selenium.is_element_present("css=#{@expected}")
|
|
@@ -26,11 +26,11 @@ module Webrat
|
|
|
26
26
|
"expected following text to not match selector #{@expected}:\n#{@document}"
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
def have_selector(content)
|
|
31
31
|
HaveSelector.new(content)
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
# Asserts that the body of the response contains
|
|
35
35
|
# the supplied selector
|
|
36
36
|
def assert_have_selector(expected)
|
|
@@ -46,4 +46,4 @@ module Webrat
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
-
end
|
|
49
|
+
end
|
|
@@ -1,72 +1,72 @@
|
|
|
1
1
|
module Webrat
|
|
2
2
|
module Selenium
|
|
3
3
|
module Matchers
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
class HaveTag < HaveSelector #:nodoc:
|
|
6
6
|
# ==== Returns
|
|
7
7
|
# String:: The failure message.
|
|
8
8
|
def failure_message
|
|
9
9
|
"expected following output to contain a #{tag_inspect} tag:\n#{@document}"
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
# ==== Returns
|
|
13
13
|
# String:: The failure message to be displayed in negative matches.
|
|
14
14
|
def negative_failure_message
|
|
15
15
|
"expected following output to omit a #{tag_inspect}:\n#{@document}"
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
def tag_inspect
|
|
19
19
|
options = @expected.last.dup
|
|
20
20
|
content = options.delete(:content)
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
html = "<#{@expected.first}"
|
|
23
23
|
options.each do |k,v|
|
|
24
24
|
html << " #{k}='#{v}'"
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
if content
|
|
28
28
|
html << ">#{content}</#{@expected.first}>"
|
|
29
29
|
else
|
|
30
30
|
html << "/>"
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
html
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
def query
|
|
37
37
|
options = @expected.last.dup
|
|
38
38
|
selector = @expected.first.to_s
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
selector << ":contains('#{options.delete(:content)}')" if options[:content]
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
options.each do |key, value|
|
|
43
43
|
selector << "[#{key}='#{value}']"
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
Nokogiri::CSS.parse(selector).map { |ast| ast.to_xpath }
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
def have_tag(name, attributes = {}, &block)
|
|
51
51
|
HaveTag.new([name, attributes], &block)
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
alias_method :match_tag, :have_tag
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
# Asserts that the body of the response contains
|
|
57
57
|
# the supplied tag with the associated selectors
|
|
58
58
|
def assert_have_tag(name, attributes = {})
|
|
59
59
|
ht = HaveTag.new([name, attributes])
|
|
60
60
|
assert ht.matches?(response), ht.failure_message
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
# Asserts that the body of the response
|
|
64
64
|
# does not contain the supplied string or regepx
|
|
65
65
|
def assert_have_no_tag(name, attributes = {})
|
|
66
66
|
ht = HaveTag.new([name, attributes])
|
|
67
67
|
assert !ht.matches?(response), ht.negative_failure_message
|
|
68
68
|
end
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
end
|
|
72
|
+
end
|
|
@@ -5,7 +5,7 @@ module Webrat
|
|
|
5
5
|
def initialize(expected)
|
|
6
6
|
@expected = expected
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
def matches?(response)
|
|
10
10
|
response.session.wait_for do
|
|
11
11
|
response.selenium.is_element_present("xpath=#{@expected}")
|
|
@@ -26,11 +26,11 @@ module Webrat
|
|
|
26
26
|
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
def have_xpath(xpath)
|
|
31
31
|
HaveXpath.new(xpath)
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
def assert_have_xpath(expected)
|
|
35
35
|
hs = HaveXpath.new(expected)
|
|
36
36
|
assert hs.matches?(response), hs.failure_message
|
|
@@ -42,4 +42,4 @@ module Webrat
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
-
end
|
|
45
|
+
end
|