nokogiri_bang_finders 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/nokogiri_bang_finders.rb +12 -4
- data/lib/nokogiri_bang_finders/version.rb +1 -1
- data/spec/nokogiri_bang_finders_spec.rb +6 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63caf64eeffec38c3acdb99726be392fb4226c5a
|
4
|
+
data.tar.gz: cc932ea45e0aff96006ce025e0665eb669fceba0
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890334fbc5f8432f4bf69f23e31ee97901b24d9c755fd991b6248fca9fdfcfb3ef8bcd17c340999341d01519d4879cd8209455032620a007184ac0b4bf4d019d
|
7
|
+
data.tar.gz: ba6e59ab2b439d48b0f2b875c3621b21b2a07f9a3b6e4e09a609e5ae8c15da0b781d16bf30ee1f2f06af772d80f39e50fc9c35def672bcceb3127851a5bea0ff
|
@@ -4,20 +4,28 @@ module Nokogiri
|
|
4
4
|
module XML
|
5
5
|
module BangFinders
|
6
6
|
def at!(*args)
|
7
|
-
at(*args)
|
7
|
+
node = at(*args); raise NotFound.new(args, self) if node.nil?; node
|
8
8
|
end
|
9
9
|
|
10
10
|
def at_xpath!(*args)
|
11
|
-
at_xpath(*args)
|
11
|
+
node = at_xpath(*args); raise NotFound.new(args, self) if node.nil?; node
|
12
12
|
end
|
13
13
|
|
14
14
|
def at_css!(*args)
|
15
|
-
at_css(*args)
|
15
|
+
node = at_css(*args); raise NotFound.new(args, self) if node.nil?; node
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
-
NotFound
|
20
|
+
class NotFound < StandardError
|
21
|
+
attr_reader :message
|
22
|
+
def initialize(needle, haystack)
|
23
|
+
@message = "#{needle} in \n#{snippet(haystack)}"
|
24
|
+
end
|
25
|
+
def snippet(haystack)
|
26
|
+
haystack.to_s.tap {|s| s.length > 200 ? "#{s[0...200]}..." : s }
|
27
|
+
end
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
@@ -24,12 +24,8 @@ describe Nokogiri::XML::BangFinders do
|
|
24
24
|
|
25
25
|
describe "when #at returns nil" do
|
26
26
|
|
27
|
-
|
28
|
-
expect
|
29
|
-
end
|
30
|
-
|
31
|
-
it "raises an exception" do
|
32
|
-
expect{xml_doc.at!('aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
27
|
+
it "raises an exception describing the failed search" do
|
28
|
+
expect{xml_doc.at!('robots')}.to raise_error(Nokogiri::XML::NotFound, /robots/)
|
33
29
|
end
|
34
30
|
|
35
31
|
end
|
@@ -53,12 +49,8 @@ describe Nokogiri::XML::BangFinders do
|
|
53
49
|
|
54
50
|
describe "when #at_css returns nil" do
|
55
51
|
|
56
|
-
|
57
|
-
expect
|
58
|
-
end
|
59
|
-
|
60
|
-
it "raises an exception" do
|
61
|
-
expect{xml_doc.at_css!('aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
52
|
+
it "raises an exception describing the failed search" do
|
53
|
+
expect{xml_doc.at_css!('robots')}.to raise_error(Nokogiri::XML::NotFound, /robots/)
|
62
54
|
end
|
63
55
|
|
64
56
|
end
|
@@ -82,12 +74,8 @@ describe Nokogiri::XML::BangFinders do
|
|
82
74
|
|
83
75
|
describe "when #at_xpath returns nil" do
|
84
76
|
|
85
|
-
|
86
|
-
expect
|
87
|
-
end
|
88
|
-
|
89
|
-
it "raises an exception" do
|
90
|
-
expect{xml_doc.at_xpath!('//aliens')}.to raise_error(Nokogiri::XML::NotFound)
|
77
|
+
it "raises an exception describing the failed search" do
|
78
|
+
expect{xml_doc.at_xpath!('//robots')}.to raise_error(Nokogiri::XML::NotFound, /\/\/robots/)
|
91
79
|
end
|
92
80
|
|
93
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokogiri_bang_finders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Long
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|