1

在非 Rails 应用程序中出现 FactoryGirl 的奇怪行为。得到错误数量的参数错误......不知道为什么。

gideon@thefonso ~/Sites/testing (master)$ rspec spec
/Users/gideon/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:6:in `define': wrong number of arguments (1 for 0) (ArgumentError)
    from /Users/gideon/Sites/testing/spec/factories.rb:1:in `<top (required)>'

以下是涉及的文件...

login_user_spec.rb

require_relative '../spec_helper'
require_relative '../lib/login_user'


describe "Existing User Log in Scenario", :type => :request do

  before :all do
    @user = FactoryGirl(:user)
  end


    xit "should allow user to select login from top nav" do 
        visit "/" 
        within("#main-header")do
            click_link 'Log In' 
        end

        page.should have_content('Log in to your account')
    end  

    it "and fill in login form" do
        visit "/login" 
        within("#login-form")do
            fill_in 'user-email', :with => @user.email
            fill_in 'user-password', :with => @user.password
        end

        #FIXME - the design crew will make this go away     
        within("#login-form") do 
            click_link '#login-link' #this gives false failing test...geek query...why?
        end

        page.should have_content('Manage courses')
    end
end 

工厂.rb

FactoryGirl.define :user do |u|
    u.email     "joe@website.com"
    u.password  "joe009"
end

用户.rb

  class User
    attr_accessor :email, :password
  end

spec_helper.rb

require 'rubygems'
require 'bundler/setup'
require 'capybara'
require 'rspec'
require 'capybara/rspec'
require 'json'

require 'capybara/dsl'
# Capybara configuration
Capybara.default_driver = :selenium
Capybara.app_host = "http://www.website.com"

require 'factory_girl'
# give me ma stuff
FactoryGirl.find_definitions

require "rspec/expectations"

include Capybara::DSL
include RSpec::Matchers
4

4 回答 4

1

尝试使用自述文件中的新语法

FactoryGirl.define do
  factory :user do
    email "joe@website.com"
    password "joe009"
  end
end
于 2013-01-23T20:54:30.860 回答
1

答案: :user 是保留字..将其更改为 :stuff ...现在可以正常工作了。

于 2012-10-05T01:28:56.397 回答
0

如果这是一个非 Rails 应用程序,您必须先创建一个User类。我不确定您是否必须拥有带有名称、密码和电子邮件的实例变量,但您肯定必须在某处定义该类。

有关更多信息,请参阅 Github 上的入门文件。

于 2012-10-04T21:09:17.547 回答
0

尝试这个

FactoryGirl.define do
    factory :user do |u|
        u.email     "joe@website.com"
        u.password  "joe009"
    end
end
于 2016-01-13T14:31:45.700 回答