webrat 0.3.1 → 0.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.
data/History.txt
CHANGED
data/lib/webrat.rb
CHANGED
@@ -3,7 +3,7 @@ require "rubygems"
|
|
3
3
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
4
4
|
|
5
5
|
module Webrat
|
6
|
-
VERSION = '0.3.
|
6
|
+
VERSION = '0.3.2'
|
7
7
|
|
8
8
|
def self.root #:nodoc:
|
9
9
|
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
|
@@ -30,8 +30,8 @@ module Webrat
|
|
30
30
|
# HaveSelector:: A new have selector matcher.
|
31
31
|
# ---
|
32
32
|
# @api public
|
33
|
-
def have_selector(expected)
|
34
|
-
HaveSelector.new(expected)
|
33
|
+
def have_selector(expected, &block)
|
34
|
+
HaveSelector.new(expected, &block)
|
35
35
|
end
|
36
36
|
alias_method :match_selector, :have_selector
|
37
37
|
|
@@ -16,17 +16,31 @@ module Webrat
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def matches_rexml?(stringlike)
|
19
|
+
@query = query
|
20
|
+
|
19
21
|
@document = rexml_document(stringlike)
|
20
|
-
|
21
|
-
query.
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
matched = @query.map do |q|
|
24
|
+
if @document.is_a?(Array)
|
25
|
+
@document.map { |d| REXML::XPath.match(d, q) }
|
26
|
+
else
|
27
|
+
REXML::XPath.match(@document, q)
|
28
|
+
end
|
29
|
+
end.flatten.compact
|
30
|
+
|
31
|
+
matched.any? && (!@block || @block.call(matched))
|
25
32
|
end
|
26
33
|
|
27
34
|
def matches_nokogiri?(stringlike)
|
35
|
+
if Nokogiri::XML::NodeSet === stringlike
|
36
|
+
@query = query.map { |q| q.gsub(%r'//', './') }
|
37
|
+
else
|
38
|
+
@query = query
|
39
|
+
end
|
40
|
+
|
28
41
|
@document = Webrat.nokogiri_document(stringlike)
|
29
|
-
@document.xpath(
|
42
|
+
matched = @document.xpath(*@query)
|
43
|
+
matched.any? && (!@block || @block.call(matched))
|
30
44
|
end
|
31
45
|
|
32
46
|
def rexml_document(stringlike)
|
@@ -35,9 +49,10 @@ module Webrat
|
|
35
49
|
case stringlike
|
36
50
|
when REXML::Document
|
37
51
|
stringlike.root
|
38
|
-
when REXML::Node
|
52
|
+
when REXML::Node, Array
|
53
|
+
@query = query.map { |q| q.gsub(%r'//', './') }
|
39
54
|
stringlike
|
40
|
-
|
55
|
+
else
|
41
56
|
begin
|
42
57
|
REXML::Document.new(stringlike.to_s).root
|
43
58
|
rescue REXML::ParseException => e
|
@@ -76,8 +91,8 @@ module Webrat
|
|
76
91
|
# HaveXpath:: A new have xpath matcher.
|
77
92
|
# ---
|
78
93
|
# @api public
|
79
|
-
def have_xpath(expected)
|
80
|
-
HaveXpath.new(expected)
|
94
|
+
def have_xpath(expected, &block)
|
95
|
+
HaveXpath.new(expected, &block)
|
81
96
|
end
|
82
97
|
alias_method :match_xpath, :have_xpath
|
83
98
|
|
data/lib/webrat/core/nokogiri.rb
CHANGED
@@ -5,9 +5,11 @@ module Webrat
|
|
5
5
|
def self.nokogiri_document(stringlike) #:nodoc:
|
6
6
|
return stringlike.dom if stringlike.respond_to?(:dom)
|
7
7
|
|
8
|
-
if
|
8
|
+
if Nokogiri::HTML::Document === stringlike
|
9
9
|
stringlike
|
10
|
-
elsif
|
10
|
+
elsif Nokogiri::XML::NodeSet === stringlike
|
11
|
+
stringlike
|
12
|
+
elsif StringIO === stringlike
|
11
13
|
Nokogiri::HTML(stringlike.string)
|
12
14
|
elsif stringlike.respond_to?(:body)
|
13
15
|
Nokogiri::HTML(stringlike.body.to_s)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.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: 2008-11-
|
12
|
+
date: 2008-11-08 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements: []
|
111
111
|
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.0
|
114
114
|
signing_key:
|
115
115
|
specification_version: 2
|
116
116
|
summary: Webrat. Ruby Acceptance Testing for Web applications
|