gpt4 book ai didi

ruby-on-rails - 名称错误 : undefined local variable or method `app'

转载 作者:行者123 更新时间:2023-12-03 16:44:28 25 4
gpt4 key购买 nike

我创建的 Controller 规范失败并显示以下错误消息:

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, email: @user.email, 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

关于ruby-on-rails - 名称错误 : undefined local variable or method `app' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18278326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com