带有特殊字符 æ 的 Rspec ø å
我正在编写一个丹麦网络应用程序,并尝试验证电子邮件地址。其中可以包括字符 æ ø å 等。这是我的 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)... ...
^>回溯: /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependency.rb:235:in <代码>加载' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependency.rb:235:in 加载中阻塞' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependency.rb:227:inload_dependency' /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependency.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
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
运行测试' /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初始化中的块' /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 <代码>初始化' /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 <代码>运行' /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:inperform_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
主循环中的块(2 级)' /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' 未处理的异常:[#
块在':未定义的方法] /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:842:in backtrace'中 [#
[]' 来自 /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:828:in]:Array (无方法错误)来自 /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
每个'来自 /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
钩子来自 /Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:344:in运行中的救援 /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运行'来自 /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加载'来自 /Users/houen/.rvm/gems/ruby-1.9.2-p180/bin/autotest:19:in
' from -e:1:inload' from -e:1:in< /代码>'
进程已完成,退出代码为 1
对于如何解决此问题有什么建议吗?
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_valid
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:inload'
block 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:inload_dependency'
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/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419:inblock in load_spec_files'
map'
/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:inload_spec_files'
run'
/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:inrun_tests'
block in run'
/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:inblock in initialize'
fork'
/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:ininitialize'
new'
/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:inrun'
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:inperform_without_block'
perform'
/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:inblock (2 levels) in main_loop'
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:inblock in main_loop' Unhandled exception: [#<ArgumentError: invalid
block in ': undefined method
byte sequence in US-ASCII>]
/Users/houen/.rvm/gems/ruby-1.9.2-p180/gems/ZenTest-4.5.0/lib/autotest.rb:842:inbacktrace' for
[]' from
[#<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:inblock in hook' from
each' 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:inany?' from
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:344:inrescue in run' from
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:inrun' from
' 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:inload' from
' from -e:1:in
/Users/houen/.rvm/gems/ruby-1.9.2-p180/bin/autotest:19:inload' from -e:1:in
'Process finished with exit code 1
Any suggestions as to how I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许将其添加到测试文件的顶部(带有特殊字符的文件):
Maybe add this to the top of your test file (the one with special characters):