Checking a tab (<li><a>tab_name</a></li>) doesn't have an ID of "current" (li#current)

2 views
Skip to first unread message

steven_noble

unread,
Oct 3, 2009, 2:11:40 AM10/3/09
to webrat
I have a scenario containing the following lines:

And the "Project: “Clothes line" tab should be current
And the "All projects (4)" tab should not be current

The step definitions are:

Then /^the "([^\"]*)" tab should be current$/ do |content|
response.should have_selector("li#current") do |li|
li.should contain(content)
end
end

Then /^the "([^\"]*)" tab should not be current$/ do |content|
response.should have_selector("li#current") do |li|
li.should_not contain(content)
end
end

The generated output contains:

<li class="all_projects"><a href="/projects">All projects (4)</a></
li>
<li class="one_project" id="current">Project: “Clothes line that
can be raised one story”</li>

The "should be current" step passes. The "should not be current" step
fails. It seems this is because it tells WebRat to check the following
is present:

<li#current/>

How do I tell WebRat to check the following is true?

<li#current><a>contains any text other than the tab_name</a></li>

Many thanks,

Steven.

steven_noble

unread,
Oct 3, 2009, 11:43:34 PM10/3/09
to webrat
I've created an acceptable workaround, which is to assign an ID of
"not_current" to any <li> with an ID of "current".

The step definition is now:

Then /^the "([^\"]*)" tab should not be current$/ do |content|
response.should have_selector("li#not_current") do |li|
li.should contain(content)
end
end

s.

Andrew Premdas

unread,
Oct 11, 2009, 2:29:25 PM10/11/09
to web...@googlegroups.com
2009/10/4 steven_noble <ste...@snoble.net>


I've created an acceptable workaround, which is to assign an ID of
"not_current" to any <li> with an ID of "current".

The step definition is now:

   Then /^the "([^\"]*)" tab should not be current$/ do |content|
     response.should have_selector("li#not_current") do |li|
       li.should contain(content)
     end
   end

s.

This makes your html invalid as you now have multiple elements with the same id!. You should use an extra class instead e.g.

<li class="project current">

All best

Andrew
Reply all
Reply to author
Forward
0 new messages