Most people keep state between steps using instance variables, but I've seen it done using a hash before. Keeping the keys visible in the steps as you seem to be doing is a good idea so there's no magic going on that you can't see from the features. I think you're basically taking the right approach.
I have a couple of thoughts. One is that you seem to have quite a lot of data floating around in your scenarios from the Background, which isn't being used in all of the scenarios. I wonder if that's contributing to the problem. Could it help to either split the feature (making list and delete their own smaller, more focussed features) or to simply move some of the steps out of the background back into the scenarios they're actually used in?
Another question I have which I'm afraid isn't clear to me from your post is exactly what pain you're feeling from this. Are you just losing confidence in your approach, or are you actually finding things hard to read and maintain? Or some other problem?
>
> Any help/advice would be greatly appreciated, thanks!
>
> Devan
>
>
>
> --
> 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.
>
cheers,
Matt
>
>
> On Jul 20, 8:44 pm, Matt Wynne <m...@mattwynne.net> wrote:
>
>> Most people keep state between steps using instance variables, but I've seen it done using a hash before. Keeping the keys visible in the steps as you seem to be doing is a good idea so there's no magic going on that you can't see from the features. I think you're basically taking the right approach.
>
> Thanks for the feedback.
>
> We got a little nervous with this hash approach as it felt like
> variable names (essentially) were leaking into the feature files, but
> it's good to know we're not out in left field.
>
> We weren't real fond of the instance variables as it seems like this
> couples your step definitions together. Because those are essentially
> in a global namespace (any regex could match in any file), the process
> of tracking down the dependencies for a step you wish to re-use is a
> little scary, as is the possibility of unintentionally clobbering an
> instance variable you didn't intend to.
>
>>
>> I have a couple of thoughts. One is that you seem to have quite a lot of data floating around in your scenarios from the Background, which isn't being used in all of the scenarios. I wonder if that's contributing to the problem. Could it help to either split the feature (making list and delete their own smaller, more focussed features) or to simply move some of the steps out of the background back into the scenarios they're actually used in?
>
> True, we could definitely split the setup up into more features quite
> a bit I think.
>
>>
>> Another question I have which I'm afraid isn't clear to me from your post is exactly what pain you're feeling from this. Are you just losing confidence in your approach, or are you actually finding things hard to read and maintain? Or some other problem?
>
> We struggle with a few issues, but the above problem with simply
> passing data from a Given to When/Then while still re-using steps and
> not creating a regex mess, is a big piece of it. To some extent we're
> concerned we're inventing bad solutions to workaround the absence of
> classes, fixtures, methods, variables and scoping, etc.
You do realise you can use your own classes and method in the step definitions don't you? Have a look at libraries like webrat and aruba for some very generic implementations of this idea. I guess what you've done with your hash is a start for this, but you could build up your own DSL library specific to your product, and have the step definitions depend on that. This wiki article will also give you some tips:
http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world
Or, are you saying you'd prefer to be able to model each step definition as a separate class instance? That's an interesting idea.
Obviously, as you've said, all the step definitions currently run in the same namespace, so feasibly any of them could be running in any given scenario. We've talked about being able to use tags to namespace step definitions, so that you could ringfence off groups of step definitions to only be available for scenarios with certain tags. Would that help you?
> Any thoughts on the Background test setup in general? In our case
> we're leaking quite a bit of this into feature files when really it
> has little to do with the behaviour we want to test. But because the
> before/after blocks in step definitions are globally run with every
> scenario in every feature (not really desired), this seems like the
> only place it can go?
Tags are probably the answer here. Have you seen how the @javascript tag in Capybara works? You can specify Before / After hooks per tag, so run can attach setup code to certain scenarios by tagging them.
> Some team members also find the process of text -> regex -> code
> unpleasant to write, re-use, and maintain, but that's not a universal
> opinion and probably just a fact of life if you're using cukes.
The idea ought to be that you spend less and less time in the step defs / regex because you've built up a nice re-usable library of step definitions. Certainly on the biggest project I've built with Cucumber, we saw the rate of step definition creation flatten off a great deal once we got up and running. I wonder whether part of this is just a reflection of the maintenance headaches you're experiencing with the step definitions.
>
> Thanks again!
>
> Cheers,
> On Jul 21, 7:05 am, Matt Wynne <m...@mattwynne.net> wrote:
>> On 21 Jul 2010, at 01:54, dgoodwin wrote:
>>
>> You do realise you can use your own classes and method in the step definitions don't you? Have a look at libraries like webrat and aruba for some very generic implementations of this idea. I guess what you've done with your hash is a start for this, but you could build up your own DSL library specific to your product, and have the step definitions depend on that. This wiki article will also give you some tips:
>>
>> http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world
>>
>> Or, are you saying you'd prefer to be able to model each step definition as a separate class instance? That's an interesting idea.
>
> No, more so about how in the past we've become accustomed to using a
> unit test framework for writing our functional tests. So our test code
> would be organized into a test suite and cases, with a defined setup/
> teardown, inheritance, and scope we're familiar with from regular
> coding.
Okay. Remember each scenario runs inside an instance of an object (known as the World) which is destroyed at the end of the scenario. You can mix in specific behaviour to the world based on tags using the before hooks:
Before('@authentication') do
World(AuthenticationHelper)
end
It's admittedly not as neat as having classes in xunit, but it might help give you some help to keep on top of the dependencies between steps.
The other thing you could consider doing is breaking up your actual features folder into separate folders / test runs. You can put common step definition code into a shared folder and require it from the step_definitions folders of the separated features folders. This might again give you a tool to understand and clarify where the seams / dependencies are.
>
>>
>> Obviously, as you've said, all the step definitions currently run in the same namespace, so feasibly any of them could be running in any given scenario. We've talked about being able to use tags to namespace step definitions, so that you could ringfence off groups of step definitions to only be available for scenarios with certain tags. Would that help you?
>
> Probably not a terrible amount of help with the step definitions but I
> could definitely see that being useful below where you mention tagging
> the before/after blocks.
>
>>
>>> Any thoughts on the Background test setup in general? In our case
>>> we're leaking quite a bit of this into feature files when really it
>>> has little to do with the behaviour we want to test. But because the
>>> before/after blocks in step definitions are globally run with every
>>> scenario in every feature (not really desired), this seems like the
>>> only place it can go?
>>
>> Tags are probably the answer here. Have you seen how the @javascript tag in Capybara works? You can specify Before / After hooks per tag, so run can attach setup code to certain scenarios by tagging them.
>>
>>> Some team members also find the process of text -> regex -> code
>>> unpleasant to write, re-use, and maintain, but that's not a universal
>>> opinion and probably just a fact of life if you're using cukes.
>>
>> The idea ought to be that you spend less and less time in the step defs / regex because you've built up a nice re-usable library of step definitions. Certainly on the biggest project I've built with Cucumber, we saw the rate of step definition creation flatten off a great deal once we got up and running. I wonder whether part of this is just a reflection of the maintenance headaches you're experiencing with the step definitions.
>
> Quite possible we just haven't reached that point yet.
>
> Thanks for the suggestions!
>
> Cheers,
>
> Devan
>