开发者

Setting up factory girl with cucumber and rails 3

I'm trying to get factory girl setup with rails 3, but I'm getting this error when I rake开发者_StackOverflow社区 cucumber:

james@james-laptop:~/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:inrequire' /home/james/rails-projs/simple-beach-63/features/support/env.rb:8

Can you pull and take a look when you get a sec?

I have this in the Gemfile:

gem 'factory_girl_rails'
gem 'factory_girl'

I have this in feature/support/env.rb

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

and then I define a factory in features/support/factories.rb

I'd appreciate any help


You should only need these steps.

Gemfile:

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

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

features/support/factory_girl.rb:

require 'factory_girl/step_definitions'

spec/factories.rb:

# your Factory definitions.


Dan,

I've followed your steps but I still cannot use the factory girl step definitions.

When I try :

  Given I am not logged in
  And   the following user exists:
    | login  | email               | password   | confirmation |
    | user50 | user50@mydomain.com | secret50   | secret 50    |
 ...

I get the following error:

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

Any ideas on what's missing?


The problem here is that you're not calling your table correctly. The line that calls the table from your feature file should look like this:

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

Your step definition should look like:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜