我在模块中有一个简单的控制器动作
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接受超薄模板?
答案 0 :(得分:0)
s.add_development_dependency "slim"
require 'slim'
中加载rails_helper.rb
的gem,例如