2012-10-04 108 views
1

在非rails應用程序中出現FactoryGirl的奇怪行爲。得到錯誤的參數數量錯誤...不知道爲什麼。爲什麼我得到FactoryGirl錯誤的參數數量錯誤?

[email protected] ~/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 

Factories.rb

FactoryGirl.define :user do |u| 
    u.email  "[email protected]" 
    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 
+0

在哪裏被定義User類?它看起來並沒有包含在你發佈的內容中。 – dpassage

+0

如果在Rails環境中運行,數據庫模型應該由ActiveSupport自動加載。如果沒有發生這種情況,也許'app/models/user.rb'不存在,或者你需要手動'require'有問題的模型。 – tadman

回答

1

答案::用戶是一個保留字..將其更改爲:東西......現在工作正常。

0

如果這是一個非Rails應用程序,你必須首先創建一個User類。我不確定是否必須使用名稱,密碼和電子郵件發送實例變量,但您肯定必須在某處定義該類。

查看Github上的Getting Started文件瞭解更多信息。

1

嘗試使用新的語法從readme

FactoryGirl.define do 
    factory :user do 
    email "[email protected]" 
    password "joe009" 
    end 
end 
0

試試這個

FactoryGirl.define do 
    factory :user do |u| 
     u.email  "[email protected]" 
     u.password "joe009" 
    end 
end 
相關問題