ruby-on-rails – NameError:未定义的局部变量或方法`app’
发布时间:2020-12-17 03:55:23 所属栏目:百科 来源:网络整理
导读:我创建的控制器规范失败,并显示以下错误消息: NameError: undefined local variable or method `app' for #RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x00000004424880 … # spec/controllers/sessions_conroller_spec.rbrequire 'spec_h
我创建的控制器规范失败,并显示以下错误消息:
NameError: undefined local variable or method `app' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x00000004424880> … # spec/controllers/sessions_conroller_spec.rb require 'spec_helper' describe SessionsController do before do @user = User.gen! end describe "#create" do context "when sending valid email and password" do it "renders a json hash ..." do post :create,email: @user.email,password: @user.password expect(last_response.status).to eq(201) end end end describe "#destroy" do context "when sending valid email and authentication token" do it "renders a json hash ..." do delete :destroy,auth_token: @user.authentication_token expect(last_response.status).to eq(200) end end end end spec_helper.rb加载了一些混合. ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment",__FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec' Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.include Rack::Test::Methods,type: :controller config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = false config.order = "random" end 解决方法
从spec_helper.rb中删除以下内容
config.include Rack::Test::Methods,type: :controller (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |