yegor256
yegor256

Reputation: 105193

How to use Minitest assertions outside of a class?

I'm trying this:

require 'minitest'
Minitest::Assertions::assert_equal(1, 1)

Doesn't work:

NoMethodError: undefined method `assert_equal' for Minitest::Assertions:Module

What is the right way? The method does exist.

Upvotes: 1

Views: 468

Answers (1)

Panic
Panic

Reputation: 2405

module Assertions
  extend Minitest::Assertions

  class << self
    attr_accessor :assertions
  end

  self.assertions = 0
end

Assertions.assert(true)
Assertions.assert(false)

The Minitest::Assertions module expects to be able to increment an instance accessor named assertions.

http://docs.seattlerb.org/minitest/Minitest/Assertions.html

Upvotes: 1

Related Questions