Class: Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedModel

Inherits:
TranslationMatcher show all
Defined in:
lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb

Overview

Instance Method Summary collapse

Methods inherited from TranslationMatcher

#in_available_locales, #in_default_locale, #initialize

Constructor Details

This class inherits a constructor from Ndd::RSpec::Rails::Matchers::TranslationMatcher

Instance Method Details

#descriptionString

Returns a description of this matcher.

Returns:

  • (String)

    a description of this matcher.


24
25
26
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb', line 24

def description
  "have a translated model name in #{locales_as_string(@tested_locales)}"
end

#failure_messageString

Returns details about the failure of this matcher.

Returns:

  • (String)

    details about the failure of this matcher.


29
30
31
32
33
34
35
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb', line 29

def failure_message
  message = ''
  message << "expected '#{@model.class}' to have a translated model name\n"
  message << "but the '#{translation_key}' key was not found\n"
  message << "for the locales: #{locales_as_string(@failed_locales)}"
  message
end

#matches?(model) ⇒ Boolean

Returns true if the model has an associated translation, false otherwise.

Parameters:

  • model (Object)

    the model being tested.

Returns:

  • (Boolean)

    true if the model has an associated translation, false otherwise.


14
15
16
17
18
19
20
21
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb', line 14

def matches?(model)
  @model = model
  @failed_locales = []
  @tested_locales.each do |tested_locale|
    @failed_locales << tested_locale unless translated?(tested_locale, translation_key)
  end
  @failed_locales.empty?
end