Sha256: 32ea5ac9a14e18993d977418d5fee12e5fcdb01b54c62e7456f02ace6f53d19f

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::Subject::Method::Metaclass do
  let(:object) do
    described_class.new(
      context:  context,
      node:     node,
      warnings: warnings
    )
  end

  let(:node)     { s(:def, :foo, s(:args)) }
  let(:warnings) { instance_double(Mutant::Warnings) }

  let(:context) do
    Mutant::Context.new(scope, instance_double(Pathname))
  end

  let(:scope) do
    Class.new do
      class << self
        def foo; end

        def name
          'Test'
        end
      end
    end
  end

  describe '#expression' do
    subject { object.expression }

    it { should eql(parse_expression('Test.foo')) }

    it_should_behave_like 'an idempotent method'
  end

  describe '#match_expression' do
    subject { object.match_expressions }

    it { should eql(%w[Test.foo Test*].map(&method(:parse_expression))) }

    it_should_behave_like 'an idempotent method'
  end

  describe '#prepare' do

    subject { object.prepare }

    it 'undefines method on scope' do
      expect { subject }.to change { scope.methods.include?(:foo) }.from(true).to(false)
    end

    it_should_behave_like 'a command method'
  end

  describe '#source' do
    subject { object.source }

    it { should eql("class << self\n  def foo\n  end\nend") }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mutant-0.9.11 spec/unit/mutant/subject/method/metaclass_spec.rb
mutant-0.9.10 spec/unit/mutant/subject/method/metaclass_spec.rb
mutant-0.9.9 spec/unit/mutant/subject/method/metaclass_spec.rb