Sha256: 3e9c8758cb6bfd0b76c094b46106eda6554ec2ddc525bbb74a4503948a6b1076

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8

module StatementModifierHelper
  def check_empty(cop, keyword)
    inspect_source(cop, ["#{keyword} cond",
                         'end'])
    expect(cop.offenses).to be_empty
  end

  def check_really_short(cop, keyword)
    inspect_source(cop, ["#{keyword} a",
                         '  b',
                         'end'])
    expect(cop.messages).to eq(
      ["Favor modifier #{keyword} usage when you have a single-line body."])
    expect(cop.offenses.map { |o| o.location.source }).to eq([keyword])
  end

  def check_too_long(cop, keyword)
    # This statement is one character too long to fit.
    condition = 'a' * (40 - keyword.length)
    body = 'b' * 36
    expect("  #{body} #{keyword} #{condition}".length).to eq(80)

    inspect_source(cop,
                   ["  #{keyword} #{condition}",
                    "    #{body}",
                    '  end'])

    expect(cop.offenses).to be_empty
  end

  def check_short_multiline(cop, keyword)
    inspect_source(cop,
                   ["#{keyword} ENV['COVERAGE']",
                    "  require 'simplecov'",
                    '  SimpleCov.start',
                    'end'])
    expect(cop.messages).to be_empty
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.19.1 spec/support/statement_modifier_helper.rb
rubocop-0.19.0 spec/support/statement_modifier_helper.rb