Question

The following works just fine:

Then /^I should see a button called "([^\"]*)"$/ do |name|
  response.should have_selector("li") do |li|
    li.should have_selector("a") do |a|
      a.should contain(name)
    end
  end
end

Now I need to complement it with a step like this:

Then /^I should not see a button called "([^\"]*)"$/ do |name|
   [snip...]
end

The standard "And I should not see" is not satisfactory, as it will pick up the target phrase anywhere in the page -- not just within buttons. I specifically need to check that no button with the target text are present.

My first instinct was to try something like this:

Then /^I should see a button called "([^\"]*)"$/ do |name|
  response.should have_selector("li") do |li|
    li.should have_selector("a") do |a|
      a.should_not contain(name)
    end
  end
end

But of course that will pass as long as there's any button on the page that does not include the target text, even if there are also one or more buttons that do include the target text.

Your thoughts?

Many thanks,

Steven.

Was it helpful?

Solution 2

Problem solved! I gave every control a class of "control", then wrote this step definition:

Then /^I should not see a control called "([^\"]*)"$/ do |name|
  response.should have_selector("a.control", :content => name, :count
=> 0)
end

Of course, this presumes I'm happy giving them all a class of "control"...

s.

OTHER TIPS

You can use assert_not_contain (and maybe not_contain but I doubt it as it's not in the rdoc).

a.should assert_not_contain(name)

Are your buttons actually links? For buttons (where there is a submit value), I use:

assert_have_selector "input[type=submit][value=\"#{text}\"]"

and:

assert_have_no_selector "input[type=submit][value=\"#{text}\"]"

hth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top