rails 2.3 rspec 1.3 undefined method `get' for #<RSpec::ExampleGroups::

133 Views Asked by At

i keep getting this error message.

  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

i am using these gems

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

this issue is related to rspec config as far as I understand

following is the spec file

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

the project directory structure is :

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

There are 1 best solutions below

1
On

Rspec 2.x will assume that everything in the controllers directory is a controller spec.

This was changed in Rspec 3:

File-type inference disabled by default

Previously we automatically inferred spec type from a file location, this was a surprising behaviour for new users and undesirable for some veteran users so from RSpec 3 onwards this behaviour must be explicitly opted into with:

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

Also do not forgot to require 'rspec/rails'