rubyrspecbundler

bundle gem: rspec says 'No examples found'


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:

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

The contents of spec/spec_helper.rb:

require "mylib"

RSpec.configure do |config|
end

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

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

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. 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.

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


Solution

  • 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