2012-02-24 85 views
2

Ruby 1.9有很酷的Unicode支持,是嗎?MiniTest和非拉丁語測試說明

# 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" 

PS我的問題似乎並不清楚。我想問如何讓minitest的失敗描述顯示我的非拉丁定義。

+0

Downvoted and vote to close。這不是一個問題,這是一個咆哮。咆哮屬於博客,SO是針對問題的。 – 2012-02-24 15:25:20

+0

這是一個問題。我試圖問我怎麼能在故障描述中返回所有的unicode字母 – fl00r 2012-02-24 16:10:37

+0

@JörgW Mittag我已經更新了我的問題,以便更清楚 – fl00r 2012-02-25 11:36:27

回答

2

它是關於regexp used here。它顯示猴子修補後的UTF-8字符/\W+//\s+/

# 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 
+0

酷! https://github.com/seattlerb/minitest/pull/97 :) – fl00r 2012-02-25 20:59:03

+0

'/ [^ [[:word:]] /'? – fl00r 2012-02-25 21:30:30