[rspec-users] help me refactor a step for finding href in specific link

David Chelimsky dchelimsky at gmail.com
Wed Mar 31 19:09:53 EDT 2010

On Mar 31, 2010, at 5:13 PM, Oren Golan wrote:

> I want to verify the href is correct:
> <p class="website">
>    <a href="http://www.com.com">Website</a>
> </p>
> my step in the cucumber file:
> And the "website" class should have "www.happyhour.com"
> the step definition:
> Then /^the "([^\"]*)" class should have "([^\"]*)"$/ do |link, url|
>  response.should have_selector(".#{link}") do |site|
>    site.inner_html.include?(url).should be_true
>  end
> end
> it's doesn't look good and would like to hear suggestion for improving
> it.
> Thanks!

Cucumber has its own list: http://groups.google.com/group/cukes, so you may get more responses there.

I'd do something like this (incomplete and untested, but ....):

And "Website" should link to "www.happyhour.com"

Then /^"([^\"]*)" should link to "([^\"]*)"$/ do |text, href|
  response.should have_xpath(<figure out the xpath including @href and text()>)

More information about the rspec-users mailing list