开发者

Rspec with special characters æ ø å

I am writing a Danish web app, and trying to verify email addresses. These can include the characters æ ø å among others. Here is my rspec code:

User.create(@attr.merge(:email => 'æøå@bætter.nåw.ørg'.to_s)).should be_开发者_如何学Govalid

And my validation in 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

This completely messes up rspec / autotest, which fails horribly with this stack trace:

Exception encountered: # "æøå@bætter.nåw.ørg".to_s)... ...

^> backtrace: /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 block in load' /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 load' /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 map' /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 run' /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 block in run' /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 fork' /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 new' /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 run' /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 perform' /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 loop' /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 block in ': undefined method 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 []' from /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 each' from /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 hook' from /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 run' from /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 ' from /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'

Process finished with exit code 1

Any suggestions as to how I solve this?


Maybe add this to the top of your test file (the one with special characters):

# encoding: UTF-8
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜