Sha256: de00bd7d854fbfd0cff0d7dd481502d6180421e3186e81a7ef9bc033ec6dfd91

Contents?: true

Size: 922 Bytes

Versions: 17

Compression:

Stored size: 922 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|
      next if row =~ /^\|\s+\|/
      row.gsub(/(?:\s|^)\|(?:\s|$)/, ' ').gsub(/\s+/, ' ').strip.split(' ').map(&:presence).compact
    }.compact
    return [] if actual.empty?
    locale_col = 0
    key_col = 1
    actual.map { |row|
      key =
      key = "#{row[locale_col]}.#{row[key_col]}"
      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

17 entries across 17 versions & 1 rubygems

Version Path
i18n-tasks-0.7.12 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.11 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.10 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.9 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.8 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.7 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.6 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.5 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.4 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.3 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.2 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.1 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.7.0 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.6.3 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.6.2 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.6.1 spec/support/i18n_tasks_output_matcher.rb
i18n-tasks-0.6.0 spec/support/i18n_tasks_output_matcher.rb