rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.18k stars 1.04k forks source link

errors after adding the gem rubocop-rspec #2050

Closed Gusarov2k closed 5 years ago

Gusarov2k commented 5 years ago

Hello! Help Wanted ? After adding the gem rubocop-rspec and running rspec, an error appears. I was looking for the answer in google but the proposed solutions did not help me. Thanks for your help!

$ bundle exec rspec spec/models

An error occurred while loading ./spec/models/card_spec.rb.
Failure/Error: require File.expand_path('../config/environment', __dir__)

NameError:
  uninitialized constant Parser::AST
 /home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-0.60.0/lib/rubocop/ast/node.rb:21:in `<module:AST>'
/home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-0.60.0/lib/rubocop/ast/node.rb:4:in `<module:RuboCop>'
/home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-0.60.0/lib/rubocop/ast/node.rb:3:in `<top (required)>'
/home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-0.60.0/lib/rubocop.rb:26:in `require_relative'
/home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-0.60.0/lib/rubocop.rb:26:in `<top (required)>'
/home/ghost/.rvm/gems/ruby-2.2.10@flashcard/gems/rubocop-rspec-1.30.1/lib/rubocop-rspec.rb:4:in `<top (required)>'
./config/application.rb:7:in `<top (required)>'
./config/environment.rb:2:in `require'
./config/environment.rb:2:in `<top (required)>'
./spec/rails_helper.rb:2:in `require'
./spec/rails_helper.rb:2:in `<top (required)>'
./spec/models/card_spec.rb:1:in `require'
./spec/models/card_spec.rb:1:in `<top (required)>'
No examples found.

Gemfile:

group :development, :test do
  gem 'byebug'
  gem 'pry-rails'
  gem 'rails-footnotes', '~> 4.0'
  gem 'rspec-rails', '~> 3.8'
  gem 'rubocop', require: false
  gem 'rubocop-rspec'
end

group :test do
  gem 'capybara'
  gem 'factory_bot_rails'
  gem 'simplecov', require: false
end

rails_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rails'
require 'spec_helper'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

begin
  ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
  puts e.to_s.strip
  exit 1
end

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!
  config.filter_rails_from_backtrace!
  config.include FactoryBot::Syntax::Methods
end

spec/models/card_spec.rb

require 'rails_helper'

RSpec.describe Card, type: :model do
  context 'validation tests' do
    let(:card) { create(:card) }
    it 'all content full' do
      expect(card.valid?).to eq(true)
    end
    it 'ensures original_text presence' do
      card.original_text = nil
      expect(card.valid?).to eq(false)
    end

    it 'ensures translated_text presence' do
      card.translated_text = nil
      expect(card.valid?).to eq(false)
    end

    it 'ensures translated_text != original_text' do
      card.translated_text = 'Дом'
      card.original_text = 'дом'
      expect(card.valid?).to eq(false)
    end

    it 'create date' do
      expect(card.review_date).to eq(Date.today + 3.days)
    end
  end
end

Ruby version: 2.2.10 Rails version: 4.2.10 Rspec version: 3.8.0

fables-tales commented 5 years ago

Rubocop depends on the parser gem, most likely it's failing to bring it along with itself. Given that you added rubocop and did not otherwise have issues with RSpec, I'd suggest this is most likely an issue with Rubocop or rubocop-rspec, and you should follow up with them.

Gusarov2k commented 5 years ago

Thank you!