forked from simianarmy/encoding-dot-com
/
spec_helper.rb
46 lines (36 loc) · 925 Bytes
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
# require File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment'))
#Bundler.require
require 'encoding-dot-com'
class EncodingXpathMatcher
def initialize(xpath)
@xpath = xpath
end
def ==(post_vars)
! Nokogiri::XML(post_vars[:xml]).xpath(@xpath).empty?
end
end
module XpathMatchers
class HaveXpath
def initialize(xpath)
@xpath = xpath
end
def matches?(xml)
@xml = xml
Nokogiri::XML(xml).xpath(@xpath).any?
end
def failure_message
"expected #{@xml} to have xpath #{@xpath}"
end
def negative_failure_message
"expected #{@xml} not to have xpath #{@xpath}"
end
end
def have_xpath(xpath)
HaveXpath.new(xpath)
end
end
Spec::Runner.configure do |config|
config.include(XpathMatchers)
end