0
型號:如何在rails(v4.2.5)中使用rspec(v3.4.1)測試參數化範圍方法?
scope :recent, ->(n) {where(:created_at => 6.months.ago..Time.now).order('created_at DESC').limit(n)}
我會做這樣的事情在Rspec的:
before(:each) do @song = double(Song,id: 1, name: "Vegan artisan.", album_id: 1, artist_id: 20, created_at: "2016-03-04 13:15:36", updated_at: "2016-03-04 13:15:36") end it "should return the recent most songs within range" do Song.stub_chain(:where,:order,:limit).with(created_at:6.months.ago..Time.now).with('created_at DESC').with(2).and_return([@song,@song]) Song.recent.should == [@song,@song] end
上述案例失敗,讓下面提到的錯誤:
ArgumentError: wrong number of arguments (0 for 1)
我嘗試不同的方法,但仍然運氣不佳。任何幫助,將不勝感激。提前致謝!!
感謝您的快速回復。它解決了我的問題。 –