如何让 Capybara @javascript 标签在 Cucumber on Rails 3 项目中正确执行?

发布于 2024-09-14 13:03:12 字数 908 浏览 5 评论 0原文

我在新的 Rails 3 项目中将 Webrat 替换为 Capybara。我在这里浏览了 Tim Riley 的精彩帖子( http:// /openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ),还克隆了他的存储库,执行了示例黄瓜功能,并看到浏览器窗口打开了。因此,整个 Cucumber、Capybara、Selenium 堆栈在这种情况下似乎工作得很好。

但是,如果我创建一个新的 Rails 3 项目,运行设置一个类似的示例项目,并使用 @javascript 注释场景,则浏览器窗口不会触发,并且 Cucumber 场景会失败,并显示通常的 Command failed with status ( 1) 事件(在失败或待处理步骤的情况下,Cucumber 根据设计触发该事件,以便 CI 工具受益)。

除了 Capybara 提供的 @javascript 功能外,所有其他功能都可以正常工作。

我错过了一些非常明显的事情吗?有没有办法让 BDD 新手更深入地研究问题(堆栈跟踪仅显示 Cucumber 失败时的标准 rake 错误)。

  • rvm 1.9.2-head
  • gem 'rails', '3.0.0.rc'
  • gem 'cucumber'
  • gem 'cucumber-rails'
  • gem 'capybara'
  • gem 'culerity'
  • gem 'celerity', :require =>;零

I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, Selenium stack seems to work fine in that instance.

However if I create a new Rails 3 project, run through setting up a similar example project, and annotate a Scenario with @javascript the browser window does not fire, and the Cucumber Scenario just fails with the usual Command failed with status (1) event (which, in the instance of failing or pending steps, Cucumber triggers by design for the benefit of CI tools).

Apart from the @javascript functionality provided by Capybara, all other features work fine.

Am I missing something incredibly obvious? Is there a way for a BDD newcomer to look deeper into the issues (the stack trace just shows the standard rake error when Cucumber fails).

  • rvm 1.9.2-head
  • gem 'rails', '3.0.0.rc'
  • gem 'cucumber'
  • gem 'cucumber-rails'
  • gem 'capybara'
  • gem 'culerity'
  • gem 'celerity', :require => nil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

蒗幽 2024-09-21 13:03:12

问题实际上是 cucumber-rails 和对 DatabaseCleaner 的依赖缺失: http:// /github.com/aslakhellesoy/cucumber-rails/issues#issue/36

将 @javascript 标签添加到 Cucumber 功能时会出现此问题。默认情况下,黄瓜选项会抑制警告我这一事实的警告。将 config/cucumber.yml 更新为:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"< /code>

运行 Cucumber 时显示错误:未初始化的常量 DatabaseCleaner (NameError)

这种情况下的快速修复是将 gem 'database_cleaner' 添加到项目的 Gemfile.

The issue is actually with cucumber-rails and a missing dependency on DatabaseCleaner: http://github.com/aslakhellesoy/cucumber-rails/issues#issue/36

The issue is manifested when adding a @javascript tag to a cucumber feature. By default the cucumber options suppress the warnings that would have alerted me to the fact. By updating config/cucumber.yml to:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"

the error is shown when running cucumber: uninitialized constant DatabaseCleaner (NameError)

The quick fix in this case is to add gem 'database_cleaner' to the project's Gemfile.

踏月而来 2024-09-21 13:03:12

水豚很“懒”,因为它会在实际需要时首先打开浏览器窗口。如果您实际上正在做一些需要浏览器的事情,Capybara 不会打开浏览器。

Capybara is "lazy" in that it will open the browser window first when it is actually needed. If you're actually doing something that would require a browser, Capybara won't open one.

小兔几 2024-09-21 13:03:12

也许您还没有安装 mongrel gem。浏览器自动化在某种程度上无法与 webrick 一起使用,我也经历过您在此处描述的相同的无声故障。

添加

将gem 'mongrel', '>= 1.2.0.beta.1'

到我的 Gemfile 中解决了这个问题。

Maybe you have not installed the mongrel gem. The browser automation is somehow not working with webrick and i have experienced the same silent failing the you describe here.

Adding

gem 'mongrel', '>= 1.2.0.beta.1'

to my Gemfile solved it.

放手` 2024-09-21 13:03:12

我制作了一个有关如何配置的示例应用程序:github.com/lailsonbm/contact_manager_app/

I made an example app on how to configure that: github.com/lailsonbm/contact_manager_app/

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