Why am I getting FactoryGirl wrong number of arguments error?

心已入冬 提交于 2019-12-24 07:17:58

问题


Having strange behavior from FactoryGirl in non-rails app. getting wrong number of arguments error...don't know why.

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)>'

Here are the files involved...

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 

Factories.rb

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

user.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

回答1:


ANSWER: :user is a reserved word..changed it to :stuff...works fine now.




回答2:


Try to use new syntax from readme

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



回答3:


If this is a non-rails app you will have to create a Userclass first. I'm not sure if you have to have instance vars with name, password and email but you definitely will have to have that class defined somewhere.

See the Getting Started file on Github for more on that.




回答4:


Try this

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


来源:https://stackoverflow.com/questions/12732450/why-am-i-getting-factorygirl-wrong-number-of-arguments-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!