2012-02-24 3 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と投票閉じるこれは疑問ではありません。 Rantsはブログに属しているので、SOは質問のためのものです。 –

+0

質問です。私はどのように失敗の説明ですべてのユニコードの文字を返すことができるか尋ねようとしていた – fl00r

+0

@JörgW Mittag私はより明確に私の質問を更新しました – fl00r

答えて

2

regexp used hereです。モンキーパッチ/\W+//\s+/のパッチ適用後に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 
+0

クール! https://github.com/seattlerb/minitest/pull/97 :) – fl00r

+0

'/ [^ [[:word:]] /'はどうですか? – fl00r

関連する問題