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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: e391b1470292d7057b9c4d2313b6bc76af79bb58
4
- data.tar.gz: ed332b50ea2af4c6d09cfe158ae9756868cd2a0a
3
+ metadata.gz: 63caf64eeffec38c3acdb99726be392fb4226c5a
4
+ data.tar.gz: cc932ea45e0aff96006ce025e0665eb669fceba0
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 371837a464c03358e1145642a6517e5d27dc87eba1179633b957c988fb9096bb660922f03946fce5cb6ec9532dfeb63a8bf87818f0c50dd2d7482dae991f6986
7
- data.tar.gz: 0f8ebbb89481f2e604d4584d9d7435954744828c911aeb49021532e94b34f4cda3ce3d66f9d6c81719c2b932245488fe398baced55b2078934b442309b17a1eb
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).tap { |node| raise NotFound if node.nil? }
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).tap { |node| raise NotFound if node.nil? }
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).tap { |node| raise NotFound if node.nil? }
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 = Class.new(StandardError)
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
 
@@ -1,3 +1,3 @@
1
1
  module NokogiriBangFinders
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,12 +24,8 @@ describe Nokogiri::XML::BangFinders do
24
24
 
25
25
  describe "when #at returns nil" do
26
26
 
27
- before :each do
28
- expect(xml_doc).to receive('at').with('aliens').and_return(nil)
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
- before :each do
57
- expect(xml_doc).to receive('at_css').with('aliens').and_return(nil)
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
- before :each do
86
- expect(xml_doc).to receive('at_xpath').with('//aliens').and_return(nil)
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.1
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-03 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri