3
我有這個項目控制器簡短的行動。rails rspec render_template匹配器
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)>'