I am working on a gem (not rails stuff just Ruby) and so far the code is working great but I am having the following error when running "rspec" from the gem root folder:
$ rspec
spec/logfile_spec.rb:3:in `<top (required)>': uninitialized constant LogFile (NameError)
...
This is how my gem is organised:
$ ls -R lib
logmsg logmsg.rb
lib/logmsg:
logfile.rb version.rb yaml
lib/logmsg/yaml:
logmsg.yml
And my specs:
$ ls -R spec/
logfile_spec.rb logmsg_spec.rb spec_helper.rb
Here are the contents of some files:
- spec/spec_helper.rb
require 'logmsg'
RSpec.configure do |config|
...
end
- spec/logmsg_spec.rb (this one works fine when I test it separately)
require 'spec_helper'
describe Logmsg do
it 'has a version number' do
expect(Logmsg::VERSION).not_to be nil
end
end
- spec/logfile_spec.rb (this is the one giving me some headaches)
require 'spec_helper'
describe LogFile do
subject { Logmsg::LogFile.new('test') }
its(:name) { should_not be nil }
its(:datetime_format) { should_not be nil }
its(:format) { should_not be nil }
its(:path) { should_not be nil }
context "registered" do
its(:registered) { should be true }
end
context 'not registered' do
its(:registered) { should be false }
end
end
- lib/logmsg.rb
require 'psych'
require 'logmsg/version'
require 'logmsg/logfile'
module Logmsg
class LogMsg
...
end
end
- lib/logmsg/logfile.rb (this is the one that it had the class not being found)
require 'logger'
module Logmsg
class LogFile
...
end
end
Your help is much appreciated! Thanks!
Aucun commentaire:
Enregistrer un commentaire