views:

70

answers:

1

Hello,

My cucumber scenario tests if my news can be create without a title. This must show "You must specify a title.".

In my news model, I have:

validates_presence_of :title, :message => I18n.t(:specify, :what => 'a title')

and in my en.yml have got :

specify: "You must specify %{what}."

but when I run my test, the result is "translation missing: en, specify".

On the other side, if my I18n.t is in a controller, it works perfectly. And when I go to the browser to test by myself, it also works.

rails 3.0.0, cucumber 0.9.2 and i18n 0.4.1

Thanks in advance.

A: 

I have no direct answer to your question, but after a short look I suggest you use the ActiveRecord error message lookup as described here: Rails I18n API

In your example the validation would then look like this:

validates_presence_of :title

The en.yml would have the following entry:

activerecord:
  errors:
    messages:
      blank: "You must specify the %{attribute}."

Or, to make the message more specific, use any of the other paths that are looked up automatically:

activerecord.errors.models.[model_name].attributes.[attribute_name].blank
activerecord.errors.models.[model_name].blank
activerecord.errors.messages.blank

I am not sure if this fixes your initial problem, but it may be worth a try.

Lysann Kessler