2
我試圖通過這個簡單的斷言的Rails 3.1無效多字節字符(UTF-8)
assert_select '.price', /\€[,\d]+\.\d\d/
在視圖的代碼的。價格類是
<span class="price">
<%= number_to_currency(product.price, options = {:format => "%u%n", :unit => "€"}) %> </span>
當我使用的默認<%= number_to_currency(product.price) %>
一切都很好。當我切換到歐元時,它不會工作。
這是錯誤消息:
/Users/noapologize/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require': /Users/noapologize/rails_projects/depot/test/functional/store_controller_test.rb:11: invalid multibyte char (UTF-8) (SyntaxError)
/Users/noapologize/rails_projects/depot/test/functional/store_controller_test.rb:11: invalid multibyte char (UTF-8)
/Users/noapologize/rails_projects/depot/test/functional/store_controller_test.rb:11: syntax error, unexpected $end, expecting keyword_end
assert_select '.price', /\€[,\d]+\.\d\d/
我想我寫這篇assert_select的方式是錯誤的。有人能啓發我嗎?
謝謝你的時間。
謝謝!它現在有效。這很奇怪,因爲那本實用書有它。我不明白。爲什麼它適用於$而不是€?它是字符或什麼的字節長度?再次感謝您的回答和您的時間。 – storedope
這是因爲美元在regexps中被用作命令字符,所以您需要將其轉義。如果Pragprog書說你需要逃離歐元,那麼你可以對他們的書提出錯誤;-) – Julik