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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa4790e15a330a52a75a38666cdcf5e2d97587b9
4
- data.tar.gz: acde529945aaa1e92570da8cace1f252ede78683
3
+ metadata.gz: 8075c76f23702fb1e2ed80385cd102bfc92d507b
4
+ data.tar.gz: a024df842466d9e389e636ac5649dd3ff4255616
5
5
  SHA512:
6
- metadata.gz: dc05010c99f90ea3de5ad8db1afe705a34eaa4b92cebd5254479feabbb31f9d0e249acc5136cd3db2db32b8f30e81e25b182de2ec4e77476e11898f007799401
7
- data.tar.gz: 6bd9b43cd3e803ea1e14449f578fd79d1faa458219138e6dc540ddb4421ecff9caa2c59c34341d049f2bd871d0998a3aef1d9260adc794e036397cf83e4bf1d8
6
+ metadata.gz: 60b0ceb4a7c163819531c6043782970a82cd7fcbd57220ecdb4859714538a3641c254c8fe5a2c1cbbebf2a1a6dc4bce3f376591551702f0d2d6c80fe35dc850d
7
+ data.tar.gz: 64e4b904035974b2aeff3316a2250048f294269518a218c7d56186b38065e72e7679ace9aa22c890e1d8cba3fa0ec64cbebc6e751447e9ecb0b09923ef47e380
@@ -1,3 +1,3 @@
1
1
  module RSpecXML
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -12,16 +12,22 @@ module RSpecXML
12
12
  end
13
13
 
14
14
  def matches?(xml)
15
- attr.each do |k, v|
16
- ::Nokogiri::XML(xml).xpath(xpath).attr(k.to_s).value == v.to_s
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 failure_message_for_should
21
- "expected #{xpath} to contain #{attr}"
22
+ def description
23
+ "have xpath #{xpath} with attribute: #{attr}"
22
24
  end
23
25
 
24
- def failure_message_for_should_not
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.should have_xpath("//#{node_name}").with_text(text) }
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.should have_xpath("//#{node_name}").with_attr({key => value}) }
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.should_not raise_error
23
+ expect(@test).not_to raise_error
24
24
  end
25
25
 
26
26
  step 'the test should fail' do
27
- @test.should raise_error(RSpec::Expectations::ExpectationNotMetError)
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.should have_xpath("/#{hash["node"]}").with_text(hash["text"])
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.should_not raise_error
24
+ expect(@test).not_to raise_error
25
25
  end
26
26
 
27
27
  step 'the test should fail' do
28
- @test.should raise_error(RSpec::Expectations::ExpectationNotMetError)
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.9
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-09-04 00:00:00.000000000 Z
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