Sha256: c6426ac50268a9fe0c81244924271a7370cae97279c7dc62a5c11783308f7a46

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

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

      it 'removes tab' do
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        content = content.gsub("\n", "\t\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 tab, use spaces instead')
      end

      it 'removes tab with third line' do
        content = <<-EOF
        class User < ActiveRecord::Base
          has_many :projects
  \t
        end
        EOF
        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 tab, use spaces instead')
      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

  \t
        end
        EOF
        content = content.gsub("\n", "\t\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_tab_check_spec.rb
rails_best_practices-1.23.1 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.23.0 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.22.1 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.22.0 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.21.0 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.20.1 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb