Skip to content

Instantly share code, notes, and snippets.

@chrisbraddock
Created December 22, 2011 19:15
Show Gist options
  • Save chrisbraddock/1511475 to your computer and use it in GitHub Desktop.
Save chrisbraddock/1511475 to your computer and use it in GitHub Desktop.
Write Better Cukes
# question regarding http://blog.steveklabnik.com/2011/12/20/write-better-cukes-with-the-rel-attribute.html
#
When /^I choose to edit the article "([^"]*)"$/ do |article_name|
article = Article.find_by_name(article_name)
find("//a[@href='#{edit_article_path article}']").click
end
@steveklabnik
Copy link

This ties the editing concept to your titles. It also loses all of the natural language aspect...

@chrisbraddock
Copy link
Author

In considering doing what you're doing I've been concerned (perhaps wrongly) that there might be another edit article link on a tested page (now or in the future) and the test doesn't account for that.

I guess I was more curious as to what you thought about the Cuke step using the same code that will (likely) be used to generate the on-page link (i.e. "edit_article_path article").

To that end and to remove the article_name bit from the equation I guess you could consider something like:

When /^I choose to edit the article$/ do
  article = @article # assigned in earlier step
  find("//a[@href='#{edit_article_path article}']").click
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment