Spec with user culture

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

any help?

Thanks
Gnagno

On 22 Dec 2009, at 11:26, Gnagno G. wrote:

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”?

Cheers,
-Tom

Tom S. wrote:

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 :slight_smile:

maybe I should access to the request object from my spec code?

On Tue, Dec 22, 2009 at 8:25 AM, Gnagno G. [email protected]
wrote:

request.env[‘HTTP_ACCEPT_LANGUAGE’].include? ‘es-ES’

You can set that explicitly in the example:

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

HTH,
David

Thank you very much :slight_smile:
I didn’t know I could access request.env[‘HTTP_ACCEPT_LANGUAGE’] in
writing, and didn’t even try it

Sorry, I have one more question,

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?

I solved the question concerning cucumber, I will post here the solution
in case someone else will need it:

in my step definitions I just put:

Given /^my culture is (.+)$/ do |culture|
header “HTTP_ACCEPT_LANGUAGE”, “it-IT” if culture == ‘italian’
header “HTTP_ACCEPT_LANGUAGE”, “en-GB” if culture == ‘english’
header “HTTP_ACCEPT_LANGUAGE”, “fr-FR” if culture == ‘french’
header “HTTP_ACCEPT_LANGUAGE”, “es-ES” if culture == ‘spanish’
header “HTTP_ACCEPT_LANGUAGE”, “de-DE” if culture == ‘german’
header “HTTP_ACCEPT_LANGUAGE”, “en-US” if culture == ‘american’
header “HTTP_ACCEPT_LANGUAGE”, “jp-JP” if culture == ‘japanese’
end

and it works :slight_smile: