【问题标题】:Rspec have_link with accent wordsRspec have_link 带有重音词
【发布时间】:2012-02-18 14:53:09
【问题描述】:

有人经历过这种考验吗?

这样做:

# this works
it { should have_link("Next") } 

但相同的测试使用包含“Próximo”等重音的单词(在葡萄牙语中表示 Next)

# it fails
it { should have_link("Próximo")  }

错误:

1) UserPages index pagination 
     Failure/Error: it { should have_link("Próximo") }
       expected link "Próximo" to return something
     # ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'

Finished in 2.8 seconds
28 examples, 1 failure

user_pages_spec.rb(仅相关代码)

describe "pagination" do
  before(:all) { 30.times { FactoryGirl.create(:user) } }
  after(:all) { User.delete_all }

  it { should_not have_link('delete') }
  it { should have_link("Próximo") }
  it { should have_link('2') }
end

我应该如何做这个测试?

【问题讨论】:

    标签: ruby-on-rails-3 rspec tdd rspec2


    【解决方案1】:

    一种方法是:

    # encoding: utf-8
    

    在您的规范文件的顶部,以便 Ruby 知道该文件包含非 ASCII 字符。

    更多信息:http://nuclearsquid.com/writings/ruby-1-9-encodings/

    【讨论】:

    • 您使用的是什么版本的 Ruby?使用 Ruby 1.9.3、Rails 3.2、RSpec 2.8 和那个评论,我刚刚在一个页面上尝试了it { should have_link("Próximo") },它通过了。
    • rails 3.2.1、ruby 1.9.2p290 和 rspec 2.8.1 - 失败
    • @KleberS。可以通过升级到 Ruby 1.9.3 来修复它吗?一个实用的解决方法可能是只测试正则表达式 /ximo/ 如果 have_link 支持的话
    【解决方案2】:

    您的来源是否指定脚本中包含 Unicode?​​p>

    # encoding: UTF-8 
    

    这是一篇非常好的文章:http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/

    【讨论】:

      【解决方案3】:

      固定。

      有一瞬间我忘记了我是在 Spork 下运行的,我所要做的就是重新启动网络服务器并同时重新启动 Spork。

      提示:如果您正在运行 Nginx,请转到控制台并在您的项目文件夹下键入 touch tmp/restart.txt。它将重新启动 Nginx。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-01-02
        • 2010-11-29
        • 2022-12-14
        • 1970-01-01
        • 1970-01-01
        • 2010-11-28
        • 1970-01-01
        相关资源
        最近更新 更多