mount

jarppe 2016-08-01T15:30:59.000350Z

Should mount/stop restore previous states that were overridden using mount/start-with?

jarppe 2016-08-01T15:33:04.000351Z

I'm trying to run tests within the same process where I have development REPL

tolitius 2016-08-01T15:45:14.000352Z

@jarppe: right mount/stop would "restore" previous states overridden with mount/start-with or swap. are you running tests after you did mount/stop, so any of the dev states would not interfere?

tolitius 2016-08-01T15:48:13.000354Z

you can also start a standalone repl just for tests that would watch for changes and rerun. this would be a lot cleaner than running tests within the same repl as you develop. depending on your build tool you can use either: https://github.com/jakemcc/lein-test-refresh or https://github.com/adzerk-oss/boot-test (i.e. boot watch speak test)

jarppe 2016-08-01T15:59:55.000356Z

@tolitius: I have app started with (mount/start), the in my tests I try to override DB with (mount/start-with {#'..../db test-db}) and after the tests are done I call (mount/stop). How ever, after the (mount/stop) it seems that all states are in mount.core.NotStartedState state.

jarppe 2016-08-01T16:00:52.000357Z

I agree that in general running tests in separate process is better most of the time

tolitius 2016-08-01T16:12:54.000358Z

ah.. yes, (mount/stop) would stop all the states, and then would bind them to a NotStartedState

tolitius 2016-08-01T16:13:42.000359Z

so the state definitions would still be restored: i.e. your db state's start and stop functions will revert back from the test ones

tolitius 2016-08-01T16:14:00.000360Z

but the states values will be NotStartedState after (mount/stop)

jarppe 2016-08-01T16:16:55.000361Z

Right, that clears what's going on. Is there some way to restore the previous state values?

tolitius 2016-08-01T16:18:05.000362Z

hm.. there should not have been any values previously, since you would need to run (mount/stop) before running the tests not to clash the test states run with the dev values

tolitius 2016-08-01T16:18:27.000363Z

i.e. if you have a started db conn in dev, it would need to be stopped before running a test with it

jarppe 2016-08-01T16:19:19.000364Z

Yes, that works. Stop everything before tests and start after tests.

jarppe 2016-08-01T16:20:08.000365Z

It's just a bit difficult to figure out where this start/stop should happen so that I could run tests both in dev repl, and stand alone "lein test".

tolitius 2016-08-01T16:20:25.000366Z

does it take time (to restart after tests), or there are other reasons you would not want to restart?

tolitius 2016-08-01T16:21:25.000367Z

if you run your tests in a standalone repl, unless your tests use the same connections (i.e. same db url user/pass), you don't have to stop anything in your dev repl

jarppe 2016-08-01T16:22:23.000369Z

No, stop & start is fast, it's just to figure out where to do stop and start. If I put them into clojure.test/use-fixtures the get executed in standalone test runs as well.

jarppe 2016-08-01T16:23:08.000370Z

I think I'll just run tests on separate process, that's easier.

tolitius 2016-08-01T16:25:00.000371Z

🙂 and cleaner. but just to recap: you can call (mount/stop) before running any tests and you should be good. so whether it is in fixtures or in repl, both should work. (mount/stop) calls take no time if there is nothing to stop, so you can include them before each test if that helps your workflow.

jarppe 2016-08-01T16:25:44.000373Z

Right, thanks for your help.

tolitius 2016-08-01T16:26:36.000374Z

and if you run it in a separate repl, I would recommend lein-test-refresh or boot watch speak test: let it work for you rather than manually rerun them every time