rails 2.3 rspec 1.3 undefined方法`get'for#<rspec :: examplegroups ::

时间:2015-06-19 10:47:38

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

=“”

我不断收到此错误消息。

  1) Worker::HomeController GET #index has a 200 status code
     Failure/Error: get :home
     NoMethodError:
       undefined method `get' for #<RSpec::ExampleGroups::WorkerHomeController::GETIndex:0x2ba04c836f18>
     # ./spec/controllers/worker/home_controller_spec.rb:14

Finished in 0.12277 seconds (files took 2 minutes 59.7 seconds to load) 1 example, 1 failure

我正在使用这些宝石

group :development, :test do
  gem "rspec", "~> 1.3"
  gem "rspec-rails", "~> 1.3"
  gem "nokogiri", "1.3.3"
  gem "rubyzip", "0.9.7"
  gem "capybara", "2.0.0"
  gem "database_cleaner", "1.4.1"
  gem "factory_girl", "2.5.0"
  gem "rspec-core", "3.3.0"
end

据我所知,此问题与rspec配置有关

以下是规范文件

require 'spec_helper'
require 'factory_girl'
require 'date'

RSpec.describe Worker::HomeController, :type => :controller do

  before :each do
    Factory.create(:zipcode, :zip => "60290")
  end

  describe "GET #index" do

    it "has a 200 status code" do
      get :home
      response.code.should eq("200")
    end
  end
end

项目目录结构是:

app
  controllers
    worker
      home_controller.rb
spec
  controllers
    worker
      home_controller_spec.rb

1 个答案:

答案 0 :(得分:0)

Rspec 2.x将假设controllers目录中的所有内容都是控制器spec

这在Rspec 3中有所改变:

默认情况下禁用文件类型推断

  

以前我们会自动从文件位置推断出规格类型,   这对于新用户来说是一种令人惊讶的行为,对某些人来说是不受欢   退伍军人用户从RSpec 3起,这种行为必须如此   明确选择:

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled

也不要忘记require 'rspec/rails'