This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Clojure: Expectations Before Run Hook
Feed Title: Jay Fields Thoughts
Feed URL: http://feeds.feedburner.com/jayfields/mjKQ
Feed Description: Blog about Ruby, Agile, Testing and other topics related to software development.
use generic example of deleting files or replacing logging
https://github.com/jaycfields/expectations/blob/master/test/clojure/expectations_options.clj
needs to be in test-directory specified in project.clj
expectations / test / clojure
The expectations library now supports calling an arbitrary number of custom functions before the test suite is run.
There are several reasons that you might want to call a custom function before the test suite is executed-
load sample data to a database
delete a temp directory
replace logging with standard out or /dev/null
As of version 1.4.24, expectations will execute any function that includes the following metadata {:expectations-options :before-run}. The following example should serve as a decent reference on how to add your own 'before-run' functions.
These functions can be defined anywhere; however, expectations looks in a default location for a configuration file. If expectations finds this configuration file it removes (what should be) the namespace and requires it with :reload. As a result, this configuration namespace will be removed and redefined with each expectations suite run.
The name of this default configuration file is expectations_options.clj (thus the namespace is expectations-options). Expectations looks for this file in the root test directory. If you have :test-paths ["test/clojure"] in your project.clj, then you'll want to create test/clojure/expectations_options.clj.
If you place your expectations_options.clj file in the correct location and you add the {:expectations-options :before-run} metadata to a function in the expectations-options namespace, your function should be run automatically the next time your test suite runs. You may want to start with a (println) just to verify that things are going as you expect.