vendredi 16 août 2019

How to use `expect` at the top level of a Minitest test?

I'm writing some tests using Minitest's 'spec' style. I'd like to be able to have a one-line test using the 'expect' method. For example (invalid):

require 'minitest/autorun'
require 'rspec/expectations/minitest_integration'

describe Tuple do

  describe "A tuple with w=1.0" do   
    a = Tuple.new(42)    
    expect(a.x).to eq 42        
  end

end

I know that I can do this:

describe Tuple do

  describe "A tuple with w=1.0" do   
    a = Tuple.new(42)    
    it { expect(a.x).to eq 42 }
  end

end

But I might as well just it { assert_equal(42, a.x) } for an equivalent one-liner.

Is there a recommended way to be able to use expect in place of it ? Or should I just alias the method?

Aucun commentaire:

Enregistrer un commentaire