Reuse settings and turn off with a background in the middle

I have a number of average facts that have settings / breaks that are almost, but not quite, completely identical.

(against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-access)) (after :contents (teardown!)] (facts "about this thing i am testing " ; ... )) (against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-other-access)) (after :contents (teardown!)] (facts "about this other thing i am testing " ; ... )) 

I would like to wrap the backgrounds in something reusable and preferably parameterizable so that I can reuse them, but I am having problems with this. Midier tells me that nothing but the above is the expected shape of the background.

+4
source share
1 answer

There is no way in Midje to do what you ask built into it. If you like it, consider adding it as a problem: https://github.com/marick/Midje/issues?sort=updated&direction=desc&state=open&page=1

The solution is to create your own macro for this. (Unverified)

 (defmacro against-my-background [docstring & body] `(against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-access)) (after :contents (teardown!)] (facts ~docstring ~@body ))) ;; usage (against-my-background "about this thing i am testing" (fact (foo) => :bar) (fact (foo) =not=> :baz)) 
+2
source

Source: https://habr.com/ru/post/1395907/


All Articles