如何让RSpec识别超薄模板?

时间:2016-04-20 10:37:45

标签: rspec rubygems

我在模块中有一个简单的控制器动作

module MyEngine
  module UsersControllerExt
    extend ActiveSupport::Concern

    def index
      @users = User.relevant
      render template: "users/index"
    end

  end
end

RSpec控制器关注使用匿名控制器的规范

RSpec.describe MyEngine::UsersControllerExt, type: :controller do
  controller(ApplicationController) do
    include MyEngine::UsersControllerExt
  end

  describe "GET :show" do
    it "should set @users instance variable" do
      get :index

      expect(assigns(:users)).to be_present      
    end
  end

end

此规范失败,

ActionView::MissingTemplate:
   Missing template users/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in:
     * "~/Documents/my_engine/spec/dummy/app/views"
     * "~/Documents/my_engine/app/views"

如果我将模板文件index.slim更改为index.erb,则规范会通过 如何让RSpec接受超薄模板?

1 个答案:

答案 0 :(得分:0)

  1. 确保您在gemspec中有s.add_development_dependency "slim"
  2. 确保您的测试环境在require 'slim'中加载rails_helper.rb的gem,例如