-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spies don't work in before-all
#180
Comments
This is actually documented in Trying to defines spies in before-all is supposed to cause an error. You should also see #122 for more background information. |
What are you trying to achieve with the spy in (describe "A suite"
:var (callcount)
(before-each
(spy-on 'some-function :and-call-fake (lambda () (incf callcount))))
(it "with a spec"
(some-function))) |
Oh, so sorry! I didn't check the documentation carefully enough! And yes, indeed, it does print an error. I expected something like this to work: (describe "A suite"
(before-all
(spy-on 'a-function :and-call-fake (lambda () t))
(very-expensive-thing-that-runs-once-that-calls-a-function))
(it
"generates the right XYZ in the buffer"
t)
(it
"correctly called the spy with whatever"
t)
(it
"Does the right ABC in the buffer"
t)) In other words, I would like to run some expensive thing once, and during that thing, I would want to spy on the various things it calls. Then, in each Now, yes, I could write that as a bunch of assertions all in one Would you be open to extending spies to be supported at the |
I wont commit to accepting a PR until I've seen it:) I'm a bit hesitant to change how spies work. At the moment they will be reset - including call statistics - at the end of each But if you can figure out a way to deal with that I'm not opposed to the feature as such. It looks like what you want is similar to Pythons subtests. |
Hm, maybe #13 is also relevant here. |
Haha, of course, but I really just meant if you were interested in the direction. Hm, my read of subtests is that it is a way to repeat a test against different repeating input. I'm more interested in testing different aspects of "one run" in multiple "it" blocks. It's not so much I want to carry state or repeat things or anything like that. I think it's just an organizational thing; perhaps it comes from web development:
is obviously equivalent to
but the former is laid out nicer and the reporting is better, I think. anyway, I think I will give it a go. Spyies can report and be reset in the after all of the suite, I think it's conceptually the same as having them reset in between each it. Will report back how it turns out. |
I spent a hot minute quickly debugging into this, and it's because
before-all
doesn't run in abuttercup-with-cleanup
, sobuttercup--add-cleanup
doesn't work.I think it would be nice if spies worked in
before-all
, as well asbefore-each
.For now, I've worked around this by making a nested describe with just one before-each in the parent suite.Oh, that doesn't actually do what I want. :-(The text was updated successfully, but these errors were encountered: