Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby RSpec AWS Lambda处理程序-模块中未初始化的常量_Ruby_Amazon Web Services_Rspec_Aws Lambda - Fatal编程技术网

Ruby RSpec AWS Lambda处理程序-模块中未初始化的常量

Ruby RSpec AWS Lambda处理程序-模块中未初始化的常量,ruby,amazon-web-services,rspec,aws-lambda,Ruby,Amazon Web Services,Rspec,Aws Lambda,我有一个用于Ruby 2.5.0的简单AWS lambda处理程序,我想测试它。我发现这样做很酷,但一开始我就遇到了未初始化的常量Bot错误 source/handlers/jira\u handler.rb require_relative '../config/environment' module Bot module JiraHandler extend self def handle(event:, context:) Slack::SlackMes

我有一个用于Ruby 2.5.0的简单AWS lambda处理程序,我想测试它。我发现这样做很酷,但一开始我就遇到了
未初始化的常量Bot
错误

source/handlers/jira\u handler.rb

require_relative '../config/environment'

module Bot
  module JiraHandler
    extend self

    def handle(event:, context:)
      Slack::SlackMessenger.new(event).call
      { statusCode: 200 }
    end
  end
end
require 'spec_helper'

RSpec.describe Bot::JiraHandler do
  subject { Bot::JiraHandler }

  describe '#handle' do
    context 'when Jira webhook is launched' do
      let!(:payload) { File.new('./spec/support/events/event.json').read }
      let!(:context) { {} }
      let!(:event) do
        {
          'body' => payload
        }
      end

      let(:response) { subject.handler(event: event, context: context) }

      it 'responds successfully' do
        allow_any_instance_of(Slack::SlackMessenger).to receive(:call)

        expect(response).to include(statusCode: 200)
      end
    end
  end
end
由于惯例,JiraHandler模块位于Bot模块内部,整个设置使用terraform完成

spec/source/handlers/jira\u handler\u spec.rb

require_relative '../config/environment'

module Bot
  module JiraHandler
    extend self

    def handle(event:, context:)
      Slack::SlackMessenger.new(event).call
      { statusCode: 200 }
    end
  end
end
require 'spec_helper'

RSpec.describe Bot::JiraHandler do
  subject { Bot::JiraHandler }

  describe '#handle' do
    context 'when Jira webhook is launched' do
      let!(:payload) { File.new('./spec/support/events/event.json').read }
      let!(:context) { {} }
      let!(:event) do
        {
          'body' => payload
        }
      end

      let(:response) { subject.handler(event: event, context: context) }

      it 'responds successfully' do
        allow_any_instance_of(Slack::SlackMessenger).to receive(:call)

        expect(response).to include(statusCode: 200)
      end
    end
  end
end

我收到
name错误:未初始化的常量Bot
。如何在specs中初始化那些self-module对象?

你在哪里加载
jira\u handler.rb
文件?我正在通过
-I source
加载
spec\u helper.rb
中的所有代码,所以,
-I
实际上没有加载文件。。。。你为什么不
需要
spec\u helper.rb中的jira\u处理程序文件?好的,对不起,我在
.rspec
文件中找到了这个
-I
。但是,即使我在spec_helper.rb中通过
require“./source/handlers/jira_handler”需要
jira_handler
我有一个错误-
LoadError:无法加载这样的文件--../source/handlers/jira\u handler
-当我试图通过
require'../../../source/handlers/jira\u handler'
使用require\u relative直接从规范文件中请求路径时,会发生相同的错误