Sha256: 5c6af17000f45a9a526dc95c9e14a2e250ed8778f8d79060fef6be40815d5346

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

RSpec.describe Mutant::Expression do
  let(:object) { described_class }

  describe '.try_parse' do
    subject { object.try_parse(input) }

    context 'on nonsense' do
      let(:input) { 'foo bar' }

      it { should be(nil) }
    end

    context 'on a valid expression' do
      let(:input) { 'Foo' }

      it { should eql(Mutant::Expression::Namespace::Exact.new('Foo')) }
    end

    context 'on ambiguous expression' do
      class ExpressionA < Mutant::Expression
        register(/\Atest-syntax\z/)
      end

      class ExpressionB < Mutant::Expression
        register(/^test-syntax$/)
      end

      let(:input) { 'test-syntax' }

      it 'raises an exception' do
        expect { subject }.to raise_error(
          Mutant::Expression::AmbiguousExpressionError,
          'Ambiguous expression: "test-syntax"'
        )
      end
    end
  end

  describe '#inspect' do
    let(:object) { described_class.parse('Foo') }
    subject { object.inspect }

    it { should eql('<Mutant::Expression: Foo>') }
    it_should_behave_like 'an idempotent method'
  end

  describe '#_dump' do
    let(:object) { described_class.parse('Foo') }
    subject { object._dump(double('Level')) }

    it { should eql('Foo') }
  end

  describe '.parse' do
    subject { object.parse(input) }

    context 'on nonsense' do
      let(:input) { 'foo bar' }

      it 'raises an exception' do
        expect { subject }.to raise_error(
          Mutant::Expression::InvalidExpressionError,
          'Expression: "foo bar" is not valid'
        )
      end
    end

    context 'on a valid expression' do
      let(:input) { 'Foo' }

      it { should eql(Mutant::Expression::Namespace::Exact.new('Foo')) }
    end
  end

  describe '._load' do
    subject { described_class._load('Foo') }

    it { should eql(described_class.parse('Foo')) }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mutant-0.8.0 spec/unit/mutant/expression_spec.rb
mutant-0.7.9 spec/unit/mutant/expression_spec.rb
mutant-0.7.8 spec/unit/mutant/expression_spec.rb
mutant-0.7.7 spec/unit/mutant/expression_spec.rb
mutant-0.7.6 spec/unit/mutant/expression_spec.rb
mutant-0.7.5 spec/unit/mutant/expression_spec.rb