【发布时间】:2015-01-15 20:43:07
【问题描述】:
我正在重构一个为轮播提供多态模型的臃肿控制器。我正在尝试构建一个类方法来处理查找和返回可轮播的项目。
在我的 RSPEC 测试中,我想存根方法“is_something?”在作为参数的结果找到的场地上。
def self.find_carouselable(params)
.......
elsif params[:venue_id].present?
venue=Venue.friendly.find(params[:venue_id])
if venue.is_something?
do this
else
do that
end
end
end
我不知道如何存根作为输入数据的结果创建的对象 - 我不确定这是否称为存根或模拟?
context "carouselable is a venue" do
before do
allow(the_venue).to receive(:is_something?).and_return(true)
end
it "returns the instance of the carouselable object" do
expect(CopperBoxCarouselItem.find_carouselable(venue_params)).to eq the_venue
end
end
非常感谢
【问题讨论】:
标签: ruby-on-rails ruby rspec