Sha256: 69965b24d45fac9bd0df9f956c16de5758fd06475c0fb52bd4ad94028bdd72fd

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'
require 'tailor/critic'
require 'tailor/configuration/style'

CLASS_LENGTH = {}
CLASS_LENGTH['class_too_long'] =
  %(class Party
  include Clowns
  include Pizza

  def barrel_roll
    puts 'DOABARRELROLL!'
  end
end)

CLASS_LENGTH['parent_class_too_long'] =
  %(class Party

  class Pizza
    include Cheese
    include Yumminess
  end
end)

describe 'Detection of class length' do
  before do
    Tailor::Logger.stub(:log)
    FakeFS.activate!
    File.open(file_name, 'w') { |f| f.write contents }
    critic.check_file(file_name, style.to_hash)
  end

  let(:critic) do
    Tailor::Critic.new
  end

  let(:contents) { CLASS_LENGTH[file_name] }

  let(:style) do
    style = Tailor::Configuration::Style.new
    style.trailing_newlines 0, level: :off
    style.allow_invalid_ruby true, level: :off
    style.max_code_lines_in_class 5

    style
  end

  context 'single class' do
    let(:file_name) { 'class_too_long' }
    specify { critic.problems[file_name].size.should be 1 }
    specify { critic.problems[file_name].first[:type].should == 'max_code_lines_in_class' }
    specify { critic.problems[file_name].first[:line].should be 1 }
    specify { critic.problems[file_name].first[:column].should be 0 }
    specify { critic.problems[file_name].first[:level].should be :error }
  end

  context 'class in a class' do
    let(:file_name) { 'parent_class_too_long' }
    specify { critic.problems[file_name].size.should be 1 }
    specify { critic.problems[file_name].first[:type].should == 'max_code_lines_in_class' }
    specify { critic.problems[file_name].first[:line].should be 1 }
    specify { critic.problems[file_name].first[:column].should be 0 }
    specify { critic.problems[file_name].first[:level].should be :error }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tailor-1.4.1 spec/functional/vertical_spacing/class_length_spec.rb