Permalink
Browse files

Fix css queries. Bump HTMLUnit version. Tests. Cleanup.

  • Loading branch information...
1 parent 31e7974 commit f776b7f1c6734501464a2878f9fcf900cad2b6d9 @devn committed Dec 26, 2013
Showing with 32 additions and 6 deletions.
  1. +2 −2 project.clj
  2. +8 −0 src/yokogiri/core.clj
  3. +22 −4 test/yokogiri/test/core.clj
View
@@ -6,8 +6,8 @@
:distribution :repo}
:url "https://github.com/devn/yokogiri"
:dependencies [[org.clojure/clojure "1.5.1"]
- [net.sourceforge.htmlunit/htmlunit "2.12"]
- [se.fishtank/css-selectors "1.0.4"]]
+ [net.sourceforge.htmlunit/htmlunit "2.13"]
+ [se.fishtank/css-selectors "1.0.2"]]
:profiles {:dev {:dependencies [[midje "1.5.1" :exclusions [org.clojure/clojure]]]
:plugins [[lein-midje "3.0.1"]]}}
:min-lein-version "2.0.0")
View
@@ -191,6 +191,7 @@
(recur (inc acc)
(let [^DomAttr attr (.item attrs acc)]
(assoc res (keyword (.getName attr)) (.getValue attr))))))))
+
(def attrs #'yokogiri.core/attr-map)
;; TODO: http://htmlunit.sourceforge.net/apidocs/com/gargoylesoftware/htmlunit/html/DomAttr.html
@@ -202,3 +203,10 @@
(let [^NamedNodeMap attrs (.getAttributes node)
len (.getLength attrs)]
(map #(.item attrs %) (range 0 len))))
+
+(comment
+ (def c (make-client))
+ (def p (get-page c "http://www.example.com/"))
+ (xpath p "//a")
+ (map attrs (css p "p"))
+)
@@ -2,14 +2,21 @@
(:use [yokogiri.core])
(:use [midje.sweet]))
+(fact "These tests need to be improved, but they're better than nothing."
+ true => true)
+
(facts "yokogiri.core/make-client"
(fact "It can create a client"
(let [simple-client (make-client)]
- simple-client => truthy
- (class simple-client) => com.gargoylesoftware.htmlunit.WebClient))
+ simple-client
+ => truthy
+ (class simple-client)
+ => com.gargoylesoftware.htmlunit.WebClient))
+
(fact "It can create a client with options"
(let [insecure-client (make-client :insecure-ssl true)]
- (:insecure-ssl (get-client-options insecure-client)) => true))
+ (:insecure-ssl (get-client-options insecure-client))
+ => true))
(fact "It can create a client with many non-default options"
(let [c (make-client :insecure-ssl false
:javascript false
@@ -18,4 +25,15 @@
(->> (-> opts
(select-keys [:insecure-ssl :javascript :css])
(vals))
- (every? false?))) => true))
+ (every? false?)))
+ => true))
+
+(facts "About CSS and XPath queries"
+ (let [c (make-client)
+ p (get-page c "http://www.example.com/")]
+ (fact "CSS works"
+ (css p "a")
+ => truthy)
+ (fact "XPath works")
+ (xpath p "//a")
+ => truthy))

0 comments on commit f776b7f

Please sign in to comment.