Sha256: 73f1b7f9ad5ce10c0014dde5334a601384c15754c9687bc7a36995298ecce74f

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

# coding: utf-8
RSpec::Matchers.define :be_i18n_keys do |expected|
  def locale_re
    /^\w{2}\b/
  end
  
  def extract_keys(actual)
    actual = Term::ANSIColor.uncolor(actual).split("\n").map(&:presence).compact
    actual = actual[3..-2]
    actual = actual.map { |row|
      row[1..-1].gsub(/(?:\s+|^)\|(?:\s+|$)/, '|').gsub(/\s+/, ' ').strip.split(/\s*\|\s*/)
    }.compact
    return [] if actual.empty?
    locale_col = 0
    key_col = 1
    actual.map { |row|
      key = [row[locale_col], row[key_col]].map(&:presence).compact.join('.')
      key = key[0..-2] if key.end_with?(':')
      key
    }.compact
  end

  match do |actual|
    expect(extract_keys(actual).sort).to eq(expected.sort)
  end

  failure_message do |actual|
    e = expected.sort
    a = extract_keys(actual).sort

    <<-MSG.strip
Expected #{e}, but had #{a}. Diff:

missing: #{e-a}
extra:   #{a-e}
    MSG
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n-tasks-0.8.7 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.8.6 spec/support/i18n_tasks_output_matcher.rb