轨道 3.1。 Capybara 的 Selenium 驱动程序无法捕获路由错误
当我在 Cucumber 的步骤定义中使用 visit
方法,然后通过 Capybara 的 Selenium 驱动程序运行该步骤时,尽管控制器未实现,但它还是通过了。
下面是一个示例:
功能
# features/one.feature
Feature: One
@selenium
Scenario: One
Given I visit the example page
步骤定义
# features/step_definitions/example_steps.rb
Given /^I visit the example page$/ do
visit example_path
end
路线
# config/routes.rb
Example::Application.routes.draw do
resource :example
end
控制器
未实现
结果
Feature: One
@selenium
Scenario: One
Given I visit the example page
1 scenario (1 passed)
1 step (1 passed)
0m18.162s
但是,当我使用 RackTest 驱动程序时,一切都会按预期工作,并且除非实现控制器,否则会出现路由异常。
这是相同的示例,但使用了 RackTest:
功能
# features/one.feature
Feature: One
@rack_test
Scenario: One
Given I visit the example page
结果
Feature: One
@rack_test
Scenario: One
Given I visit the example page
uninitialized constant ExamplesController (ActionController::RoutingError)
./features/step_definitions/example_steps.rb:2:in `/^I visit the example page$/'
features/one.feature:5:in `Given I visit the example page'
Failing Scenarios:
cucumber features/one.feature:4 # Scenario: One
1 scenario (1 failed)
1 step (1 failed)
如何强制 Capybara 在使用 Selenium 驱动程序时引发路由错误?
谢谢。
红宝石 1.9.2;
Ruby on Rails 3.1.0.rc1;
黄瓜0.10.3;
黄瓜导轨 0.5.0;
水豚1.0.0.beta1;
Selenium-webdriver 0.2.0。
When I use the visit
method in Cucumber's step definitions and then run the step through Capybara's Selenium driver it's passed despite the controller isn't implemented.
Here's an example:
Feature
# features/one.feature
Feature: One
@selenium
Scenario: One
Given I visit the example page
Step definition
# features/step_definitions/example_steps.rb
Given /^I visit the example page$/ do
visit example_path
end
Route
# config/routes.rb
Example::Application.routes.draw do
resource :example
end
Controller
isn't implemented
Result
Feature: One
@selenium
Scenario: One
Given I visit the example page
1 scenario (1 passed)
1 step (1 passed)
0m18.162s
However, when I use the RackTest driver all works as it expected to be and the routing exception is risen unless a controller is implemented.
Here's the same example but with the usage of RackTest:
Feature
# features/one.feature
Feature: One
@rack_test
Scenario: One
Given I visit the example page
Result
Feature: One
@rack_test
Scenario: One
Given I visit the example page
uninitialized constant ExamplesController (ActionController::RoutingError)
./features/step_definitions/example_steps.rb:2:in `/^I visit the example page$/'
features/one.feature:5:in `Given I visit the example page'
Failing Scenarios:
cucumber features/one.feature:4 # Scenario: One
1 scenario (1 failed)
1 step (1 failed)
How can I force Capybara to raise the routing error when using the Selenium driver?
Thanks.
Ruby 1.9.2;
Ruby on Rails 3.1.0.rc1;
Cucumber 0.10.3;
Cucumber-rails 0.5.0;
Capybara 1.0.0.beta1;
Selenium-webdriver 0.2.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Selenium 驱动程序在收到“失败”http 代码(如 500)时不会失败。如果您将 config/environments/test.rb 保留为默认值,则应该有一行 config.action_dispatch.show_exceptions = false。因此,您可以将其设置为 true,否则您必须添加更多步骤以确保页面实际显示您期望的内容。
The Selenium driver does not fail when it receives a "failure" http code like 500. If you left your config/environments/test.rb at it's defaults, there should be a line config.action_dispatch.show_exceptions = false. So you can either set this to true or you would have to add some more steps to ensure the page is actually showing what you expect.