Sha256: 8db8c639919fcb641f6508a45b7257ae5a78534fc5acb63c32210e529fe9d268

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 KB

Contents

RSpec.describe Mutest::Expression::Parser do
  let(:object) { Mutest::Config::DEFAULT.expression_parser }

  describe '#call' do
    subject { object.call(input) }

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

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

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

      it { is_expected.to eql(Mutest::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
    end
  end

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

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

      it { is_expected.to be(nil) }
    end

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

      it { is_expected.to eql(Mutest::Expression::Namespace::Exact.new(scope_name: 'Foo')) }
    end

    context 'on ambiguous expression' do
      let(:object) { described_class.new([test_a, test_b]) }

      let(:test_a) do
        Class.new(Mutest::Expression) do
          include Anima.new
          const_set(:REGEXP, /\Atest-syntax\z/)
        end
      end

      let(:test_b) do
        Class.new(Mutest::Expression) do
          include Anima.new
          const_set(:REGEXP, /^test-syntax$/)
        end
      end

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mutest-0.0.10 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.9 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.8 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.7 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.6 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.5 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.4 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.3 spec/unit/mutest/expression/parser_spec.rb
mutest-0.0.2 spec/unit/mutest/expression/parser_spec.rb