Ruby1.9有很酷的Unicode支持,是吗?
# encoding: utf-8
require 'minitest/spec'
require 'minitest/autorun'
describe "test" do
it "α β γ δ & a b c d" do
(1+1).must_equal 3
end
end
# 1) Failure:
# test_0001__a_b_c_d(TestSpec) [test.rb:7]:
# Expected 3, not 2.
我的非拉丁字母呢我应该总是用我糟糕的英语写考试?
因为我可以用任何Unicode符号定义方法:
def α_β_γ_δ_a_b_c_d
puts "geeeek"
end
α_β_γ_δ_a_b_c_d
#=> "geeeek"
我的问题似乎不清楚。我想问如何使minitest的失败描述显示我的非拉丁定义。
最佳答案
它是关于regexp used here的用/\W+/
进行猴修补后,显示utf-8字符。
# encoding: utf-8
require 'minitest/spec'
require 'minitest/autorun'
class MiniTest::Spec < MiniTest::Unit::TestCase
def self.it desc = "anonymous", &block
block ||= proc { skip "(no tests defined)" }
@specs ||= 0
@specs += 1
# regexp /\W+/ replaced with /\s+/
name = "test_%04d_%s" % [ @specs, desc.gsub(/\s+/, '_').downcase ]
define_method name, &block
self.children.each do |mod|
mod.send :undef_method, name if mod.public_method_defined? name
end
end
end
describe "test" do
it "α β γ δ & a b c D" do
(1+1).must_equal 3
end
end
# 1) Failure:
# test_0001_α_β_γ_δ_&_a_b_c_d(test) [forwarding.rb:24]:
# Expected: 3
# Actual: 2
关于ruby - MiniTest和非拉丁测试说明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9430930/