型号:
范围:近期,->(n) {where(:created_at => 6.months.ago..Time.now).order('created_at DESC').limit(n)}
我会在Rspec做这样的事情:
(:每一首) do @song = double(Song,id: 1,name:"Vegan .“,album_id: 1,artist_id: 20,created_at:"2016-03-04 13:15:36",updated_at:"2016-03-04 13:15:36")结束时,”应该返回范围内最近最多的歌曲“do Song.stub_chain(:where,:order,:limit).with(created_at:6.months.ago..Time.now).with('created_at .with(2).and_return(“歌”,“歌”) Song.recent.should == @song,“歌曲结尾”
上述情况失败,给出了下面提到的错误:
ArgumentError:错误的参数数(1为0)
我试过不同的方法,但还是运气不好。如能对此提供任何帮助,将不胜感激。提前谢谢!!
发布于 2016-04-12 18:11:45
recent作用域要求您传递一个限制搜索结果的参数,因此需要适当地更改这一行:
Song.recent(2).should eq([@song,@song])或
expect(Song.recent(2)).to match_array([@song,@song])https://stackoverflow.com/questions/36580660
复制相似问题