Sha256: f964341273d59c6d31eff15feab796ce39a61a98fe140727652b3bc44cd2a228

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module RailsBestPractices
  module Lexicals
    describe RemoveTrailingWhitespaceCheck do
      let(:runner) { Core::Runner.new(lexicals: described_class.new) }

      it 'removes trailing whitespace' do
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        content = content.gsub("\n", "  \n")
        runner.lexical('app/models/user.rb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq('app/models/user.rb:1 - remove trailing whitespace')
      end

      it 'removes whitespace with third line' do
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        content = content.gsub("d\n", "d  \n")
        runner.lexical('app/models/user.rb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq('app/models/user.rb:3 - remove trailing whitespace')
      end

      it 'does not remove trailing whitespace' do
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        runner.lexical('app/models/user.rb', content)
        expect(runner.errors.size).to eq(0)
      end

      it 'does not check ignored files' do
        runner = Core::Runner.new(lexicals: described_class.new(ignored_files: /user/))
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        content = content.gsub("\n", "  \n")
        runner.lexical('app/models/user.rb', content)
        expect(runner.errors.size).to eq(0)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.23.1 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.23.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.22.1 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.22.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.21.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.20.1 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb