导轨|如何创建非ASCII规范?

时间:2011-08-15 18:59:24

标签: ruby-on-rails internationalization rspec

代码

welcomes_spec.rb

...
describe "GET /welcomes" do
  it "Should render main page" do
    visit root_path
    page.should have_content(t("popular_photos"))
  end
end
...

ru.yml

...
ru:
  hello: "Hello world"
  default_page_title: "Test_page_title"
  main_page: "Главная"
  popular_photos:  !NON ASCII SYMBOLS HERE!
$rake spec导致错误后

Failure/Error: page.should have_content(t("popular_photos"))
NoMethodError:
  undefined method `t' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1:0xba77028>

我是新手,不知道如何解决它。

1 个答案:

答案 0 :(得分:2)

简单地替换:

page.should have_content(t("popular_photos"))

使用:

page.should have_content(I18n.translate("popular_photos"))