gpt4 book ai didi

ruby-on-rails - 在我的 rspec 中要求 thor 任务导致未定义的方法

转载 作者:太空宇宙 更新时间:2023-11-03 18:18:57 24 4
gpt4 key购买 nike

我正在尝试为我的 Thor 任务编写一个非常基本的 rspec,但是当尝试要求(或加载)它失败的任务时,为各种 Thor 类提供 NoMethodError('undefined method ...') -级别方法(desc、method_option、class_option 等)

require "spec_helper"
require Rails.root.join('lib/tasks/test_task.thor')

describe 'TestTask' do

it "is instantiated ok" do
TestTask.new
end
end

如您所见,我正在 Rails 应用程序环境中进行测试。

thor 任务本身可以从命令行正常执行。

我已经按照其他地方的建议(Where can I find good examples of testing a Thor script with RSpec?)查看了 Thor 规范

有什么想法吗?

最佳答案

我找到的答案是使用 load 而不是 require(我以为我测试过这个,但也许我错了)

所以:


需要'雷神'
加载 File.join(Rails.root.join('lib/tasks/test_task.thor'))

关于ruby-on-rails - 在我的 rspec 中要求 thor 任务导致未定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559121/

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