Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Only pass arrays of strings around

  • Loading branch information...
commit 099ef7d4a0ec5989f1448d8cebd4fc717d59a440 1 parent 868589a
Felix Schäfer authored
3  lib/page_watcher/filter/xpath.rb
@@ -7,8 +7,7 @@ def initialize(xpath)
7 7
         @xpath = xpath
8 8
       end
9 9
 
10  
-      def call(strings = "")
11  
-        strings = [strings] unless strings.respond_to? :each
  10
+      def call(strings = [])
12 11
         strings.map {|string| Nokogiri::HTML(string).xpath(@xpath)}.flatten.map(&:to_s)
13 12
       end
14 13
     end
6  specs/lib/page_watcher/filter/xpath_spec.rb
@@ -27,13 +27,13 @@ def example_content_2
27 27
     "Find me if you can!"
28 28
   end
29 29
 
30  
-  it "should work when passed an array of strings" do
  30
+  it "should work when passed many strings in the input array" do
31 31
     PageWatcher::Filter::XPath.new(example_xpath).call([example_html, example_html]).must_equal [example_content_2, example_content_2]
32 32
   end
33 33
 
34 34
   describe "when the xpath returns one string" do
35 35
     it "should return the content we're looking for" do
36  
-      PageWatcher::Filter::XPath.new(example_xpath).call(example_html).must_equal [example_content_2]
  36
+      PageWatcher::Filter::XPath.new(example_xpath).call([example_html]).must_equal [example_content_2]
37 37
     end
38 38
   end
39 39
 
@@ -43,7 +43,7 @@ def example_xpath
43 43
     end
44 44
 
45 45
     it "should return the content we're looking for" do
46  
-      PageWatcher::Filter::XPath.new(example_xpath).call(example_html).must_equal [example_content_1, example_content_2]
  46
+      PageWatcher::Filter::XPath.new(example_xpath).call([example_html]).must_equal [example_content_1, example_content_2]
47 47
     end
48 48
   end
49 49
 end

0 notes on commit 099ef7d

Please sign in to comment.
Something went wrong with that request. Please try again.