RSpec::Matchers.define :have_translation do |expected|

  match do |page|
    translated_value = I18n.t(expected, default: 'no_translation_found')
    if translated_value == 'no_translation_found'
      @failure_message = "there is no expected translation for #{expected}"
      false
    else
      page.has_content? translated_value
    end
  end

  failure_message do |page|
    @failure_message || "Expected to find translation for #{expected} in:#{page.current_path}"
  end

  def supports_block_expectations?
    false
  end
end
RSpec::Matchers.alias_matcher :have_a_translation_for, :have_translation
