Yes. Before and After hooks run before and after each and every scenario.
> Do you know how I can structure my code so that before and after are
> only been invoked once for many scenarios?
>
What is it that you want to do once, and why do you want to do it only once?
Cheers,
Aslak
> Cheers
>
> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>
you can also google for "cucumber seed data"
jon
blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA
Yianna said the following on 2/28/12 10:09 AM:
On 02/28/2012 01:18 PM, Jon Kern wrote:
> have you explored DatabaseCleaner and Cucumber?
I haven't tried using that stuff with the cucumber-jvm jruby backend,
I don't know how it'd behave. It might work, but the necessary hooks
might be missing. It'd also depend on how DatabaseCleaner talks to the
database and such.
Good idea for ruby, but it might not work in cucumber-jvm.
David
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGcBAEBAgAGBQJPTSqxAAoJEMnf+vRw63ObUncL/2+1uJ48bDgDI2AbHF7nY3bX
T3P+Hn86y0ocDjhc8YLTirNPol2UF9trWqQzGTD4jMbNXiGiDqBxjxdija4//N/Z
cGs/Y91XGG51atAhKLUxcyk1BLJq3bynyS+MeACfS/i0VC2ryUjnT5l4/FaTnnD7
0mp89DWbtUUm7nV3+ECAtzXSuc+KbYubguhPHyTLruCPGcWHe91dUUc+8mxr4cK+
KjbjYm/Sz3R2Ju/zdwCGFbxpvfJgA4YjtrOJYTdLtjJ/nzxeSd3jP95SOC9Pn4CD
u8J0y30FQxASR3+Ph7APmd5rh5nY6MG7ninsaySCQHBWnCLAHmfFgpnZ7pV97nUE
9iaILf9gq/MN2lwpLqrpnmmitfvxWxLYWiRyytUI+Xs/B2QUmmg0uM8mBNBv9BcF
exgrjr9LVK7xh1CuR3NcM4NHSo1Pc9sUpfbWre2DXmPsLLZLj7l5pOPh2JTCB+gI
qdGeDEru55ElZM0knJI9ap0EugUM6GX9vNx8EsFvDA==
=ox10
-----END PGP SIGNATURE-----
> We
> need this because we have different setup for different types of tests, but
> still want to perform all tests in a single Cucumber run.
You could annotate features or single scenarios and write a tagged
before (scenario) hook that would run before every scenario within an
annotated feature and every annotated scenario. In my opinion,
features represent the point of view of the business, hooks are
technical details, related to step definitions.
There is a rejected pull request to Cucumber-JVM on adding feature
hooks: https://github.com/cucumber/cucumber-jvm/pull/295
> George, I disagree with your assertion that this is "a special case that is
> not often needed". There does seem to be significant interest in this
> feature, and you might want to count not only current Cucumber users, but
> others who may have decided not to use Cucumber, in part at least because
> this was a need they had. It may very well be that Cucumber is targeted at a
> specific group, and I acknowledge that it's not my place to have any
> expectations otherwise, but I just wanted to express my view so that it is
> available for consideration.
>
> * * *
>
> Regarding implementing before_all functionality myself, I now have a working
> solution in my Ruby/Cucumber testing. I use a class method (so that it is
> globally available, but does not pollute the global namespace). This method
> manages a set of initialization group keys internally (currently, I use
> __FILE__ as the key, but anticipate needing to be more precise later). These
> keys are needed because the setup and teardown may need to be done multiple
> times in a given Cucumber run (e.g. once for each of 2 feature files). So I
> can call MyInitializationClass.init_once(__FILE__), and the initialization
> will only be performed if it has not yet been sent that key. I think this is
> the best I'm going to get for my needs, but would appreciate any suggested
> improvements.
Can't understand why the initialization should depend on features, and
it's difficult to suggest an alternative without any context.
Step
definitions depending on features is usually a test smell, as
technical details should be separated from the logical grouping of
scenarios in features.
> My problem with this and any other solution I can think of is that, in my
> opinion, all of them are less intention revealing, more complex, more
> verbose, and/or more error prone than a built-in Cucumber before_all would
> be.
>
> * * *
>
> Paolo, regarding your statement that if I want it, I should write it myself,
> you're right, of course. However, this unfortunately is not likely to
> happen, since I suspect the time I would need to invest just to understand
> the source base well enough to present an intelligent solution would
> probably be prohibitive for me. In contrast, someone already familiar with
> the code base would probably know exactly where this modification should go,
> what gotchas to look out for, etc. In addition, even if I were to provide a
> patch, it might still not be accepted, either because it was not a good
> technical fit, or there may be a philosophical opposition to it. I do
> realize that this is open source software and I am not a paying customer, so
> can't complain if I don't do it myself.
It's always good to check in the mailing list before working on a new
feature. No one was able to provide an example of feature hooks that
cannot be already handled with tags and hooks, or other techniques.
> George, I disagree with your assertion that this is "a special case that is
> not often needed". There does seem to be significant interest in this
> feature, and you might want to count not only current Cucumber users, but
> others who may have decided not to use Cucumber, in part at least because
> this was a need they had. It may very well be that Cucumber is targeted at a
> specific group, and I acknowledge that it's not my place to have any
> expectations otherwise, but I just wanted to express my view so that it is
> available for consideration.
>
> * * *
>
> Regarding implementing before_all functionality myself, I now have a working
> solution in my Ruby/Cucumber testing. I use a class method (so that it is
> globally available, but does not pollute the global namespace). This method
> manages a set of initialization group keys internally (currently, I use
> __FILE__ as the key, but anticipate needing to be more precise later). These
> keys are needed because the setup and teardown may need to be done multiple
> times in a given Cucumber run (e.g. once for each of 2 feature files). So I
> can call MyInitializationClass.init_once(__FILE__), and the initialization
> will only be performed if it has not yet been sent that key. I think this is
> the best I'm going to get for my needs, but would appreciate any suggested
> improvements.
Can't understand why the initialization should depend on features, and
it's difficult to suggest an alternative without any context.
I understand what you're saying; the feature boundary is somewhat artificial; I just think it's the least bad of all the alternatives. And since a feature file is intended to be a set of logically related tests, it's a likely candidate for locating that boundary.
Parameterized tags could help; so could the ability to programmatically examine all the tags used in the current suite. Then the code could look to see if this test were the last scenario to run with a given key; but I don't know Cucumber, and don't know if this level of introspection is possible or feasible.
I wish someone else could join this thread, as it seems we have
reached a point where Keith and I agree to disagree. It would be good
to have others' point of view, especially from members of the Cucumber
team and people that have been using it for years.
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
In the java world you could try DBUnit - it hasn't had much done to it
recently, but seems to work.