Class: Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedError
- Inherits:
-
TranslationMatcher
- Object
- TranslationMatcher
- Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedError
- Defined in:
- lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb
Overview
Implements #have_a_translated_error.
Instance Method Summary collapse
-
#description ⇒ String
A description of this matcher.
-
#failure_message ⇒ String
Details about the failure of this matcher.
-
#initialize(error) ⇒ HaveATranslatedError
constructor
A new instance of HaveATranslatedError.
-
#matches?(model) ⇒ Boolean
True if the error has an associated translation, false otherwise.
-
#on_attribute(attribute) ⇒ Object
Set the attribute of the error to test.
Methods inherited from TranslationMatcher
#in_available_locales, #in_default_locale
Constructor Details
#initialize(error) ⇒ HaveATranslatedError
Returns a new instance of HaveATranslatedError.
13 14 15 16 |
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb', line 13 def initialize(error) super() @error = error end |
Instance Method Details
#description ⇒ String
Returns a description of this matcher.
38 39 40 41 42 43 |
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb', line 38 def description description = "have a translated error message for '#{@error}'" description << " on '#{@attribute}'" if @attribute.present? description << " in #{locales_as_string(@tested_locales)}" description end |
#failure_message ⇒ String
Returns details about the failure of this matcher.
46 47 48 49 50 51 52 |
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb', line 46 def = "expected '#{subject_as_string}' to have a translated error message for '#{@error}'\n" << "but none of the following keys was found:\n" << "#{translation_keys.map { |l| " - #{l}" }.join("\n")}\n" << "for the locales: #{locales_as_string(@failed_locales)}" end |
#matches?(model) ⇒ Boolean
Returns true if the error has an associated translation, false otherwise.
28 29 30 31 32 33 34 35 |
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb', line 28 def matches?(model) @model = model @failed_locales = [] @tested_locales.each do |tested_locale| @failed_locales << tested_locale unless translated_in?(tested_locale) end @failed_locales.empty? end |
#on_attribute(attribute) ⇒ Object
Set the attribute of the error to test.
21 22 23 24 |
# File 'lib/ndd/rspec/rails/matchers/model/have_a_translated_error.rb', line 21 def on_attribute(attribute) @attribute = attribute self end |