Webrat 'within' bug
Reported by Yuval | March 16th, 2010 @ 05:08 AM
Webrat's within selector does not seem to work properly for more
than one element of the same kind.
Here's how to reproduce the problem while working with
cucumber:
An Admin feature:
Feature: Admin
In order to administer the site properly
As an admin
I want to browse and see admin links
Scenario: Show menu
Given I go to path "/admin"
Then I should see "Pages" within "a"
And I should see "Gallery" within "a"
And the path /admin contains the following only:
<%= link_to "Pages", "/" %>
<%= link_to "Gallery", "/" %>
<%= link_to "Articles", "/" %>
Running the tests with Cucumber: cucumber features
produces:
Feature: Admin
In order to administer the site properly
As an admin
I want to browse and see admin links
Scenario: Show menu # features/admin.feature:7
Given I go to path "/admin" # features/step_definitions/web_steps.rb:18
Then I should see "Pages" within "a" # features/step_definitions/web_steps.rb:150
And I should see "Gallery" within "a" # features/step_definitions/web_steps.rb:150
expected the following element's content to include "Gallery":
Pages.
<false> is not true. (Test::Unit::AssertionFailedError)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:48:in `assert_block'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:500:in `_wrap_assertion'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:46:in `assert_block'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:63:in `assert'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:495:in `_wrap_assertion'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:61:in `assert'
./features/step_definitions/web_steps.rb:156
(eval):2:in `within'
./features/step_definitions/web_steps.rb:151:in `/^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/'
features/admin.feature:10:in `And I should see "Gallery" within "a"'
Failing Scenarios:
cucumber features/admin.feature:7 # Scenario: Show menu
1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m0.049s
Thinking it is some type of issue with my syntax, I simply switch the order of the links around, so my scenario looks like this:
Scenario: Show menu
Given I go to path "/admin"
And I should see "Gallery" within "a"
Then I should see "Pages" within "a"
And the path admin contains the following:
<%= link_to "Gallery", "/" %>
<%= link_to "Pages", "/" %>
Running the test again:
Feature: Admin
In order to administer the site properly
As an admin
I want to browse and see admin links
Scenario: Show menu # features/admin.feature:7
Given I go to path "/admin" # features/step_definitions/web_steps.rb:18
And I should see "Gallery" within "a" # features/step_definitions/web_steps.rb:150
Then I should see "Pages" within "a" # features/step_definitions/web_steps.rb:150
expected the following element's content to include "Pages":
Gallery.
<false> is not true. (Test::Unit::AssertionFailedError)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:48:in assert_block'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:500:in
_wrap_assertion'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:46:in assert_block'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:63:in
assert'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:495:in _wrap_assertion'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/assertions.rb:61:in
assert'
./features/step_definitions/web_steps.rb:156
(eval):2:in within'
./features/step_definitions/web_steps.rb:151:in
/^(?:|I )should see "([^"]*)" within "([^"]*)"$/'
features/admin.feature:10:in `Then I should see "Pages" within "a"'
Failing Scenarios:
cucumber features/admin.feature:7 # Scenario: Show menu
1 scenario (1 failed)
3 steps (1 failed, 2 passed)
0m0.045s
Now the step that failed before magically succeeds and the next
step that succeeded before suddenly fails.
Magic, you say? I think I'll just call it a bug.
Thanks!
Comments and changes to this 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 (Sort)
- ↓↑ drag 326 Open Bugs
- ↓↑ drag 32 Open Patches
- ↓↑ drag 26 Open Feature Requests
People watching this ticket
- Nobody is watching this ticket.
Pages
- ↓↑ dragHome