如何获得我的规格中的minitest capture_io方法?

时间:2012-08-18 17:56:07

标签: rspec2 testunit minitest

这是我的spec/helper.rb文件:

require 'minitest/autorun'
require 'minitest/spec'
require_relative '../lib/launcher'

class MiniTest::Spec
  include MiniTest::Assertions
end

这是spec文件:

require 'helper'

describe Launcher do
  it "should get the stdout" do
    out, err = capture_io do
      warn "You did a bad thing"
    end
    err.should =~ /bad/
  end
end

但是当我运行规范时:

± rake spec                                                                                                          
/Users/millisami/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ./spec/launcher_spec.rb -Ispec:lib
F

Failures:

  1) Launcher should be a launcher for cloud
     Failure/Error: out, err = capture_io do
     NoMethodError:
       undefined method `capture_io' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001012a4840>
     # ./spec/launcher_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00044 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/launcher_spec.rb:4 # launcher should be a launcher for cloud
rake aborted!
/Users/millisami/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec ./spec/launcher_spec.rb -Ispec:lib failed

Tasks: TOP => spec

但是当我使用默认的MiniTest :: Unit方式执行此操作时,它有效吗? 为什么不是规范方式?

1 个答案:

答案 0 :(得分:0)

您的spec_helper.rb应该更像这样:

require 'minitest/unit'
RSpec.configure do |c|
  c.include MiniTest::Assertions
end