4

我有这个项目控制器的简短动作。

项目控制器.rb

def brief
    #@project before_filter_da ataniyor
    if @project.user_allowed_to_view_brief?(current_user)
      @brief_notes = @project.brief_notes.order(:id)
      @project_files = @project.project_files
      render :action => :written_brief if @project.project_type.brief_template == :written
    else
      render :action => :hidden_brief
    end
  end

这是我的projects_controller_spec.rb文件

context 'get :brief' do 
    it 'should be loaded successfully' do 
      sign_in @creative      
      @project.stub(:user_allowed_to_view_brief?).with(@creative).and_return(false)
      get :brief, :id => @project.to_param
      response.should render_template("hidden_gallery")
    end
  end

当我运行这个测试时,我遇到了这样的错误。

Failure/Error: response.should have_rendered("hidden_gallery")
       expecting <"hidden_gallery"> but rendering with <"shared/_project_title, shared/_project_header, shared/_project_buttons, shared/_messages, projects/_brief, projects/brief, shared/_header, shared/_footer, layouts/application">
     # ./spec/controllers/projects_controller_spec.rb:63:in `block (3 levels) in <top (required)>'
4

1 回答 1

4

我认为规范的最后一行应该改为:

 response.should render_template("hidden_brief")
于 2013-09-16T19:43:48.303 回答