Sha256: e7fcfe2beb74c92d9fda557006558e28693ab6bc3e9a3dc6989d09a64254d1e1

Contents?: true

Size: 2 KB

Versions: 3

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe AktionTest::Matchers::Base do
  before :each do
    matcher_class = define_class('Matcher', described_class) do
      def expectation;         "an expectation";               end
      def problems_for_should; "\na problem\nanother problem"; end
      def problems_for_should_not; "\na problem\nanother problem"; end
    end

    @matcher = matcher_class.new
  end
    
  describe '#failure_message' do
    it "outputs an expectation with associated problems when the matcher is unsuccessful" do
      @matcher.stub(:perform_match! => false)
      @matcher.matches?(nil)
      @matcher.failure_message.should == <<-MSG.strip_heredoc
        Expected an expectation

        a problem
        another problem
      MSG
    end

    it "raises an error if called before running the matcher" do
      expect { @matcher.failure_message }.to raise_error(RuntimeError, /failure message before/)
    end

    it "raises an error if called when the matcher was successful" do
      @matcher.stub(:perform_match! => true)
      @matcher.matches? nil
      expect { @matcher.failure_message }.to raise_error(RuntimeError, /failure message while/)
    end
  end

  describe '#negative_failure_message' do
    before { @matcher.stub(:perform_match! => true) }
    it 'outputs a negative expectation with associated problems when the matcher is successful' do
      @matcher.matches?(nil)
      @matcher.negative_failure_message.should == <<-MSG.strip_heredoc
        Did not expect an expectation

        a problem
        another problem
      MSG
    end

    it "raises an error if called before running the matcher" do
      expect { @matcher.negative_failure_message }.to raise_error(RuntimeError, /negative failure message before/)
    end

    it "raises an error if called when the matcher was unsuccessful" do
      @matcher.stub(:perform_match! => false)
      @matcher.matches? nil
      expect { @matcher.negative_failure_message }.to raise_error(RuntimeError, /negative failure message while/)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aktion_test-0.2.2 spec/matchers/base_spec.rb
aktion_test-0.2.1 spec/matchers/base_spec.rb
aktion_test-0.2.0 spec/matchers/base_spec.rb