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 -- Posted via http://www.ruby-forum.com/.
On 22 Dec 2009, at 11:26, Gnagno Gnagno 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) > endHow does the application detect the user''s "culture"? Cheers, -Tom
Tom Stuart wrote:> How does the application detect the user''s "culture"? > > Cheers, > -TomThanks 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? -- Posted via http://www.ruby-forum.com/.
On Tue, Dec 22, 2009 at 8:25 AM, Gnagno Gnagno <lists at ruby-forum.com> wrote:> Tom Stuart 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'' >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> > 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? > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091222/2f320525/attachment.html>
Thank you very much :) I didn''t know I could access request.env[''HTTP_ACCEPT_LANGUAGE''] in writing, and didn''t even try it -- Posted via http://www.ruby-forum.com/.
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 <culture> When I go to the home page Then I should be redirected to the <page> 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? -- Posted via http://www.ruby-forum.com/.
On 23 Dec 2009, at 10:07, Gnagno Gnagno wrote:> 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.http://wiki.github.com/aslakhellesoy/cucumber/get-in-touch> 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 <culture> > When I go to the home page > Then I should be redirected to the <page> > > 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?Right. You need to ask the cukes group (or the webrat group, or the rails group) about how you pass HTTP headers with your in the step "When I go to the home page".> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-userscheers, Matt http://mattwynne.net +447974 430184
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 :) -- Posted via http://www.ruby-forum.com/.