【发布时间】:2010-02-28 22:40:26
【问题描述】:
我是 Rails 新手,我正在尝试使用 rspec 测试控制器。我的第一个测试是调用 show 操作时,它应该通过 url 查找 Category。
问题是当我添加存根代码时,我收到以下错误:
##的未定义方法`find'
我的测试如下所示:
require 'spec_helper'
describe CategoriesController do
describe "GET /category-name/" do
before(:each) do
@category = mock_model(Category)
Category.stub!(:find).with(:first, :conditions => ["url = :url", {:url => "category-name"}]).and_return(@category)
end
it "should find the category by url" do
controller.show
Category.should_receive(:find).with(:first, :conditions => ["url = :url", {:url => "category-name"}]).and_return(@category)
end
end
end
【问题讨论】:
标签: ruby-on-rails ruby rspec