我正在使用带有 Cucumber、Capybara 和 Factory_Girl 的 Rails 3。我正在尝试按照 HTML 表中的一行的“显示”链接进行测试。我正在使用以下语法:
And I follow "Show" within "Net 30"
我给了我以下错误:
unexpected '30' after 'DESCENDANT_SELECTOR' (Nokogiri::CSS::SyntaxError)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `_racc_do_parse_c'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `__send__'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/racc/parser.rb:99:in `do_parse'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
features/view_payment_terms.feature:10:in `And I follow "Show" within "Net 30"'
这是失败的完整 Cucumber 脚本:
Feature: View Payment Terms
In order to view payment terms
As a user
I want to view payment terms
Scenario: View Payment Terms
Given there is a payment term named "Net 30"
And there is a payment term named "Net 60"
When I go to the "payment terms screen"
And I follow "Show" within "Net 30"
Then I should see "Terms description: Net 30"
如果我将该行更改为只说:
And I follow "Show"
它通过没有错误。我查看了 Capybara 附带的 web_steps.rb,我使用的似乎是正确的:
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
with_scope(selector) do
click_link(link)
end
end