Forum: RSpec Using has_selector to identify responses.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2009-01-13 23:11
This is more of a "best practices" question.

Earlier, when I was trying to understand what it was I was supposed to
be testing with cucumber, I was advised that I should test for text
elements contained in the response body of the expected output.  Now,
what I am wondering is how one accounts for multilingual implementation.

I have hit upon the idea of simply adding special css id selectors to
the templates that identify their use.  So, for example, instead of
looking for the word "Registration" I would look for a css selector
id=user_registration.

I know that this will work but, is there another, preferred, way of
handling this situation?

Regards,
Pat M. (Guest)
on 2009-01-14 00:36
(Received via mailing list)
On Tue, Jan 13, 2009 at 1:11 PM, James B. <removed_email_address@domain.invalid>
wrote:
> id=user_registration.
> http://rubyforge.org/mailman/listinfo/rspec-users
>

semantic markup ftw
(so, yes, your way :)
Aslak H. (Guest)
on 2009-01-14 00:42
(Received via mailing list)
On Tue, Jan 13, 2009 at 10:11 PM, James B. 
<removed_email_address@domain.invalid>
wrote:

> This is more of a "best practices" question.
>

I'll describe a practice that has worked well for me.
(I stopped believing in best practices several years ago :-))


> I know that this will work but, is there another, preferred, way of
> handling this situation?
>

I'm developing a multilingual app now. Based on the user's preferences
it
will display UI elements (text, links etc) in either Norwegian, Nynorsk
(Neo
Norwegian) or** Sámi (the 3 official languages in Norway).

We use Webrat, and for the Cucumber Scenarios we have chosen one
arbitrary
language - Norwegian. (Actually, it's not that arbitrary - it's what all
the
developers speak and write). In order to make the scenarios readable for
the
stakeholders we prefer to refer to use the visible text instead of the
DOM
id or names. (This also verifies that the <label> tags have properly
corresponding "for" attributes). So we say (translated):

When I fill in "Drammensveien 1" for "Address (work)"

This is much better than

When I fill in "Drammensveien 1" for "user_work_address"

So what about the other languages? We don't even think about them in 95%
of
the Cucumber features. We have one feature file that just verifies that
we
get Sámi UI instead of Norwegian when the user sets preferences to that
language. This is to verify that the language switching logic works ok.
We
also have a few RSpec specs to verify the same down at the ActiveRecord
and
Controller level.

HTH,
Aslak
This topic is locked and can not be replied to.