[英]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.