Rails 3 Cucumber/Webrat 在简单的“Given”上失败:我是否设置了错误的东西?

发布于 2024-10-10 00:11:40 字数 1259 浏览 4 评论 0原文

我的功能文件:

Feature: home page links

  Background: I am on the home page
    Given I am on the home page

  Scenario: I visit the about page
    When I follow "About"
    Then I should be on the about page

在我的 paths.rb 中,我有

when /the home\s?page/ then root_path

并且 rake 路线给出:

    root  /(.:format)         {:controller=>"home", :action=>"home"}

当我尝试运行“bundle exec cucumber”时,我收到消息:

undefined local variable or method `controller' for #<HomeController:0xb29583c> (ActionView::Template::Error)
<a lot of crap>
./features/step_definitions/web_steps.rb:16:in `/^(?:|I )am on (.+)$/'
features/home_page.feature:4:in `Given I am on the home page'

Failing Scenarios:
cucumber features/home_page.feature:6 # Scenario: I visit the about page

这是一个微不足道的测试,但我不知道从哪里开始调查此故障。有什么想法吗?谢谢。


另外,我的 Gemfile:

source :rubygems

gem "rails", "~>3.0"
gem "haml", "~>3.0"

group :test do
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'nokogiri'
  gem 'webrat'
end

group :development do
  gem "rspec-rails", "~>2.0.pre"
  gem "heroku"
  gem "will_paginate", "~>3.0.pre2"
end

My feature file:

Feature: home page links

  Background: I am on the home page
    Given I am on the home page

  Scenario: I visit the about page
    When I follow "About"
    Then I should be on the about page

In my paths.rb, I have

when /the home\s?page/ then root_path

and rake routes gives:

    root  /(.:format)         {:controller=>"home", :action=>"home"}

When I try to run "bundle exec cucumber", I get the message:

undefined local variable or method `controller' for #<HomeController:0xb29583c> (ActionView::Template::Error)
<a lot of crap>
./features/step_definitions/web_steps.rb:16:in `/^(?:|I )am on (.+)$/'
features/home_page.feature:4:in `Given I am on the home page'

Failing Scenarios:
cucumber features/home_page.feature:6 # Scenario: I visit the about page

It's a trivial test, but I don't know where to start investigating this failure. Any ideas? Thanks.


Also, my Gemfile:

source :rubygems

gem "rails", "~>3.0"
gem "haml", "~>3.0"

group :test do
  gem 'cucumber'
  gem 'cucumber-rails'
  gem 'nokogiri'
  gem 'webrat'
end

group :development do
  gem "rspec-rails", "~>2.0.pre"
  gem "heroku"
  gem "will_paginate", "~>3.0.pre2"
end

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

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

发布评论

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

评论(2

李不 2024-10-17 00:11:40

我找不到警告了,但我认为现在建议将 Capybara gem 与 Cucumber 一起使用铁轨3。

好吧,经过一些搜索,它可能工作得很好,但是看看这里的评论 。这个问题并不完全像你的问题,但可能是相关的。

I can't find the warnings anymore, but I think the Capybara gem is now recommended for use with Cucumber on Rails3.

Okay, after some searching, it may work fine, but take a look at the comments here. The problem isn't exactly like yours but it could be related.

长安忆 2024-10-17 00:11:40

事实上,我曾经也遇到过同样的问题。我认为 Cucumber 是负责任的,但仔细一看,似乎错误出在你的观点中: ActionView::Template::Error

Cucumber 使用测试数据库,如果你的主页需要种子,它们不是已加载。

就您而言,您似乎编写了一个被误解的controller,也许是在输入诸如params[controller]之类的内容时

Actually, I did have the same problem once. I thought Cucumber was responsible but look closer, it seems the error lies in your view: ActionView::Template::Error

Cucumber uses the test database, if you require seeds for your homepage, they aren't loaded.

In your case, it seems you've written a misunderstood controller, maybe while typing something like params[controller]

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