简体   繁体   English

告诉rspec(核心)测试正在测试控制器

[英]Tell rspec (core) that test is testing controller

Trying to run this test but keep getting the following error: 尝试运行此测试,但不断出现以下错误:

Failure/Error: get :index

 NoMethodError:
   undefined method `get' for #<RSpec::ExampleGroups::TestModuleTestController::Controller:0x007fa4bc120d00>

Note: I'm not using rspec-rails. 注意:我没有使用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

Note: I'm not using rspec-rails. 注意:我没有使用rspec-rails。

That's your problem right there. 那就是你的问题。 All the rails type specs (controller, request, features, views) are part of rspec-rails not rspec-core. 所有的rails类型规范(控制器,请求,功能,视图)都是rspec-rails的一部分,而不是rspec-core。

Without rspec-rails the type metadata does absolutely nothing - its just a plain example group describing a class. 如果没有rspec-rails,则type元数据绝对不会做任何事情-它只是描述类的简单示例组。

The solution is to add rspec-rails to your gemfile. 解决方案是将rspec-rails添加到您的gemfile中。

group :development, :test do
  gem 'rspec-rails', '~> 3.6'
end

And run rails g rspec install . 然后运行rails g rspec install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM