Sha256: d6cfc8f65615babfe7920f814f9ef44ce0594ab38e821a2c709d530ab06d15af

Contents?: true

Size: 1.62 KB

Versions: 8

Compression:

Stored size: 1.62 KB

Contents

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

describe Tailor::Rulers::SpacesBeforeRbraceRuler do
  subject { Tailor::Rulers::SpacesBeforeRbraceRuler.new(nil, {}) }
  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 rbrace" 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 rbrace" 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 rbrace" 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 == 2 }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tailor-1.2.1 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.2.0 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.5 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.4 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.3 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.2 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.1 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb
tailor-1.1.0 spec/unit/tailor/rulers/spaces_before_rbrace_ruler_spec.rb