2

I want to use Coveralls.io for my gem Headhunter that I'm developing at the moment. The doc says, I should simply add

gem 'coveralls', require: false

to the project, but as far as I know, this isn't the right way to load gems within another gem. Instead, stuff like that should happen in the .gemspec file. So I tried to add it like this:

s.add_development_dependency('coveralls', '>= 2.0')

But this doesn't work - it breaks my gem's whole functionality:

$ rake
/Users/josh/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -S rspec ./spec/headhunter/css_hunter_spec.rb ./spec/headhunter/css_validator_spec.rb ./spec/headhunter/html_validator_spec.rb
/Users/josh/Documents/Work/MuheimWebdesign/headhunter/lib/headhunter/css_validator.rb:6:in `<class:CssValidator>': undefined method `full_gem_path' for nil:NilClass (NoMethodError)

This is the file that breaks:

require 'net/http'
require 'nokogiri/xml'

module Headhunter
  class CssValidator
    VALIDATOR_PATH = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/css-validator/'

So Gem.loaded_specs['headhunter'] isn't available anymore, no idea what's going on here.

What's wrong here?

Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152

1 Answers1

3

I was wondering the same and I just got it working.

You need to add:

spec.add_development_dependency "coveralls", "0.7.0"

to your .gemspec (0.7.0 is the coveralls gem latest version as the time of writing this)

make sure to run bundle installsuccessfully

and add:

require 'coveralls'
Coveralls.wear!

to the beginning of your spec_helper.rb or test_helper.rb, before requiring anything else.

Hope this helps.

Daniel Romero
  • 1,581
  • 1
  • 20
  • 33