rspec-xml 0.0.6 → 0.0.8
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.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/lib/rspec-xml/version.rb +1 -1
- data/lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb +34 -0
- data/lib/rspec-xml/xml_matchers/have_xpath/matcher.rb +4 -0
- data/lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb +4 -0
- data/lib/rspec-xml/xml_matchers/have_xpath.rb +12 -1
- data/lib/rspec-xml/xml_matchers.rb +1 -0
- data/readme.md +5 -9
- data/spec/features/have_path.feature +6 -1
- data/spec/features/steps/have_path_steps.rb +9 -1
- data/spec/features/steps/within_steps.rb +1 -1
- data/spec/rspec-xml/xml_matchers/have_xpath/matcher_spec.rb +9 -2
- data/spec/rspec-xml/xml_matchers/have_xpath/text_matcher_spec.rb +10 -3
- data/spec/rspec-xml/xml_matchers/have_xpath_matcher_spec.rb +13 -0
- metadata +18 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4198e8dd85cad2e5bfbd99519de7376b323b94ce
|
4
|
+
data.tar.gz: cfa2a5428ccffbe5e7e16294d4b367dc2a98c3cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 104efcd3f80764495b0878dfe782958a30a14554990ff24e3090ba3dbc095f1cbe5818bb731922f3a692f7413c041618511d305d69175b25c0aed876f2807d4d
|
7
|
+
data.tar.gz: ff19d27bb3d121a7ba1082424397f4ee23a2516870d90e64ab768c7acad44663be0f79df31c089620e55b40202edd980bfe11a66293010bb8d3cde28b8237207
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-r turnip/rspec
|
data/lib/rspec-xml/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
module RSpecXML
|
2
|
+
module XMLMatchers
|
3
|
+
class HaveXPath
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
class AttrMatcher
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
self.xpath = options[:xpath]
|
11
|
+
self.attr = options[:attr]
|
12
|
+
end
|
13
|
+
|
14
|
+
def matches?(xml)
|
15
|
+
attr.each do |k, v|
|
16
|
+
::Nokogiri::XML(xml).xpath(xpath).attr(k.to_s).value == v.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message_for_should
|
21
|
+
"expected #{xpath} to contain #{attr}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message_for_should_not
|
25
|
+
"expected #{xpath} to not exist with attribute: #{attr}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_accessor :attr, :xpath
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -12,7 +12,18 @@ module RSpecXML
|
|
12
12
|
def with_text(text)
|
13
13
|
self.matcher = TextMatcher.new(
|
14
14
|
:xpath => matcher.full_xpath,
|
15
|
-
:text => text.to_s
|
15
|
+
:text => text.to_s
|
16
|
+
)
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_attr(attr)
|
22
|
+
self.matcher = AttrMatcher.new(
|
23
|
+
:xpath => matcher.full_xpath,
|
24
|
+
:attr => attr
|
25
|
+
)
|
26
|
+
|
16
27
|
self
|
17
28
|
end
|
18
29
|
|
data/readme.md
CHANGED
@@ -21,13 +21,9 @@ gem 'rspec-xml'
|
|
21
21
|
### Builder
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
xml =
|
25
|
-
|
26
|
-
|
24
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
25
|
+
xml.send("inner", "stuff", "Country" => "USA", "City" => "New York")
|
26
|
+
end.to_xml
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
xml.should have_xpath('//some_xml/inner').with_text('stuff')
|
33
|
-
```
|
28
|
+
xml.should have_xpath('//some_xml/inner').with_text('stuff').with_attr({"Country" => "USA", "City" =>"New York"})
|
29
|
+
```
|
@@ -1,5 +1,5 @@
|
|
1
1
|
@have_path
|
2
|
-
Feature: "some xml".should have_xpath('//something').with_text('Budweiser') ---
|
2
|
+
Feature: "some xml".should have_xpath('//something').with_text('Budweiser').with_attr("Category" => "Alcohol") ---
|
3
3
|
|
4
4
|
Background:
|
5
5
|
Given there is a string of XML
|
@@ -13,3 +13,8 @@ Feature: "some xml".should have_xpath('//something').with_text('Budweiser') ---
|
|
13
13
|
Given the best node contains the text: Budweiser
|
14
14
|
When I test for the text: Miller within the best node
|
15
15
|
Then the test should fail
|
16
|
+
|
17
|
+
Scenario: the matcher should pass when the node contains the attribute
|
18
|
+
Given the best node contains the attribute Category with value: Alcohol
|
19
|
+
When I test for the attribute: "Category" to be "Alcohol" within the best node
|
20
|
+
Then the test should pass
|
@@ -11,8 +11,16 @@ steps_for :have_path do
|
|
11
11
|
@test = lambda { @xml.should have_xpath("//#{node_name}").with_text(text) }
|
12
12
|
end
|
13
13
|
|
14
|
+
step 'the :node_name node contains the attribute :key with value: :value' do |node_name, key, value|
|
15
|
+
@xml = @xml.call "<#{node_name} #{key}=\"#{value}\"></#{node_name}>"
|
16
|
+
end
|
17
|
+
|
18
|
+
step 'I test for the attribute: :key to be :value within the :node_name node' do |key, value, node_name|
|
19
|
+
@test = lambda { @xml.should have_xpath("//#{node_name}").with_attr({key => value}) }
|
20
|
+
end
|
21
|
+
|
14
22
|
step 'the test should pass' do
|
15
|
-
@test.should_not raise_error
|
23
|
+
@test.should_not raise_error
|
16
24
|
end
|
17
25
|
|
18
26
|
step 'the test should fail' do
|
@@ -13,12 +13,12 @@ describe RSpecXML::XMLMatchers::HaveXPath::Matcher do
|
|
13
13
|
|
14
14
|
it 'should return true if the supplied xml contains the xpath' do
|
15
15
|
matcher = subject.class.new(:xpath => '//hi')
|
16
|
-
matcher.matches?('<hi></hi>').should
|
16
|
+
matcher.matches?('<hi></hi>').should == true
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should return false if the supplied xml contains the xpath' do
|
20
20
|
matcher = subject.class.new(:xpath => '//hi')
|
21
|
-
matcher.matches?('<no></no>').should
|
21
|
+
matcher.matches?('<no></no>').should == false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -35,4 +35,11 @@ describe RSpecXML::XMLMatchers::HaveXPath::Matcher do
|
|
35
35
|
subject.failure_message_for_should_not.should == "expected xpath to not exist"
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
describe '#description' do
|
40
|
+
it 'should return a message describing the xpath matcher' do
|
41
|
+
subject.stubs(:xpath).returns('/expr')
|
42
|
+
subject.description.should == 'have xpath /expr'
|
43
|
+
end
|
44
|
+
end
|
38
45
|
end
|
@@ -19,17 +19,17 @@ describe RSpecXML::XMLMatchers::HaveXPath::TextMatcher do
|
|
19
19
|
|
20
20
|
it 'should return true if the supplied xml contains the xpath with supplied text' do
|
21
21
|
matcher = subject.class.new(:xpath => '//hi', :text => 'hi')
|
22
|
-
matcher.matches?('<hi>hi</hi>').should
|
22
|
+
matcher.matches?('<hi>hi</hi>').should == true
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should return false if the supplied xml contains the xpath but not the text' do
|
26
26
|
matcher = subject.class.new(:xpath => '//hi', :text => 'what')
|
27
|
-
matcher.matches?('<hi></hi>').should
|
27
|
+
matcher.matches?('<hi></hi>').should == false
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should return false if the supplied xml does not contain the xpath' do
|
31
31
|
matcher = subject.class.new(:xpath => '//hi', :text => 'what')
|
32
|
-
matcher.matches?('<no></no>').should
|
32
|
+
matcher.matches?('<no></no>').should == false
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -50,4 +50,11 @@ describe RSpecXML::XMLMatchers::HaveXPath::TextMatcher do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe '#description' do
|
54
|
+
it 'should return a message describing the text matcher' do
|
55
|
+
subject.stubs(:xpath).returns('/expr')
|
56
|
+
subject.stubs(:text).returns('text')
|
57
|
+
subject.description.should == 'have xpath /expr with text text'
|
58
|
+
end
|
59
|
+
end
|
53
60
|
end
|
@@ -40,6 +40,19 @@ describe RSpecXML::XMLMatchers::HaveXPath do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
describe '#with_attr' do
|
44
|
+
it 'should build a new attribute matcher containing supplied xpath and attributes' do
|
45
|
+
|
46
|
+
RSpecXML::XMLMatchers::HaveXPath::AttrMatcher.
|
47
|
+
expects(:new).
|
48
|
+
with(:xpath => 'fake xpath', :attr => {"name" => "John Doe"}).
|
49
|
+
returns(:flag)
|
50
|
+
|
51
|
+
xpath_matcher = Factory.xpath_matcher('fake xpath').with_attr({"name" => "John Doe"})
|
52
|
+
xpath_matcher.send(:matcher).should == :flag
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
43
56
|
describe '#failure_message_for_should' do
|
44
57
|
it 'should delegate to the matcher' do
|
45
58
|
xpath_matcher = Factory.xpath_matcher('whatever')
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.8
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dan Carper
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: turnip
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: mocha
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: nokogiri
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: One simple matcher for now
|
@@ -82,7 +73,8 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
86
78
|
- CHANGELOG.md
|
87
79
|
- Gemfile
|
88
80
|
- Rakefile
|
@@ -90,6 +82,7 @@ files:
|
|
90
82
|
- lib/rspec-xml/version.rb
|
91
83
|
- lib/rspec-xml/xml_matchers.rb
|
92
84
|
- lib/rspec-xml/xml_matchers/have_xpath.rb
|
85
|
+
- lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb
|
93
86
|
- lib/rspec-xml/xml_matchers/have_xpath/matcher.rb
|
94
87
|
- lib/rspec-xml/xml_matchers/have_xpath/text_matcher.rb
|
95
88
|
- license.txt
|
@@ -106,27 +99,26 @@ files:
|
|
106
99
|
- spec/spec_helper.rb
|
107
100
|
homepage: ''
|
108
101
|
licenses: []
|
102
|
+
metadata: {}
|
109
103
|
post_install_message:
|
110
104
|
rdoc_options: []
|
111
105
|
require_paths:
|
112
106
|
- lib
|
113
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
108
|
requirements:
|
116
|
-
- -
|
109
|
+
- - ">="
|
117
110
|
- !ruby/object:Gem::Version
|
118
111
|
version: '0'
|
119
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
113
|
requirements:
|
122
|
-
- -
|
114
|
+
- - ">="
|
123
115
|
- !ruby/object:Gem::Version
|
124
116
|
version: '0'
|
125
117
|
requirements: []
|
126
118
|
rubyforge_project: rspec-xml
|
127
|
-
rubygems_version:
|
119
|
+
rubygems_version: 2.2.2
|
128
120
|
signing_key:
|
129
|
-
specification_version:
|
121
|
+
specification_version: 4
|
130
122
|
summary: Spec your XML
|
131
123
|
test_files:
|
132
124
|
- spec/features/have_path.feature
|
@@ -138,4 +130,3 @@ test_files:
|
|
138
130
|
- spec/rspec-xml/xml_matchers/have_xpath_matcher_spec.rb
|
139
131
|
- spec/rspec-xml/xml_matchers_spec.rb
|
140
132
|
- spec/spec_helper.rb
|
141
|
-
has_rdoc:
|