Hello all,
I am making my first experiments with rspec, I wanted to do something
like this:
when a user visit the home page of my site he will be redirected
depending on his culture, so if his culture is english he will be
redirected to myapp/en if he is italian to myapp/it and so on…
how can I say this with rspec?
I was trying something like:
it “should redirect to spanish home page” do
get ‘index’ #don’t know how to say the culture is spanish
response.should redirect_to(spanish_home_page)
end
it “should redirect to spanish home page” do
get ‘index’ #don’t know how to say the culture is spanish
response.should redirect_to(spanish_home_page)
end
How does the application detect the user’s “culture”?
How does the application detect the user’s “culture”?
Cheers,
-Tom
Thanks for your reply Tom,
in my home controller I have a line like this for each language:
redirect_to localized_home_page_path :culture => ‘es’ and return if
request.env[‘HTTP_ACCEPT_LANGUAGE’].include? ‘es-ES’
as I said before I am just ‘experimenting and playing’ so any suggestion
is accepted
maybe I should access to the request object from my spec code?
it “should redirect to spanish home page” do
request.env[‘HTTP_ACCEPT_LANGUAGE’] = ‘es-ES’
get ‘index’
response.should redirect_to(spanish_home_page)
end
I didn’t find the cucumber forum, so please forgive me if I am too much
out of topic here.
I was trying to achieve the same with cucumber, so I wrote this:
Scenario Outline: visit home page and get redirect to localized home
page
Given my culture is
When I go to the home page
Then I should be redirected to the
Examples:
| culture | page |
| italian | italian_home_page |
| english | english_home_page |
| french | french_home_page |
| spanish | spanish_home_page |
| german | german_home_page |
| japanese | japanese_home_page |
but I cannot access request.env from a cucumber step, and moreover I
think accessing to request.env from cucumber could tie it too much to
the application, am I right?