Sha256: 3cddd2c0ba18de4c90c580dcdb5b92b58d48196301f02f28b2130ca1a783ca69

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe Mutant::WarningExpectation do
  let(:object) { described_class.new(expected_warnings) }

  let(:expected_warnings) { [] }
  let(:warnings) { [] }

  let(:warning_a) { "foo.rb:10: warning: We have a problem!\n" }
  let(:warning_b) { "bar.rb:10: warning: We have an other problem!\n" }

  describe '#execute' do
    subject { object.execute(&block) }

    before do
      @called = false
    end

    let(:block) do
      lambda do
        @called = true
        warnings.each(&Kernel.method(:warn))
      end
    end

    it 'executes block' do
      expect { subject }.to change { @called }.from(false).to(true)
    end

    context 'when no warnings occur during block execution' do
      context 'and no warnings are expected' do
        it_should_behave_like 'a command method'
      end

      context 'and warnings are expected' do
        let(:expected_warnings) { [warning_a] }

        it 'raises an expectation error' do
          expect { subject }.to raise_error(Mutant::WarningExpectation::ExpectationError.new([], [warning_a]))
        end
      end
    end

    context 'when warnings occur during block execution' do
      let(:warnings) { [warning_a, warning_b] }

      context 'and only some no warnings are expected' do
        let(:expected_warnings) { [warning_a] }

        it 'raises an expectation error' do
          expect { subject }.to raise_error(Mutant::WarningExpectation::ExpectationError.new([warning_b], []))
        end
      end

      context 'and all warnings are expected' do
        let(:expected_warnings) { [warning_a, warning_b] }

        it_should_behave_like 'a command method'
      end

      context 'and there is an expected warning missing' do
        let(:expected_warnings) { [warning_a] }
        let(:warnings)          { [warning_b] }

        it 'raises an expectation error' do
          expect { subject }.to raise_error(Mutant::WarningExpectation::ExpectationError.new([warning_b], [warning_a]))
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mutant-0.5.24 spec/unit/mutant/warning_expectation.rb
mutant-0.5.23 spec/unit/mutant/warning_expectation.rb
mutant-0.5.22 spec/unit/mutant/warning_expectation.rb
mutant-0.5.21 spec/unit/mutant/warning_expectation.rb
mutant-0.5.20 spec/unit/mutant/warning_expectation.rb
mutant-0.5.19 spec/unit/mutant/warning_expectation.rb
mutant-0.5.18 spec/unit/mutant/warning_expectation.rb
mutant-0.5.17 spec/unit/mutant/warning_expectation.rb
mutant-0.5.16 spec/unit/mutant/warning_expectation.rb
mutant-0.5.15 spec/unit/mutant/warning_expectation.rb
mutant-0.5.14 spec/unit/mutant/warning_expectation.rb
mutant-0.5.13 spec/unit/mutant/warning_expectation.rb
mutant-0.5.12 spec/unit/mutant/warning_expectation.rb
mutant-0.5.11 spec/unit/mutant/warning_expectation.rb