From a53a4d2d67ce7ca09ad224081b87b15e74300352 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 6 Jul 2014 03:00:21 +0000 Subject: [PATCH] Add a spec for matching methods without source location --- lib/mutant/env.rb | 4 ++-- spec/spec_helper.rb | 3 ++- .../mutant/matcher/method/instance_spec.rb | 19 ++++++++++++++++++- .../mutant/matcher/method/singleton_spec.rb | 2 +- .../mutant/matcher/methods/instance_spec.rb | 2 +- .../mutant/matcher/methods/singleton_spec.rb | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/mutant/env.rb b/lib/mutant/env.rb index 3051619a..7e5424f4 100644 --- a/lib/mutant/env.rb +++ b/lib/mutant/env.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f6edbb79..f3e376dc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/unit/mutant/matcher/method/instance_spec.rb b/spec/unit/mutant/matcher/method/instance_spec.rb index a67e1800..0f3a0efc 100644 --- a/spec/unit/mutant/matcher/method/instance_spec.rb +++ b/spec/unit/mutant/matcher/method/instance_spec.rb @@ -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('# 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 diff --git a/spec/unit/mutant/matcher/method/singleton_spec.rb b/spec/unit/mutant/matcher/method/singleton_spec.rb index d8a48634..e79f2db3 100644 --- a/spec/unit/mutant/matcher/method/singleton_spec.rb +++ b/spec/unit/mutant/matcher/method/singleton_spec.rb @@ -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 } diff --git a/spec/unit/mutant/matcher/methods/instance_spec.rb b/spec/unit/mutant/matcher/methods/instance_spec.rb index 1c5e4c2b..f1726eac 100644 --- a/spec/unit/mutant/matcher/methods/instance_spec.rb +++ b/spec/unit/mutant/matcher/methods/instance_spec.rb @@ -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 } } diff --git a/spec/unit/mutant/matcher/methods/singleton_spec.rb b/spec/unit/mutant/matcher/methods/singleton_spec.rb index 4e9718f2..9fe8d1c2 100644 --- a/spec/unit/mutant/matcher/methods/singleton_spec.rb +++ b/spec/unit/mutant/matcher/methods/singleton_spec.rb @@ -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 } }