2012-03-05 57 views
2

我的Capybaras测试仅适用于默认语言环境,不适用于指定的语言环境。无法通过:语言环境到水豚的方法访问

describe "How it works" do 
    it "should have the content 'how it works'" do 
    visit how_it_works_url(:locale => :en) 
    page.should have_content('How it works')  
    end 
    it "should have the content 'wie es geht'" do 
    visit how_it_works_url(:locale => :de) 
    page.should have_content('Wie es geht')  
    end 
end 

如果default_locale是'en',则第一次测试通过,如果是'de',则第二次通过。

这两条路线都没有翻译过(我使用gem'rails-translate-routes')也没有内容。

回答

2

也许这会有所帮助:使用capybara

时对于rspec的

路径不能正常工作,就可以把这个片段在spec/support/locale.rb例如:了解更多详情

# workaround, to set default locale for ALL spec 
class ActionView::TestCase::TestController 
    def default_url_options(options={}) 
    { :locale => I18n.default_locale } 
    end 
end 

class ActionDispatch::Routing::RouteSet 
    def default_url_options(options={}) 
    { :locale => I18n.default_locale } 
    end 
end 

here