带有特殊字符 æ 的 Rspec ø å

发布于 2024-11-29 19:38:07 字数 4447 浏览 0 评论 0原文

我正在编写一个丹麦网络应用程序,并尝试验证电子邮件地址。其中可以包括字符 æ ø å 等。这是我的 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:in load_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: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 主循环中的块(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'中 [#]: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: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:in load' 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: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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路黄昏 2024-12-06 19:38:07

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

# encoding: UTF-8

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

# encoding: UTF-8
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文