rails rspec render_template matcher

时间:2013-07-17 07:57:51

标签: ruby-on-rails rspec

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

projects_controller.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)>'

1 个答案:

答案 0 :(得分:4)

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

 response.should render_template("hidden_brief")