#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

  • nbenes

    nbenes August 27th, 2009 @ 03:50 PM

    I'm having a problem with this issue as well. A fix here would be much appreciated :)

  • Joshua Scott

    Joshua Scott August 28th, 2009 @ 09:52 AM

    @nbenes (and anyone else) Here's the workaround I'm using right now:

    it "should not find missing text in a have_selector block" do
      render "/admin/test/html.haml"
      response.should have_selector("#section")
      response.should_not have_selector("#section", :content => "asdfjkl")
    end
    

    This accomplishes the same thing as the test I was attempting. It doesn't work for searching multiple levels deep in the HTML structure, though.

  • ehartung

    ehartung November 24th, 2009 @ 08:22 AM

    Here's another workaround which is especially useful in case of nested have_selector() blocks.

      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 have_selector("#sub-section") do |subdiv|
            not subdiv.to_s.include?("asdfjkl")
          end
        end
      end
    
  • 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
    
  • Gary Greyling

    Gary Greyling July 28th, 2010 @ 04:37 AM

    • Milestone order changed from “0” to “0”

    Upgrading to Webrat 0.7.1 fixed it for me

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