Gem 开发无法添加新文件
Gem development can't add new file
我在 ruby 的 Gem 开发中遇到了一些非常基本的问题。
我用这个命令创建了一个新项目。
bundle gem foobar
我现在可以了 运行
bundle && bundle exec rake spec
一切都很好。
但是我尝试在我的规范中添加一个新部分
expect(Foobar::BAR).not_to be nil
然后在./lib/foobar/error.rb
中定义
module Foobar
BAR="bar"
end
就是没有找到这个文件。错误是 NameError: uninitialized constant
。我可以 require_relative
在 spec_helper.rb
但这显然是不正确的或可持续的。
我已在此处看到问题 Missing File in Gem after Build 我已将新文件添加到 git。这无济于事,直接在 gemspec 文件中添加文件也无济于事。
整个项目在这里https://github.com/ollyjshaw/broken_gem
我做错了什么?应该是小事,但是看不出来
答案:
答案在安东尼的评论中
"You're not requiring your error file when your gem is loaded: github.com/ollyjshaw/broken_gem/blob/master/lib/foobar.rb#L1"
"You'd load your main module and that module would load other modules/classes it needs and down the tree it goes"
通常您会将所有 class/module 文件添加到 spec_helper.rb
文件中的加载路径:
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "your_gem"
我在 ruby 的 Gem 开发中遇到了一些非常基本的问题。
我用这个命令创建了一个新项目。
bundle gem foobar
我现在可以了 运行
bundle && bundle exec rake spec
一切都很好。
但是我尝试在我的规范中添加一个新部分
expect(Foobar::BAR).not_to be nil
然后在./lib/foobar/error.rb
中定义module Foobar
BAR="bar"
end
就是没有找到这个文件。错误是 NameError: uninitialized constant
。我可以 require_relative
在 spec_helper.rb
但这显然是不正确的或可持续的。
我已在此处看到问题 Missing File in Gem after Build 我已将新文件添加到 git。这无济于事,直接在 gemspec 文件中添加文件也无济于事。
整个项目在这里https://github.com/ollyjshaw/broken_gem
我做错了什么?应该是小事,但是看不出来
答案: 答案在安东尼的评论中 "You're not requiring your error file when your gem is loaded: github.com/ollyjshaw/broken_gem/blob/master/lib/foobar.rb#L1" "You'd load your main module and that module would load other modules/classes it needs and down the tree it goes"
通常您会将所有 class/module 文件添加到 spec_helper.rb
文件中的加载路径:
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "your_gem"