开发者

Rails 3 Cucumber/Webrat fails on simple "Given": did I set up something wrong?

开发者 https://www.devze.com 2023-02-01 07:25 出处:网络
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

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:i开发者_如何学Cn `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


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.


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]

0

精彩评论

暂无评论...
验证码 换一张
取 消