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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…