iGEL / it

A helper for links and other html tags in your translations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spec for dot-prefix keys

jamesarosen opened this issue · comments

I tried to write a spec that asserted that It would obey translation keys like ".widgets_link," but I had some trouble getting the spec to work. It looks like It uses ActionView::Helpers::TranslationHelper#t under the hood, so this should work. There's no functionality problem; I was just trying to improve the test suite. If you have any suggestions on how to get that spec to pass, I'd love to hear them.

What I tried:

it 'should support dot-prefixed keys' do
  I18n.backend.store_translations(:en, :widgets => { :show => { :all_widgets => "See %{widgets_link:all widgets}" } })
  @view.it('.all_widgets', :widgets_link => '/widgets').should == 'See <a href="/widgets>all widgets</a>'
end

The problem is that the t method relies on a @_virtual_path instance variable to be available. Other than just setting that instance variable directly on @view, I don't see how to get it in there.

Does your spec work, if you replace it with the normal t method?

Sadly, no. The test in ActionPack itself looks like this. It requires setting up the view paths and having a template to render. That seems like an awful lot of effort to test something that already works.

I agree. It should be easier to test such things, but I think, that's out of the scope of this gem. I've added your spec tough, so I won't break that feature in future releases. See @fc96941