以编程方式运行minitest

时间:2012-08-03 11:50:25

标签: ruby minitest pry

我有这个代码(撬):

class Hash
  def invert_by_array
    each.with_object({}) {|(key,value), obj|
      value.each do |element|
        obj[element] = key
      end
    }
  end
end

require 'minitest/spec'

describe "invert_by_array" do
  it "should use the array element as keys" do
    {'foo' => %w(bar baz)}.invert_by_array.must_equal({'bar' => 'foo', 'baz' => 'foo'})
  end
end

如何在编辑的底部运行测试 - 基本上将上面的内容复制/粘贴到readline?

1 个答案:

答案 0 :(得分:0)

您可以致电MiniTest::Unit.runner.run

来调用跑步者
class Hash
  def invert_by_array
    each.with_object({}) {|(key,value), obj|
      value.each do |element|
        obj[element] = key
      end
    }
  end
end

require 'minitest/spec'

describe "invert_by_array" do
  it "should use the array element as keys" do
    {'foo' => %w(bar baz)}.invert_by_array.must_equal({'bar' => 'foo', 'baz' => 'foo'})
  end
end

MiniTest::Unit.runner.run