Sha256: 1bd287ea754c587dab5bb29a9a4a22f5fa58167ce58c8d23fe3864fb2b620a46

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8

require 'spec_helper'

module Rubocop
  module Cop
    module Style
      describe SpaceAroundBraces do
        subject(:cop) { SpaceAroundBraces.new }

        it 'registers an offence for left brace without spaces' do
          inspect_source(cop, ['each{ puts }'])
          expect(cop.messages).to eq(["Surrounding space missing for '{'."])
          expect(cop.highlights).to eq(['{'])
        end

        it 'registers an offence for right brace without inner space' do
          inspect_source(cop, ['each { puts}'])
          expect(cop.messages).to eq(
            ["Space missing to the left of '}'."])
          expect(cop.highlights).to eq(['}'])
        end

        it 'accepts an empty hash literal with no space inside' do
          inspect_source(cop,
                         ['view_hash.each do |view_key|',
                          'end',
                          '@views = {}',
                          ''])
          expect(cop.messages).to be_empty
        end

        it 'accepts string interpolation braces with no space inside' do
          inspect_source(cop,
                         ['"A=#{a}"',
                          ':"#{b}"',
                          '/#{c}/',
                          '`#{d}`',
                          'sprintf("#{message.gsub(/%/, \'%%\')}", line)'])
          expect(cop.messages).to be_empty
        end

        it 'accepts braces around a hash literal argument' do
          inspect_source(cop, ["new({'user' => user_params})"])
          expect(cop.messages).to be_empty
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.13.0 spec/rubocop/cop/style/space_around_braces_spec.rb