捆绑宝石:rspec说'没有找到例子'

时间:2021-08-27 00:19:57

I am in the middle of porting part of a ruby on rails project into a gem. I have used bundle gem to create the new gem directory. For the lib and spec directories, the gem's project layout looks like this:

我正在将rails项目中ruby的一部分移植到gem中。我使用bundle gem来创建新的gem目录。对于lib和spec目录,gem的项目布局如下所示:

|- lib
|  |- mylib
|  |  |- MYCLASS.rb
|  |  |- version.rb
|  |
|  |- mylib.rb
|
|- spec
   |- spec_helper.rb
   |- mylib
      |- test_MYCLASS.rb

The contents of spec/spec_helper.rb:

spec / spec_helper.rb的内容:

require "mylib"

RSpec.configure do |config|
end

The relevant parts of mylib.gemspec, as generated by the bundle gem command:

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"]

When I run bundle exec rspec spec, I get

当我运行bundle exec rspec spec时,我明白了

No examples found.


Finished in 0.00004 seconds
0 examples, 0 failures

Two questions.

两个问题。

  1. Is my directory layout for this gem "correct"? (Assuming there is an official layout)
  2. 这个宝石的目录布局是否“正确”? (假设有官方布局)
  3. Why are my tests not running? When I do bundle exec rspec spec/mylib/*, the tests in spec/mylib/test_MYCLASS.rb run, whereas if I do bundle exec rspec spec/mylib/, it says no examples found.
  4. 为什么我的测试没有运行?当我捆绑exec rspec spec / mylib / *时,spec / mylib / test_MYCLASS.rb中的测试运行,而如果我捆绑了exec rspec spec / mylib /,则说没有找到示例。

I've looked at similar questions and googled around, but none of them solves my problem.

我看过类似的问题并用Google搜索,但没有一个能解决我的问题。

2 个解决方案

#1


41  

Solved it with help from my colleague. Turns out that the spec files have to be named with a _spec suffix, and bundle exec rspec spec works. I name the spec file with a test_ prefix previously. Was using bundler 1.3.5 and rspec 2.14.1

在我的同事的帮助下解决了这个问题。事实证明,spec文件必须使用_spec后缀命名,并且bundle exec rspec spec可以工作。我以前用test_前缀命名spec文件。使用的是bundler 1.3.5和rspec 2.14.1

#2


0  

Another possible issue is forgetting to require 'rails_helper' which is usually where you require most of your test supporting libraries, including require 'rspec/rails'.

另一个可能的问题是忘记需要'rails_helper',这通常是您需要大多数测试支持库的地方,包括require'rspec / rails'。

#1


41  

Solved it with help from my colleague. Turns out that the spec files have to be named with a _spec suffix, and bundle exec rspec spec works. I name the spec file with a test_ prefix previously. Was using bundler 1.3.5 and rspec 2.14.1

在我的同事的帮助下解决了这个问题。事实证明,spec文件必须使用_spec后缀命名,并且bundle exec rspec spec可以工作。我以前用test_前缀命名spec文件。使用的是bundler 1.3.5和rspec 2.14.1

#2


0  

Another possible issue is forgetting to require 'rails_helper' which is usually where you require most of your test supporting libraries, including require 'rspec/rails'.

另一个可能的问题是忘记需要'rails_helper',这通常是您需要大多数测试支持库的地方,包括require'rspec / rails'。