[英]Tell rspec (core) that test is testing controller
尝试运行此测试,但不断出现以下错误:
Failure/Error: get :index
NoMethodError:
undefined method `get' for #<RSpec::ExampleGroups::TestModuleTestController::Controller:0x007fa4bc120d00>
注意:我没有使用rspec-rails。
require "spec_helper"
module TestModule
describe TestController, :type => :controller do
describe "controller" do
it "sets X-Frame-Options to ALLOWALL" do
get :index
expect(response.headers['X-Frame-Options']).to eq('ALLOWALL')
end
end
end
end
注意:我没有使用rspec-rails。
那就是你的问题。 所有的rails类型规范(控制器,请求,功能,视图)都是rspec-rails的一部分,而不是rspec-core。
如果没有rspec-rails,则type
元数据绝对不会做任何事情-它只是描述类的简单示例组。
解决方案是将rspec-rails添加到您的gemfile中。
group :development, :test do
gem 'rspec-rails', '~> 3.6'
end
然后运行rails g rspec install
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.