#283 new
Joshua Scott

should_not inside have_selector fails

Reported by Joshua Scott | August 21st, 2009 @ 06:31 PM

When using should_not inside a have_selector block, the have_selector is returning the false message back to the should, which makes the test fail, when it should succeed.

html being searched:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div id="section"></div></body></html>
  it "should find the div" do
    response.should have_selector("#section")
  end

  it "should not find missing text in a have_selector block" do
    render "/admin/test/html.haml"
    response.should have_selector("#section") do |div|
      div.should_not contain("asdfjkl")
    end
  end

Which produces this output:

.F

1)
'/admin/test.html.haml should look right inside the div' FAILED
expected following output to contain a <#section/> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div id="section"></div></body></html>
./spec/views/admin/test.html.haml_spec.rb:12:
script/spec:10:

Finished in 0.076674 seconds

2 examples, 1 failure

As you can see, the second test is failing, even though it should succeed, since the contain("asdfjkl") should return false.

This:
http://github.com/cavalle/webrat/commit/79a716c5fc55c5de399c497c854...
seems to be a fix for a similar issue with have_xpath.

Comments and changes to this ticket

  • rap (at endymion)

    rap (at endymion) April 26th, 2010 @ 03:57 PM

    I had a problem that may be related. This test was failing when it should have passed:

    When /^I should see an enabled "([^\"]*)" for the user named "([^\"]*)"$/ do |action, name|
      user = User.find_by_first(name)
      response.should have_selector("#people__users-list-#{user.id}-row") do |scope|
        scope.inner_html.should have_tag("a", action)
        scope.inner_html.should_not have_tag("a.disabled", action)
      end
    end
    

    I was able to make it work simply by reversing the order of the inner_html tests:

    When /^I should see an enabled "([^\"]*)" for the user named "([^\"]*)"$/ do |action, name|
      user = User.find_by_first(name)
      response.should have_selector("#people__users-list-#{user.id}-row") do |scope|
        scope.inner_html.should_not have_tag("a.disabled", action)
        scope.inner_html.should have_tag("a", action)
      end
    end
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Pages