2011-01-22 32 views
3

我試圖讓工廠女孩設置了Rails 3,但是當我rake cucumber我得到這個錯誤:建立工廠女孩,黃瓜和軌道3

[email protected]:~/rails-projs/simple-beach-63$ rake cucumber:wip 
(in /home/james/rails-projs/simple-beach-63) 
bundle exec /usr/bin/ruby1.8 -I "/usr/lib/ruby/gems/1.8/gems/cucumber-0.9.4/lib:lib" 

"/usr/lib/ruby/gems/1.8/gems/cucumber-0.9.4/bin/cucumber" --profile wip Using the wip profile... uninitialized constant Factory (NameError) /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.1.0/lib/rspec/expectations/backward_compatibility.rb:6:in const_missing' /usr/lib/ruby/gems/1.8/gems/factory_girl-1.3.3/lib/factory_girl/step_definitions.rb:25 /home/james/rails-projs/simple-beach-63/features/support/env.rb:8:in require' /home/james/rails-projs/simple-beach-63/features/support/env.rb:8

你能拉來看一看當你得到一秒鐘?

我有這樣的Gemfile中:

gem 'factory_girl_rails' 
gem 'factory_girl' 

我有這樣的功能/支持/ env.rb

require "factory_girl/step_definitions" 
require "factory_girl" 
require File.dirname(__FILE__) + "/factories" 

,然後我定義功能工廠/支持/ factories.rb

我想感謝所有幫助

+0

會發生什麼事,如果你使用factory_girl_rails寶石呢? – monocle 2011-01-22 02:49:22

回答

8

您應該只需要執行這些步驟。

的Gemfile:

group :development, :test do 
    gem "rspec-rails" 
end 

group :test do 
    gem "cucumber-rails" 
    gem "factory_girl_rails" 
end 

功能/支持/ factory_girl.rb:

require 'factory_girl/step_definitions' 

規格/ factories.rb:

# your Factory definitions. 
3

丹,

我已經按照你的步驟,但我仍然無法使用工廠女孩的步驟定義。

當我嘗試:

Given I am not logged in 
    And the following user exists: 
    | login | email    | password | confirmation | 
    | user50 | [email protected] | secret50 | secret 50 | 
... 

我得到以下錯誤:

Undefined step: "the following user exists:" (Cucumber::Undefined exception) 

You can implement step definitions for undefined steps with these snippets: 
Given /^the following user exists:$/ do |table| 
    # table is a Cucumber::Ast::Table 
    pending # express the regexp above with the code you wish you had 
end 

上缺少了什麼任何想法?

+0

您需要在features/support/factory_girl.rb中首先要求'factory_girl_rails'`,因爲步驟定義是從您的工廠生成的。 – RobinGower 2011-09-23 01:59:12

0

這裏的問題是,你沒有正確調用你的表。從您的功能文件調用表中的行應該是這樣的:

And the following user with <login> and <email> <password> and <confirmation> exists 

你的步驟定義應該是這樣的:

And /^The following user with ([A-za-z0-9\[email protected]:]+) and ([A-za-z0-9\[email protected]:]+) ([A-za-z0-9\[email protected]:]+) and ([A-za-z0-9\[email protected]:]+) exists$/ do |login, email, password, confirmation|