Sha256: a74c2edc7990ed31d51f084b685a23d072ff5df62078ddabfc453961de73c3f9

Contents?: true

Size: 1.77 KB

Versions: 11

Compression:

Stored size: 1.77 KB

Contents

require 'multi_test/minitest_world'

module MultiTest
  class AssertionLibrary
    def self.detect_best
      available.detect(&:require?)
    end

    def initialize(requirer, extender)
      @requirer = requirer
      @extender = extender
    end

    def require?
      begin
        @requirer.call
        true
      rescue LoadError
        false
      end
    end

    def extend_world(world)
      @extender.call(world)
    end

    private

    def self.null
      AssertionLibrary.new(
        proc { },
        proc { }
      )
    end

    def self.available
      @available ||= [
        AssertionLibrary.new(
          proc { require 'rspec/expectations' },
          proc { |object| object.extend(::RSpec::Matchers) }
        ),
        AssertionLibrary.new(
          proc {
            require 'spec/expectations'
            require 'spec/runner/differs/default'
            require 'ostruct'
          },
          proc { |object|
            options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
            Spec::Expectations.differ = Spec::Expectations::Differs::Default.new(options)
            object.extend(Spec::Matchers)
          }
        ),
        AssertionLibrary.new(
          proc { require 'minitest/assertions' },
          proc { |object| object.extend(MinitestWorld) }
        ),
        AssertionLibrary.new(
          proc { require 'minitest/unit' },
          proc { |object| object.extend(MiniTest::Assertions) }
        ),
        AssertionLibrary.new(
          proc { require 'test/unit/assertions' },
          proc { |object| object.extend(Test::Unit::Assertions) }
        ),
        # Null assertion library must come last to prevent exceptions if
        # unable to load a test framework
        AssertionLibrary.null
      ]
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/multi_test-1.1.0/lib/multi_test/assertion_library.rb
multi_test-1.1.0 lib/multi_test/assertion_library.rb
multi_test-1.0.0 lib/multi_test/assertion_library.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/multi_test-0.1.2/lib/multi_test/assertion_library.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/multi_test-0.1.2/lib/multi_test/assertion_library.rb
multi_test-0.1.2 lib/multi_test/assertion_library.rb