Sha256: 7df379464f0f1c0cfac92d55cd2e3d011e4fd9d2067360c8e2f3e848a71272ec

Contents?: true

Size: 1.19 KB

Versions: 3

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 having 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

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.21.0 spec/support/statement_modifier_helper.rb
rubocop-0.20.1 spec/support/statement_modifier_helper.rb
rubocop-0.20.0 spec/support/statement_modifier_helper.rb