【发布时间】:2013-12-11 08:00:32
【问题描述】:
我正在将 ruby on rails 项目的一部分移植到 gem 中。我已经使用bundle gem 创建了新的 gem 目录。对于lib 和spec 目录,gem 的项目布局如下所示:
|- lib
| |- mylib
| | |- MYCLASS.rb
| | |- version.rb
| |
| |- mylib.rb
|
|- spec
|- spec_helper.rb
|- mylib
|- test_MYCLASS.rb
spec/spec_helper.rb的内容:
require "mylib"
RSpec.configure do |config|
end
mylib.gemspec 的相关部分,由bundle gem 命令生成:
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
当我运行bundle exec rspec spec 时,我得到了
No examples found.
Finished in 0.00004 seconds
0 examples, 0 failures
两个问题。
- 我的这个 gem 的目录布局是否“正确”? (假设有官方布局)
- 为什么我的测试没有运行?当我执行
bundle exec rspec spec/mylib/*时,spec/mylib/test_MYCLASS.rb中的测试运行,而如果我执行bundle exec rspec spec/mylib/,它显示没有找到示例。
我查看了类似的问题并在 Google 上四处搜索,但没有一个能解决我的问题。
【问题讨论】:
-
看来 git 没有计算 spec 文件夹。请使用
git show HEAD:spec命令的输出指定我们。