在使用Minitest规格时如何包含mixin?

时间:2015-07-14 13:10:56

标签: ruby minitest

使用Minitest规格时如何添加mixin?

这是Minitest Specs中的测试套件示例:

require "minitest/autorun"

describe Meme do
  before do
    @meme = Meme.new
  end

  describe "when asked about cheeseburgers" do
    it "must respond positively" do
      @meme.i_can_has_cheezburger?.must_equal "OHAI!"
   end
  end
end

1 个答案:

答案 0 :(得分:0)

顶层describe块定义了一个测试用例,与你在编写断言式测试时类定义的方式基本相同,所以你只需像往常一样包含你的mixin模块:

require "minitest/autorun"

describe Meme do
  include MyMixin

  before do
    @meme = Meme.new
  end

  describe "when asked about cheeseburgers" do
    it "must respond positively" do
      @meme.i_can_has_cheezburger?.must_equal "OHAI!"
   end
  end
end

记住:Minitest只是Ruby。