Sha256: 9d11bdc176cb77e973215e6011850f7eeabc6006d8570b3983951a3b77537eab

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

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

      it 'should remove 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 'should remove 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 'should 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 'should not check ignored files' do
        runner = Core::Runner.new(lexicals: RemoveTabCheck.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

5 entries across 5 versions & 1 rubygems

Version Path
rails_best_practices-1.20.0 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.19.5 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.19.4 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.19.3 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
rails_best_practices-1.19.2 spec/rails_best_practices/lexicals/remove_tab_check_spec.rb