undefined method `get' for #

前端 未结 12 826
野性不改
野性不改 2020-11-30 00:57

Anyone know how to get around this? On OSX, trying to get RSpec running with Rails 3.0.7. Full details at: https://gist.github.com/1017044

  it \"renders but         


        
相关标签:
12条回答
  • 2020-11-30 01:23

    I was able to fix this issue in my app by adding require 'rspec/rails' to my spec_helper file.

    0 讨论(0)
  • 2020-11-30 01:24

    If at all you are using 'spec/features', you may need to add the following to your 'spec_helper.rb'

    config.include RSpec::Rails::RequestExampleGroup, type: :feature
    
    0 讨论(0)
  • 2020-11-30 01:25

    I had this issue when I added

    gem 'rspec'
    

    to my Gemfile in the rails project. It should be

    gem 'rspec'
    gem 'rspec-rails'
    

    (or just rspec-rails). After

    bundle install
    

    re-create the spec directory with

    rspec --init
    

    and put your xxx_spec.rb file in the appropriate directory (won't work if it is in the spec directory). Beginners error but maybe this helps somebody ;) Here's the link that helped me:

    https://www.relishapp.com/rspec/rspec-rails/docs/gettingstarted

    0 讨论(0)
  • 2020-11-30 01:26

    For others looking into this. I was trying to track down a undefined method 'get' error. My issue was that I had the get in a describe block make sure your get is in an it block.

    0 讨论(0)
  • 2020-11-30 01:26

    If you used rspec to generate the .rspec file, you should change the content from:

    --require spec_helper
    

    to:

    --require rails_helper
    
    0 讨论(0)
  • 2020-11-30 01:32

    An alternative is to specify type: :request for your spec. For example:

    RSpec.describe "Widget management", :type => :request do
    
      it "creates a Widget and redirects to the Widget's page" do
        get "/widgets/new"
        expect(response).to render_template(:new)
    
        post "/widgets", :widget => {:name => "My Widget"}
    
        expect(response).to redirect_to(assigns(:widget))
        follow_redirect!
    
        expect(response).to render_template(:show)
        expect(response.body).to include("Widget was successfully created.")
      end
    
    end
    

    Example taken from here https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec.

    0 讨论(0)
提交回复
热议问题