轨道 3.1。 Capybara 的 Selenium 驱动程序无法捕获路由错误

发布于 2024-11-09 18:08:21 字数 1765 浏览 0 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-11-16 18:08:21

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文