【发布时间】:2010-05-12 18:51:19
【问题描述】:
我正在尝试运行以下规范:
describe UsersController, "GET friends" do
it "should call current_user.friends" do
user = mock_model(User)
user.should_receive(:friends)
UsersController.stub!(:current_user).and_return(user)
get :friends
end
end
我的控制器是这样的
def friends
@friends = current_user.friends
respond_to do |format|
format.html
end
end
问题是我无法存根 current_user 方法,因为当我运行测试时,我得到:
Spec::Mocks::MockExpectationError in 'UsersController GET friends should call current
_user.friends'
Mock "User_1001" expected :friends with (any args) once, but received it 0 times[0m
./spec/controllers/users_controller_spec.rb:44:
current_user 是来自 Restful-authentication 的一个方法,它包含在这个控制器中。我应该如何测试这个控制器?
提前致谢
【问题讨论】:
标签: ruby-on-rails rspec