Sha256: 1c94c858d2dabc4780e319e3de93bb30c25d865e7c168ce2e98e906c734519de

Contents?: true

Size: 1.69 KB

Versions: 11

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

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

      it "should remove trailing whitespace" do
        content =<<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        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 "should remove whitespace with third line" do
        content =<<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        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 "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: RemoveTrailingWhitespaceCheck.new(ignored_files: /user/))
        content =<<-EOF
        class User < ActiveRecord::Base
          has_many :projects
        end
        EOF
        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

11 entries across 11 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.18.1 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.18.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.17.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.16.0 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.7 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.6 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.4 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.3 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.2 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
rails_best_practices-1.15.1 spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb