Rspec带有特殊字符æøå

时间:2011-08-17 14:48:32

标签: ruby-on-rails-3 rspec special-characters rspec2

我正在撰写丹麦网络应用,并尝试验证电子邮件地址。这些可以包括人物æøå等。这是我的rspec代码:

User.create(@attr.merge(:email => 'æøå@bætter.nåw.ørg'.to_s)).should be_valid

我在User.rb中的验证:

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, :presence => true, :format    => { :with => email_regex, :message => 'must be valid email' }, :uniqueness => true

这完全搞砸了rspec / autotest,它在这个堆栈跟踪中失败了很多:

  

遇到异常:#“æøå@bætter.nåw.ørg”.to_s)...... ......   ^&GT;回溯:   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in   load' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in 阻止加载'   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:in   load_dependency' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in 负载”   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in   block in load_spec_files' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in 映射”   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:in   load_spec_files' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:18:in 运行”   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.6.4/lib/rspec/monkey/spork/test_framework/rspec.rb:5:in   run_tests' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/run_strategy/forking.rb:13:in 阻止运行'   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/forker.rb:21:in   block in initialize' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/forker.rb:18:in 叉”   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/forker.rb:18:in   initialize' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/run_strategy/forking.rb:9:in 新的”   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/run_strategy/forking.rb:9:in   run' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/spork-0.9.0.rc3/lib/spork/server.rb:48:in 运行”   /Users/houen/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1558:in   perform_without_block' /Users/houen/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1518:in 执行”   /Users/houen/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1592:in   block (2 levels) in main_loop' /Users/houen/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1588:in 环”   /Users/houen/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1588:in   block in main_loop' Unhandled exception: [#<ArgumentError: invalid byte sequence in US-ASCII>] /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:842:in 阻止':undefined方法backtrace' for [#<ArgumentError: invalid byte sequence in US-ASCII>]:Array (NoMethodError) from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in []'来自   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in   每个block in hook' from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in 来自   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in   any?' from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in 来自   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:344:in   rescue in run' from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:320:in 从'跑'   /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:241:in   来自run' from /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/bin/autotest:6:in '   /Users/houen/.rvm/gems/ruby-1.9.2-p180/bin/autotest:19:in load' from /Users/houen/.rvm/gems/ruby-1.9.2-p180/bin/autotest:19:in'from -e:1:in load' from -e:1:in'

     

使用退出代码1完成处理

关于我如何解决这个问题的任何建议?

1 个答案:

答案 0 :(得分:1)

也许将它添加到测试文件的顶部(具有特殊字符的文件):

# encoding: UTF-8