Add a spec for matching methods without source location

This commit is contained in:
Markus Schirp 2014-07-06 03:00:21 +00:00
parent 4213789903
commit a53a4d2d67
6 changed files with 25 additions and 7 deletions

View file

@ -11,8 +11,8 @@ module Mutant
#
# @api private
#
def self.new(config)
super(config, Cache.new)
def self.new(config, cache = Cache.new)
super(config, cache)
end
# Initialize env

View file

@ -30,7 +30,8 @@ $LOAD_PATH << File.join(TestApp.root, 'lib')
require 'test_app'
module Fixtures
BOOT_ENV = Mutant::Env.new(Mutant::Config::DEFAULT)
TEST_CACHE = Mutant::Cache.new
TEST_ENV = Mutant::Env.new(Mutant::Config::DEFAULT, TEST_CACHE)
end # Fixtures
module ParserHelper

View file

@ -3,7 +3,9 @@ require 'spec_helper'
# rubocop:disable ClassAndModuleChildren
describe Mutant::Matcher::Method::Instance do
let(:env) { Fixtures::BOOT_ENV }
let(:config) { Mutant::Config::DEFAULT.update(reporter: reporter) }
let(:env) { Mutant::Env.new(config, Fixtures::TEST_CACHE) }
let(:reporter) { Mutant::Reporter::Trace.new }
describe '#each' do
subject { object.each { |subject| yields << subject } }
@ -25,6 +27,21 @@ describe Mutant::Matcher::Method::Instance do
node.children[1]
end
context 'when method is defined without source location' do
let(:scope) { Module }
let(:method) { scope.instance_method(:object_id) }
it 'does not emit matcher' do
subject
expect(yields.length).to be(0)
end
it 'does warn' do
subject
expect(reporter.warn_calls.last).to eql('#<UnboundMethod: Module(Kernel)#object_id> does not have valid source location unable to emit matcher')
end
end
context 'when method is defined once' do
let(:base) { __LINE__ }
class self::Foo

View file

@ -6,7 +6,7 @@ describe Mutant::Matcher::Method::Singleton, '#each' do
let(:object) { described_class.new(env, scope, method) }
let(:method) { scope.method(method_name) }
let(:env) { Fixtures::BOOT_ENV }
let(:env) { Fixtures::TEST_ENV }
let(:yields) { [] }
let(:namespace) { self.class }
let(:scope) { self.class::Foo }

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Mutant::Matcher::Methods::Instance, '#each' do
let(:object) { described_class.new(env, Foo) }
let(:env) { Fixtures::BOOT_ENV }
let(:env) { Fixtures::TEST_ENV }
subject { object.each { |matcher| yields << matcher } }

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe Mutant::Matcher::Methods::Singleton, '#each' do
let(:object) { described_class.new(env, Foo) }
let(:env) { Fixtures::BOOT_ENV }
let(:env) { Fixtures::TEST_ENV }
subject { object.each { |matcher| yields << matcher } }