2
votes

I am updating a gem to make sure it works with the new versions of the bitly and rspec gems, and I have run into an odd issue.

When I run guard to make sure all the tests pass with the new gem, I get a TypeError; however, if I run my test suite directly with just rspec they all pass and do not throw the error.

My code is available on GitHub if you want to see the whole shebang.

From digging around, I've seen people suggesting to wrap the class inside of its own module to keep the class names from conflicting, but since it works fine with just rspec, I am hoping I don't need to add another layer.

Here's the TypeError:

/Users/jstim/Documents/Programming/Ruby/uncoil/lib/uncoil.rb:6:in '': Uncoil is not a class (TypeError)
from /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in 'require_relative'
from /Users/jstim/Documents/Programming/Ruby/uncoil/spec/uncoil_spec.rb:1:in ''
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'block in load_spec_files'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'map'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in 'load_spec_files'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in 'run'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in 'run_in_process'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in 'run'
from /Users/jstim/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in 'block in autorun'

Let me know if I can include additional code to help out. thanks!

1
Everything works fine for me. Are you sure the version on Github is the same as the one you have that is failing? Also, are you using bundler when you run rspec and guard? (ie: bundle exec guard and bundle exec rspec spec). Also, you don't need require_relative as RSpec manages the path for you (lib is in the path, just do require "uncoil").Joshua Cheek
just pushed up the version I'm working with. since the one you pulled, I added dev and runtime dependencies to the gemspec file. And I also ran a bundle update to get the new bitly gem. Running anything inside of the bundle throws an error, but running rspec outside of it completesjstim

1 Answers

6
votes

The problem is that in "lib/uncoil", you define class Uncoil but in "lib/uncoil/version" you define module Uncoil. If the version gets loaded, there will be a conflict in that you're trying to reopen a class that is actually a module (or vice versa, depending on which gets loaded first).

I assume that when you run rspec spec that it doesn't use bundler at all (potential problem, btw, as your dependencies aren't being managed, so you should always do bundle exec rspec spec), so it never loads the .gemspec, which is the only place you require the version file. Presumably Bundler loads the gemspecs, which in turn loads version file, causing the conflict. If you didn't experience this before, I would guess that one of your dependencies (probably guard-rspec) was changed to load Bundler in the newer version.

You might consider specifying versions on the dependencies in the gemspec.