【问题标题】:Getting the, NoMethodError: undefined method `get' for #<RSpec.. but have controller type specified获取 NoMethodError:#<RSpec.. 的未定义方法“get”,但指定了控制器类型
【发布时间】:2015-08-04 23:27:58
【问题描述】:

我正在使用 RSpec 3.2。

require 'spec_helper'

describe SimulationsController, :type => :controller do
    context "GET #index" do 
        it "populates an array of simulations" do 
            simulation = FactoryGirl.build(:simulation)
            get :index
            response.should render_template :index
        end 
    end
end

我指定了控制器类型,但仍然收到此错误,是不是我做错了什么?

【问题讨论】:

  • 你能发布你的spec_helper.rb吗?
  • 实际上只是修复了它,需要'require'rspec/rails''
  • 太棒了!将其添加为答案:)

标签: ruby-on-rails ruby rspec controller specifications


【解决方案1】:

我通过添加解决了这个问题

require 'rspec/rails'

到我的 spec_helper.rb,例如:

RSpec.configure do |config|
  # Deals with being unable to find 'get' function
  require 'rspec/rails'
end

【讨论】:

    猜你喜欢
    • 2013-12-09
    • 2022-11-05
    • 2014-09-26
    • 2017-12-09
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    相关资源
    最近更新 更多