undefined method `get' for #

前端 未结 12 857
野性不改
野性不改 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:46

    RSpec doesn't know that your spec is a controller spec, so your examples don't have access to a get method.

    RSpec 2.x assumes 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

    In the rspec-rails README:

    Controller specs default to residing in the spec/controllers folder. Tagging any context with the metadata :type => :controller treats it's examples as controller specs.

    An example of setting the controller context metadata for RSpec:

    describe ToolsController, :type => :controller do
        # ...
    end
    

提交回复
热议问题