2013-07-21 35 views
0

我有一個簡單的餐廳類,看起來像這樣:工廠女孩+ Rspec的:引發ArgumentError:錯誤的參數數目(0 2)

module Restaurant 
    class Identity 

     attr_reader :name, :location 

     def initialize (name, location) 
      @name = name 
      @location = location 
     end 

    end 
end 

我廠是這樣的:

FactoryGirl.define do 
    factory :restaurant, :class => Restaurant::Identity do |f| 
     f.name "Alfredos" 
     f.location "Andheri" 
    end 
end 

而我的測試是這樣寫的:

describe Restaurant::Identity do 

subject { build(:restaurant) } 

its(:name) {should_not be_nil} 
its(:location) {should_not be_nil} 

end 

但是當我運行它,我得到

1) Restaurant::Identity name 
    Failure/Error: subject { build(:restaurant) } 
    ArgumentError: 
     wrong number of arguments (0 for 2) 
    # ./lib/restaurant.rb:7:in `initialize' 
    # ./spec/restaurant_spec.rb:9:in `block (2 levels) in <top (required)>' 
    # ./spec/restaurant_spec.rb:11:in `block (2 levels) in <top (required)>' 

這是怎麼發生的?我究竟做錯了什麼?

回答

相關問題