Sha256: 2ae971d666a8f5bc1a382bce3c0c36eb20a320671203b590498cfdc132f26345

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::AST::Meta::Send do
  let(:object) { described_class.new(node) }

  def parse(source)
    Parser::CurrentRuby.parse(source)
  end

  let(:method_call)            { parse('foo.bar(baz)')  }
  let(:attribute_read)         { parse('foo.bar')       }
  let(:index_assignment)       { parse('foo[0] = bar')  }
  let(:attribute_assignment)   { parse('foo.bar = baz') }
  let(:binary_method_operator) { parse('foo == bar')    }

  class Expectation
    include Adamantium, Anima.new(:name, :assignment, :attribute_assignment, :index_assignment, :binary_method_operator)

    ALL = [
      [:method_call,            false, false, false, false],
      [:attribute_read,         false, false, false, false],
      [:index_assignment,       true,  false, true,  false],
      [:attribute_assignment,   true,  true,  false, false],
      [:binary_method_operator, false, false, false, true]
    ].map do |values|
      new(Hash[anima.attribute_names.zip(values)])
    end.freeze
  end # Expectation

  # Rspec should have a build in for this kind of "n-dimensional assertion with context"
  (Expectation.anima.attribute_names - %i[name]).each do |name|
    describe "##{name}?" do
      subject { object.public_send(:"#{name}?") }

      Expectation::ALL.each do |expectation|
        context "on #{expectation.name}" do
          let(:node) { public_send(expectation.name) }

          it { should be(expectation.public_send(name)) }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mutant-0.8.20 spec/unit/mutant/ast/meta/send_spec.rb
mutant-0.8.19 spec/unit/mutant/ast/meta/send_spec.rb
mutant-0.8.18 spec/unit/mutant/ast/meta/send_spec.rb
mutant-0.8.17 spec/unit/mutant/ast/meta/send_spec.rb