Test failed in guestbook tutorial in 'Your First Application'
lemonteaa opened this issue ยท 5 comments
When following the guestbook tutorial, the unit test in the section 'Adding some tests' failed with the following message:
C:\Users\Owner\Documents\clojure_web\guestbook>lein test
2017-10-14 00:20:42,385 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
2017-10-14 00:20:43,348 [main] INFO guestbook.env -
-=[guestbook started successfully using the development profile]=-
2017-10-14 00:20:43,517 [main] INFO luminus.http-server - starting HTTP server on port 3000
2017-10-14 00:20:43,615 [main] INFO org.xnio - XNIO version 3.3.6.Final
2017-10-14 00:20:44,000 [main] INFO org.projectodd.wunderboss.web.Web - Registered web context /
lein test guestbook.test.db.core
2017-10-14 00:20:44,428 [main] INFO migratus.core - Starting migrations
2017-10-14 00:20:44,465 [main] INFO migratus.database - creating migration table 'schema_migrations'
2017-10-14 00:20:44,548 [main] DEBUG migratus.migrations - Looking for migrations in in #object[java.io.File 0x12a22dc4 C:\Users\Owner\Documents\clojure_web\guestbook\resources\migrations]
2017-10-14 00:20:44,571 [main] INFO migratus.core - Running up for [20171013234027]
2017-10-14 00:20:44,572 [main] INFO migratus.core - Up 20171013234027-add-users-table
2017-10-14 00:20:44,596 [main] DEBUG migratus.migration.sql - found 1 up migrations
2017-10-14 00:20:44,610 [main] DEBUG migratus.database - marking 20171013234027 complete
2017-10-14 00:20:44,621 [main] INFO migratus.core - Ending migrations
lein test :only guestbook.test.db.core/test-users
FAIL in (test-users) (core.clj:28)
expected: {:name "Bob",
:message "Hello, World",
:timestamp #inst "2017-10-13T16:20:44.636-00:00"}
actual: {:name "Bob",
:message "Hello, World",
:timestamp
#object[org.joda.time.DateTime 0x1e2ea153 "2017-10-13T16:20:44.636Z"]}
diff: - {:timestamp #inst "2017-10-13T16:20:44.636-00:00"}
+ {:timestamp
#object[org.joda.time.DateTime 0x1e2ea153 "2017-10-13T16:20:44.636Z"]}
lein test guestbook.test.handler
Ran 2 tests containing 4 assertions.
1 failures, 0 errors.
Tests failed.
Does the db library do automatic conversion to/from Jodatime somewhere? (Just a wild guess)
The Jodatime conversion is triggered by clj-time.jdbc. It attempts to coerce dates coming back in results into Joda time objects:
(extend-protocol jdbc/IResultSetReadColumn
java.sql.Timestamp
(result-set-read-column [v _2 _3]
(tc/from-sql-time v))
java.sql.Date
(result-set-read-column [v _2 _3]
(tc/from-sql-date v))
java.sql.Time
(result-set-read-column [v _2 _3]
(org.joda.time.DateTime. v)))
; http://clojure.github.io/java.jdbc/#clojure.java.jdbc/ISQLValue
(extend-protocol jdbc/ISQLValue
org.joda.time.DateTime
(sql-value [v]
(tc/to-sql-time v)))
I updated the example to use JodaTime as follows:
(deftest test-message
(jdbc/with-db-transaction [t-conn *db*]
(jdbc/db-set-rollback-only! t-conn)
(let [timestamp (org.joda.time.DateTime. org.joda.time.DateTimeZone/UTC)]
(is (= 1 (db/save-message!
t-conn
{:name "Bob"
:message "Hello, World"
:timestamp timestamp}
{:connection t-conn})))
(is (=
{:name "Bob"
:message "Hello, World"
:timestamp timestamp}
(-> (db/get-messages t-conn {})
(first)
(select-keys [:name :message :timestamp])))))))
Thanks for the explanation! (and code search I suppose ๐ )
It works now ๐
It seems like tests from repository and tests from tutorial are'nt syncronised. I've got hard times to figure out what is happening, then repo version saved my life. Please update section "Adding some tests" in guestbook application like in this line
Thanks for the heads up, updated the docs accordingly.