% tree
.
├── Rakefile
├── bin
│ └── nvshen
├── nvshen.gemspec
├── lib
│ ├── nvshen
│ │ └── translator.rb
│ └── nvshen.rb
└── test
└── test_nvshen.rb
Rakefile可以让你自动跑测湿:
123456789
% cat Rakefile
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << 'test'
end
desc "Run tests"
task :default => :test
现在执行rake test或者就rake就能跑测湿啦。呵呵,下面是一个女神的基本测湿文件:
1234567891011121314151617181920
% cat test/test_nvshen.rb
require 'test/unit'
require 'nvshen'
class NvshenTest < Test::Unit::TestCase
def test_english_hello
assert_equal "hello nvshen",
nvshen.hi("english")
end
def test_any_hello
assert_equal "hello nvshen",
nvshen.hi("ruby")
end
def test_spanish_hello
assert_equal "你好 女神",
nvshen.hi("chinese")
end
end
最后执行测湿:
12345678910
% rake test
(in /Users/qrush/Dev/ruby/nvshen)
Loaded suite
Started
...
Finished in 0.000736 seconds.
3 tests, 3 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 15331
# The main Nvshen driver
class Nvshen
# Say hi to the world!
#
# Example:
# >> Nvshen.hi("chinese")
# => 你好 女神
#
# Arguments:
# language: (String)
def self.hi(language = "english")
translator = Translator.new(language)
puts translator.hi
end
end