Reputation: 83680
Ruby 1.9 has got cool Unicode support, yeah?
# 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.
Where are my non-Latin letters? I should always write my tests in my horrible English?
Because I can define methods with any Unicode symbol:
def α_β_γ_δ_a_b_c_d
puts "geeeek"
end
α_β_γ_δ_a_b_c_d
#=> "geeeek"
PS My question seems to be not clear. I want to ask how to make minitest's failure description to show my non latin definitions.
Upvotes: 2
Views: 242
Reputation: 867
it is about regexp used here. it shows utf-8 characters after monkey patching /\W+/
with /\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
Upvotes: 2