rails rspec stubbing instance variables和current_user

时间:2013-07-19 13:48:23

标签: ruby-on-rails rspec

ProjectsController#展示

if !@project.user_allowed_to_view_gallery?(current_user)
  render :action => :hidden_gallery
elsif @project.project_type.gallery_template == :written
  render :action => :written_gallery
end

我想测试这个动作,这是我的测试文件。

sign_in @creative
get :show, :id => @project.to_param
controller.stub(:current_user).and_return(@creative)
@project.stub!(:user_allowed_to_view_gallery?).with(@creative).and_return(false)
response.should render_template("hidden_gallery")

它不起作用。我认为问题是存根实例@project变量和current_user。你知道我该如何解决它?

1 个答案:

答案 0 :(得分:0)

您应该期望响应呈现模板。不是你的项目实例。

response.should render_template 'hidden_gallery'