bundle gem: rspec says 'No examples found'

Viewed 15567

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.

2 Answers

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

Related