我正在为控制器编写规范:
it 'should call the method that performs the movies search' do
movie = Movie.new
movie.should_receive(:search_similar)
get :find_similar, {:id => '1'}
end
我的控制器看起来像:
def find_similar
@movies = Movie.find(params[:id]).search_similar
end
运行 rspec 后,我得到以下信息:
Failures:
1) MoviesController searching by director name should call the method that performs the movies search
Failure/Error: movie.should_receive(:search_similar)
(#<Movie:0xaa2a454>).search_similar(any args)
expected: 1 time
received: 0 times
# ./spec/controllers/movies_controller_spec.rb:33:in `block (3 levels) in <top (required)>'
我似乎理解并接受,因为在我的控制器代码中,我调用了类(电影)方法,但我看不到任何将“find_similar”与规范中创建的对象连接起来的方法。
所以问题是-> 检查方法是否在规范中创建的对象上调用的方法是什么?