Add a spec for matching methods without source location
This commit is contained in:
parent
4213789903
commit
a53a4d2d67
6 changed files with 25 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 } }
|
||||
|
||||
|
|
|
@ -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 } }
|
||||
|
||||
|
|
Loading…
Reference in a new issue