Let’s say you have a resource called Article. On the index page, you have many articles listed. In one scenario, I have this Cucumber step:
When /^I activate the edit article switch for the article "(.+)"$/ do |name|
I’m trying to identify that specific article – i.e. clicking the “edit” button for that specific article. I’ve been thinking about using the “within” helper of capybara, but I don’t feel like that’s the solution. I somehow need to find the name of the article on the page and then click that article’s particular edit button… see what I mean?
If anyone has a clean solution, I’d appreciate knowing it. Thanks in advance.
What I do for this kind of thing is write a step like this:
My step definition then looks like this:
In my views I’m clearly defining the id on some parent element that will sufficiently scope calls like this. This pattern keeps you from having to get too dirty in the cukes themselves, while still giving you a certain degree of flexibility. For example: