I use rspec 2.6.0 and Capybara 1.1.1 for acceptance testing.
With a view like the following:
<tr >
<td>Team 3 Name</td>
<td>true</td>
<td><a href="/teams/3">Show</a></td>
<td><a href="/teams/3/edit">Edit</a></td>
<td><a href="/teams/3">Deactivate</a></td>
</tr>
<tr >
<td>Team 4 Name</td>
<td>true</td>
<td><a href="/teams/4">Show</a></td>
<td><a href="/teams/4/edit">Edit</a></td>
<td><a href="/teams/4">Deactivate</a></td>
</tr>
I want to write an acceptance test that states: "Team 3 does NOT have the 'Deactivate' link." I expect the following to fail:
within('tr', :text => 'Team 3 Name') do |ref|
page.should_not have_selector('a', :text => 'Deactivate')
end
But it passes. To further test what is going on, I wrote the absurd:
lock = false
within('tr', :text => 'Team 3 Name') do |ref|
page.should have_selector('a', :text => 'Deactivate')
page.should_not have_selector('a', :text => 'Deactivate')
lock = true
end
lock.should be_true
Which passes as well.
I am assuming from this that the scope the have_selector() call is using is not limited by the within() block, but I am not sure why this is. The capybara documentation uses this pattern and does not seem to mention any gotchas. What is the correct way to use within to limit the scope of my select? Thank you. /Salernost
page
is nil by some strange coincidence, or put in a debugger line at the top of the test so you can get to a console and output the value ofpage
, or added the stepAnd show me the page
so your browser will show you a copy of the page in the state it's in right before it runs this test? If so, what is the test framework actually seeing? – jefflunt