2

This is the error reported by Travis CI when it try to build my gem under Ruby 1.9.3:

NoMethodError: undefined method `spec' for nil:NilClass

I cannot find any reason or source for this error.

This is causing build failures which is misleading people into believing that the code in the gem itself is incorrect.

Why might this be happening and how can I fix it?

Keith Bennett
  • 4,722
  • 1
  • 25
  • 35
  • Do you use gem `rspec` to test your code or is it in your gemfile? – guitarman May 02 '16 at 09:46
  • Yes, I use rspec for testing, and it's specified in the .gemspec as a development dependency. Please note that the answer below is mine, and it fixed the problem (though if you or anyone has a better solution, that's welcomed). – Keith Bennett May 02 '16 at 09:54

2 Answers2

1

I believe it is due to Travis using an old version of Bundler. Adding the code below to the .travis.yml file should fix it:

before_install:
  - gem install bundler

(Found at https://github.com/travis-ci/travis-ci/issues/3531.)

(Example of usage is at https://github.com/keithrbennett/trick_bag/blob/master/.travis.yml#L5-6.)

Keith Bennett
  • 4,722
  • 1
  • 25
  • 35
0

That's good, if you found a solution.

I had a similar problem that travis wasn't able to run my rspec tests. I edited my .travis.yml to create some binstubs on bundle install in my project. This way I can call bin/rspec easily from my project and run my tests.

My .travis.yml:

language: ruby
rvm:
  - 2.3.0
bundler_args: --binstubs
script:
  - bundle install
  - bin/rspec spec
guitarman
  • 3,290
  • 1
  • 17
  • 27