Sha256: af818753df209b71084469711908d03eb86696a55b8a97f251314ec33bf95ac1

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

RSpec.describe Mutant::Env do
  let(:config) { Mutant::Config::DEFAULT.update(jobs: 1, reporter: Mutant::Reporter::Trace.new) }

  context '.new' do
    subject { described_class.new(config) }

    context 'when Module#name calls result in exceptions' do
      it 'warns via reporter' do
        klass = Class.new do
          def self.name
            raise
          end
        end

        expected_warnings = ["Class#name from: #{klass} raised an error: RuntimeError fix your lib to follow normal ruby semantics!"]

        expect { subject }.to change { config.reporter.warn_calls }.from([]).to(expected_warnings)

        # Fix Class#name so other specs do not see this one
        class << klass
          undef :name
          def name
          end
        end
      end
    end

    context 'when Module#name does not return a String or nil' do
      it 'warns via reporter' do
        klass = Class.new do
          def self.name
            Object
          end
        end

        expected_warnings = ["Class#name from: #{klass.inspect} returned #{Object.inspect} instead String or nil. Fix your lib to follow normal ruby semantics!"]

        expect { subject }.to change { config.reporter.warn_calls }.from([]).to(expected_warnings)

        # Fix Class#name so other specs do not see this one
        class << klass
          undef :name
          def name
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mutant-0.6.7 spec/unit/mutant/env_spec.rb