rspec-xml 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec-xml/version.rb +1 -1
- data/lib/rspec-xml/xml_matchers/have_xpath/attr_matcher.rb +11 -5
- data/spec/features/have_path.feature +10 -0
- data/spec/features/steps/have_path_steps.rb +4 -4
- data/spec/features/steps/within_steps.rb +3 -3
- data/spec/rspec-xml/xml_matchers/have_xpath/attr_matcher_spec.rb +65 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8075c76f23702fb1e2ed80385cd102bfc92d507b
|
4
|
+
data.tar.gz: a024df842466d9e389e636ac5649dd3ff4255616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b0ceb4a7c163819531c6043782970a82cd7fcbd57220ecdb4859714538a3641c254c8fe5a2c1cbbebf2a1a6dc4bce3f376591551702f0d2d6c80fe35dc850d
|
7
|
+
data.tar.gz: 64e4b904035974b2aeff3316a2250048f294269518a218c7d56186b38065e72e7679ace9aa22c890e1d8cba3fa0ec64cbebc6e751447e9ecb0b09923ef47e380
|
data/lib/rspec-xml/version.rb
CHANGED
@@ -12,16 +12,22 @@ module RSpecXML
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def matches?(xml)
|
15
|
-
|
16
|
-
|
15
|
+
node = ::Nokogiri::XML(xml).xpath(xpath)
|
16
|
+
!node.empty? && attr.all? do |k, v|
|
17
|
+
attr_value = node.attr(k.to_s)
|
18
|
+
!attr_value.nil? && attr_value.value == v.to_s
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
"
|
22
|
+
def description
|
23
|
+
"have xpath #{xpath} with attribute: #{attr}"
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
26
|
+
def failure_message
|
27
|
+
"expected #{xpath} to contain attribute: #{attr}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure_message_when_negated
|
25
31
|
"expected #{xpath} to not exist with attribute: #{attr}"
|
26
32
|
end
|
27
33
|
|
@@ -18,3 +18,13 @@ Feature: "some xml".should have_xpath('//something').with_text('Budweiser').with
|
|
18
18
|
Given the best node contains the attribute Category with value: Alcohol
|
19
19
|
When I test for the attribute: "Category" to be "Alcohol" within the best node
|
20
20
|
Then the test should pass
|
21
|
+
|
22
|
+
Scenario: the matcher should fail when the node doesn't contains the attribute
|
23
|
+
Given the best node contains the attribute Category with value: Alcohol
|
24
|
+
When I test for the attribute: "Type" to be "Alcohol" within the best node
|
25
|
+
Then the test should fail
|
26
|
+
|
27
|
+
Scenario: the matcher should fail when the node doesn't contains the attribute value
|
28
|
+
Given the best node contains the attribute Category with value: Alcohol
|
29
|
+
When I test for the attribute: "Category" to be "Soft Drink" within the best node
|
30
|
+
Then the test should fail
|
@@ -8,7 +8,7 @@ steps_for :have_path do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
step 'I test for the text: :text within the :node_name node' do |text, node_name|
|
11
|
-
@test = lambda { @xml.
|
11
|
+
@test = lambda { expect(@xml).to have_xpath("//#{node_name}").with_text(text) }
|
12
12
|
end
|
13
13
|
|
14
14
|
step 'the :node_name node contains the attribute :key with value: :value' do |node_name, key, value|
|
@@ -16,15 +16,15 @@ steps_for :have_path do
|
|
16
16
|
end
|
17
17
|
|
18
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.
|
19
|
+
@test = lambda { expect(@xml).to have_xpath("//#{node_name}").with_attr({key => value}) }
|
20
20
|
end
|
21
21
|
|
22
22
|
step 'the test should pass' do
|
23
|
-
@test.
|
23
|
+
expect(@test).not_to raise_error
|
24
24
|
end
|
25
25
|
|
26
26
|
step 'the test should fail' do
|
27
|
-
@test.
|
27
|
+
expect(@test).to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -13,7 +13,7 @@ steps_for :within do
|
|
13
13
|
within('xml') do
|
14
14
|
within('/elem') do
|
15
15
|
table.hashes.each do |hash|
|
16
|
-
@xml.
|
16
|
+
expect(@xml).to have_xpath("/#{hash["node"]}").with_text(hash["text"])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -21,11 +21,11 @@ steps_for :within do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
step 'the test should pass' do
|
24
|
-
@test.
|
24
|
+
expect(@test).not_to raise_error
|
25
25
|
end
|
26
26
|
|
27
27
|
step 'the test should fail' do
|
28
|
-
@test.
|
28
|
+
expect(@test).to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RSpecXML::XMLMatchers::HaveXPath::AttrMatcher do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should accept an xpath' do
|
6
|
+
matcher = subject.class.new(:xpath => 'not a real xpath')
|
7
|
+
expect(matcher.send(:xpath)).to eq 'not a real xpath'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should accept attr' do
|
11
|
+
matcher = subject.class.new(:attr => {'foo' => 'bar', 'x' => 2})
|
12
|
+
expect(matcher.send(:attr)).to eq({'foo' => 'bar', 'x' => 2})
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#matches?' do
|
18
|
+
# TODO mock out Nokogiri
|
19
|
+
|
20
|
+
it 'should return true if the supplied xml contains the xpath with supplied attributes' do
|
21
|
+
matcher = subject.class.new(:xpath => '//hi', :attr => {'foo' => 'bar', 'x' => 2})
|
22
|
+
expect(matcher.matches?('<hi foo="bar" x="2"/>')).to be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return false if the supplied xml contains the xpath but not the one of the attibutes' do
|
26
|
+
matcher = subject.class.new(:xpath => '//hi', :attr => {'foo' => 'bar', 'x' => 2, 'y' => 3})
|
27
|
+
expect(matcher.matches?('<hi foo="bar" x="2"/>')).to be_falsey
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return false if the supplied xml contains the xpath but one of the attibutes has a wrong value' do
|
31
|
+
matcher = subject.class.new(:xpath => '//hi', :attr => {'foo' => 'bar', 'x' => 3})
|
32
|
+
expect(matcher.matches?('<hi foo="bar" x="2"/>')).to be_falsey
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return false if the supplied xml does not contain the xpath' do
|
36
|
+
matcher = subject.class.new(:xpath => '//hi', :attr => {'foo' => 'bar', 'x' => 2})
|
37
|
+
expect(matcher.matches?('<no></no>')).to be_falsey
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#failure_message' do
|
43
|
+
it 'should turn a message about the xpath not existing when the supplied text' do
|
44
|
+
subject.stubs(:xpath).returns('xpath')
|
45
|
+
subject.stubs(:attr).returns({'foo' => 'bar', 'x' => 2})
|
46
|
+
expect(subject.failure_message).to eq "expected xpath to contain attribute: {\"foo\"=>\"bar\", \"x\"=>2}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#failure_message_when_negated' do
|
51
|
+
it 'should turn a message about the xpath existing when it should not' do
|
52
|
+
subject.stubs(:xpath).returns('xpath')
|
53
|
+
subject.stubs(:attr).returns({'foo' => 'bar', 'x' => 2})
|
54
|
+
expect(subject.failure_message_when_negated).to eq "expected xpath to not exist with attribute: {\"foo\"=>\"bar\", \"x\"=>2}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#description' do
|
59
|
+
it 'should return a message describing the text matcher' do
|
60
|
+
subject.stubs(:xpath).returns('/expr')
|
61
|
+
subject.stubs(:attr).returns({'foo' => 'bar', 'x' => 2})
|
62
|
+
expect(subject.description).to eq "have xpath /expr with attribute: {\"foo\"=>\"bar\", \"x\"=>2}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Carper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: turnip
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- spec/features/steps/have_path_steps.rb
|
93
93
|
- spec/features/steps/within_steps.rb
|
94
94
|
- spec/features/within.feature
|
95
|
+
- spec/rspec-xml/xml_matchers/have_xpath/attr_matcher_spec.rb
|
95
96
|
- spec/rspec-xml/xml_matchers/have_xpath/matcher_spec.rb
|
96
97
|
- spec/rspec-xml/xml_matchers/have_xpath/text_matcher_spec.rb
|
97
98
|
- spec/rspec-xml/xml_matchers/have_xpath_matcher_spec.rb
|
@@ -125,6 +126,7 @@ test_files:
|
|
125
126
|
- spec/features/steps/have_path_steps.rb
|
126
127
|
- spec/features/steps/within_steps.rb
|
127
128
|
- spec/features/within.feature
|
129
|
+
- spec/rspec-xml/xml_matchers/have_xpath/attr_matcher_spec.rb
|
128
130
|
- spec/rspec-xml/xml_matchers/have_xpath/matcher_spec.rb
|
129
131
|
- spec/rspec-xml/xml_matchers/have_xpath/text_matcher_spec.rb
|
130
132
|
- spec/rspec-xml/xml_matchers/have_xpath_matcher_spec.rb
|