【发布时间】:2016-08-03 12:02:54
【问题描述】:
型号:
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)
我尝试了不同的方法,但还是运气不好。对此的任何帮助将不胜感激。提前致谢!!
【问题讨论】: