Sha256: e014923a80bd7cf8339733b86dd92398b1702e0d4c8b4afe84c73cfeb4af0db6

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

require_relative '../../spec_helper'
require 'tailor/rulers/spaces_before_lbrace_ruler'

describe Tailor::Rulers::SpacesBeforeLbraceRuler do
  subject { Tailor::Rulers::SpacesBeforeLbraceRuler.new 1 }
  before { Tailor::Logger.stub(:log) }

  describe "#count_spaces" do
    context "lexed_line.event_index is 0" do
      let(:lexed_line) do
        l = double "LexedLine"
        l.stub(:event_index).and_return 0
        l.stub(:at).and_return nil

        l
      end

      specify { subject.count_spaces(lexed_line, 1).should be_zero }

      it "sets @do_measurement to false" do
        expect { subject.count_spaces(lexed_line, 1) }.
          to change{subject.instance_variable_get(:@do_measurement)}.from(true).
          to(false)
      end
    end

    context "no space before lbrace" do
      let(:lexed_line) do
        l = double "LexedLine"
        l.stub(:event_index).and_return 1
        l.stub(:at).and_return [[10, 0], :on_const, "HI"]

        l
      end

      specify { subject.count_spaces(lexed_line, 1).should be_zero }
    end

    context "1 space before lbrace" do
      let(:lexed_line) do
        l = double "LexedLine"
        l.stub(:event_index).and_return 1
        l.stub(:at).and_return [[10, 0], :on_sp, " "]

        l
      end

      specify { subject.count_spaces(lexed_line, 1).should == 1 }
    end

    context "> 1 space before lbrace" do
      let(:lexed_line) do
        l = double "LexedLine"
        l.stub(:event_index).and_return 1
        l.stub(:at).and_return [[10, 1], :on_sp, "  "]

        l
      end

      specify { subject.count_spaces(lexed_line, 3).should == 2 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tailor-1.0.0.alpha2 spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb
tailor-1.0.0.alpha spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb