Sha256: 7d3224f439a5449ab8fae6cacb30364afb7db8af41065e245d0610a7df3c3c4a

Contents?: true

Size: 1.05 KB

Versions: 5

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'analysers_test_helper'
require 'rubycritic/analysers/helpers/methods_counter'

describe RubyCritic::MethodsCounter do
  describe '#count' do
    context 'when a file contains Ruby code' do
      it 'calculates the number of methods' do
        analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb')
        RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 2
      end
    end

    context 'when a file is empty' do
      it 'returns 0 as the number of methods' do
        analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb')
        RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
      end
    end

    context 'when a file is unparsable' do
      it 'does not blow up and returns 0 as the number of methods' do
        analysed_module = AnalysedModuleDouble.new(path: 'test/samples/unparsable.rb')
        capture_output_streams do
          RubyCritic::MethodsCounter.new(analysed_module).count.must_equal 0
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubycritic-3.4.0 test/lib/rubycritic/analysers/helpers/methods_counter_test.rb
rubycritic-3.3.0 test/lib/rubycritic/analysers/helpers/methods_counter_test.rb
rubycritic-3.2.3 test/lib/rubycritic/analysers/helpers/methods_counter_test.rb
rubycritic-3.2.2 test/lib/rubycritic/analysers/helpers/methods_counter_test.rb
rubycritic-3.2.1 test/lib/rubycritic/analysers/helpers/methods_counter_test.rb