luminus-framework / guestbook

guestbook example
42 stars 19 forks source link

db tests sometimes fail when run from repl #21

Open zlrth opened 7 years ago

zlrth commented 7 years ago

I can’t figure out how to run tests that use a test database from my cider-repl. lein test works as intended, for what it's worth.

But when I run the the test in the test-db namespace[1], it creates a dev database (./guestbook_dev.db).

This means that if I, from the repl, (start), then add something to the db using the form at localhost:3000, then run the db test, the db test fails[3].

I think this is because the mount/start function is creating an environment using the dev profile.[2] I'd open a pull request for your review, but I don't know enough about mount, profiles.clj, cprop, and possibly other things. I suspect that using the :test profile in project.clj would do it, but I don't know how to tell mount/start to use it.

[1] https://github.com/luminus-framework/guestbook/blob/master/test/clj/guestbook/test/db/core.clj#L18 [2] https://github.com/luminus-framework/guestbook/blob/master/test/clj/guestbook/test/db/core.clj#L13 [3]

guestbook.test.db.core

Tested 1 namespaces
Ran 4 assertions, in 1 test functions
3 failures

Results

guestbook.test.db.core
3 non-passing tests:

Fail in test-message
expected: 1
  actual: (2)

Fail in test-message
expected: {:name "test",
 :message "test",
 :timestamp #inst "2017-08-31T18:29:42.400-00:00"}
  actual: ({:name "name from form",
  :message "this is the message i entered into the form",
  :timestamp #inst "2017-08-31T18:29:26.477000000-00:00"})

Fail in test-message
expected: (empty? (db/get-messages))
  actual: (not
 (empty?
  ({:id 2,
    :name "name from form",
    :message "this is the message i entered into the form",
    :timestamp #inst "2017-08-31T18:29:26.477000000-00:00"})))
yogthos commented 7 years ago

Yeah I think this is the same cause as this issue.