RSpec does not load my class, even if it loads in the Rails console

I have a class inside app/models/parser called data.rb with the contents:

 class Parser::Data def method1 end end 

Nothing special at the moment. I am trying to write a test for it, before I implement too much, I just installed RSpec for Rails.

My RSpec file is located in spec/models/parser/data_spec.rb and is very simple:

 require 'spec_helper.rb' describe Parser::Data do let(:parser) { Parser::Data.new } end 

When I run the test, I get this error:

 spec/models/parser/data_spec.rb:3:in `<top (required)>': uninitialized constant Parser (NameError) 

I tried to place the module Parser around the Data class in the same directory app/models/parser , I also tried to move it to lib/parser , doing the same module packaging class, and added lib/parser to autoload in application.rb , but nothing yet not done.

What am I doing wrong?

+1
ruby ruby-on-rails ruby-on-rails-4 rspec rspec-rails
Apr 19 '16 at 2:54 on
source share
1 answer

require 'rails_helper' instead of spec_helper . Requiring only spec_helper reproduces the problem for me, and it requires rails_helper . Learn more about spec_helper and rails_helper (including performance implications) here: How is spec / rails_helper.rb different from spec / spec_helper.rb? Do I need her?

I reproduced the problem by running RSpec using bundle exec rspec . If I started RSpec using bin/rspec (which is a binstub created using spring -commands-rspec gem), it doesn't matter which helper file I need. I think spring loads more willingly.

+1
Apr 19 '16 at 15:42
source share



All Articles