From 5b3d506523ab3953090370a273fea5cc89ad5d8c Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 21 Jan 2013 23:54:25 +0100 Subject: [PATCH] Reconnect API changes for successful spec run Sorry this looks like spiking around and yeah it was some kind of. --- lib/mutant/context/scope.rb | 22 +++++++-------- lib/mutant/killer/rspec.rb | 6 ++-- lib/mutant/reporter.rb | 5 ++-- lib/mutant/reporter/cli.rb | 15 ++++++++-- lib/mutant/runner.rb | 4 +-- lib/mutant/strategy/rspec/dm2.rb | 6 ++-- lib/mutant/strategy/rspec/dm2/lookup.rb | 2 +- .../strategy/rspec/dm2/lookup/method.rb | 6 ++-- lib/mutant/subject/method.rb | 28 +++++++++++++++++-- .../unit/mutant/cli/class_methods/run_spec.rb | 9 +++--- .../lookup/method/instance/spec_files_spec.rb | 10 +++---- .../method/singleton/spec_files_spec.rb | 10 +++---- 12 files changed, 79 insertions(+), 44 deletions(-) diff --git a/lib/mutant/context/scope.rb b/lib/mutant/context/scope.rb index a5af3690..f51e0a5c 100644 --- a/lib/mutant/context/scope.rb +++ b/lib/mutant/context/scope.rb @@ -76,6 +76,16 @@ module Mutant name_nesting.last end + # Return name + # + # @return [String] + # + # @api private + # + def name + scope.name + end + # Return scope wrapped by context # # @return [::Module|::Class] @@ -105,17 +115,7 @@ module Mutant # @api private # def root_ast - "#{keyword} #{qualified_name}; end".to_ast - end - - # Return qualified name of scope - # - # @return [String] - # - # @api private - # - def qualified_name - scope.name + "#{keyword} #{name}; end".to_ast end # Return nesting of names of scope diff --git a/lib/mutant/killer/rspec.rb b/lib/mutant/killer/rspec.rb index c15160a9..6ff447f9 100644 --- a/lib/mutant/killer/rspec.rb +++ b/lib/mutant/killer/rspec.rb @@ -10,16 +10,16 @@ module Mutant # Run rspec test # # @return [true] - # returns true when test is NOT successful and the mutant was killed + # when test is NOT successful and the mutant was killed # # @return [false] - # returns false otherwise + # otherwise # # @api private # def run mutation.insert - !::RSpec::Core::Runner.run(command_line_arguments, strategy.error_stream, strategy.output_stream).zero? + !!::RSpec::Core::Runner.run(command_line_arguments, strategy.error_stream, strategy.output_stream).nonzero? end memoize :run diff --git a/lib/mutant/reporter.rb b/lib/mutant/reporter.rb index c1a92029..505f697b 100644 --- a/lib/mutant/reporter.rb +++ b/lib/mutant/reporter.rb @@ -58,7 +58,7 @@ module Mutant # # @api private # - def subject(subject) + def subject(_subject) stats.count_subject self end @@ -71,7 +71,7 @@ module Mutant # # @api private # - def mutation(mutation) + def mutation(_mutation) self end @@ -85,7 +85,6 @@ module Mutant # def report_killer(killer) stats.count_killer(killer) - self end diff --git a/lib/mutant/reporter/cli.rb b/lib/mutant/reporter/cli.rb index 52ee6576..4890b657 100644 --- a/lib/mutant/reporter/cli.rb +++ b/lib/mutant/reporter/cli.rb @@ -67,7 +67,7 @@ module Mutant self end - # Report config + # Report start # # @param [Mutant::Config] config # @@ -75,13 +75,24 @@ module Mutant # # @api private # - def print_config + def start(config) message = [] message << 'Mutant configuration:' message << "Matcher: #{config.matcher.inspect}" message << "Filter: #{config.filter.inspect}" message << "Strategy: #{config.strategy.inspect}" puts message.join("\n") + super + end + + # Report stop + # + # @return [self] + # + # @api private + # + def stop + super end # Report killer diff --git a/lib/mutant/runner.rb b/lib/mutant/runner.rb index 2d0481ea..fba638ce 100644 --- a/lib/mutant/runner.rb +++ b/lib/mutant/runner.rb @@ -68,7 +68,7 @@ module Mutant # @api private # def run - reporter.print_config + reporter.start(config) util = strategy util.setup config.matcher.each do |subject| @@ -76,7 +76,7 @@ module Mutant run_subject(subject) end util.teardown - reporter.print_stats + reporter.stop end # Run mutation killers on subject diff --git a/lib/mutant/strategy/rspec/dm2.rb b/lib/mutant/strategy/rspec/dm2.rb index e5fa5915..4e6f8c45 100644 --- a/lib/mutant/strategy/rspec/dm2.rb +++ b/lib/mutant/strategy/rspec/dm2.rb @@ -6,12 +6,14 @@ module Mutant # Return filename pattern # + # @param [Subject] subject + # # @return [Enumerable] # # @api private # - def spec_files(mutation) - ExampleLookup.run(mutation) + def spec_files(subject) + Lookup.run(subject) end end diff --git a/lib/mutant/strategy/rspec/dm2/lookup.rb b/lib/mutant/strategy/rspec/dm2/lookup.rb index ba9d2866..21e94662 100644 --- a/lib/mutant/strategy/rspec/dm2/lookup.rb +++ b/lib/mutant/strategy/rspec/dm2/lookup.rb @@ -42,7 +42,7 @@ module Mutant # @api private # def self.run(subject) - new(subject).spec_files + build(subject).spec_files end REGISTRY = {} diff --git a/lib/mutant/strategy/rspec/dm2/lookup/method.rb b/lib/mutant/strategy/rspec/dm2/lookup/method.rb index 03400e1f..69e4066a 100644 --- a/lib/mutant/strategy/rspec/dm2/lookup/method.rb +++ b/lib/mutant/strategy/rspec/dm2/lookup/method.rb @@ -25,7 +25,7 @@ module Mutant # @api private # def base_path - "spec/unit/#{Inflector.underscore(subject.context_name)}" + "spec/unit/#{Inflector.underscore(subject.context.name)}" end # Return method name @@ -35,7 +35,7 @@ module Mutant # @api private # def method_name - subject.method_name + subject.name end # Test if method is public @@ -58,7 +58,7 @@ module Mutant # @api private # def expanded_name - MethodExpansion.run(subject.method_name) + MethodExpansion.run(method_name) end # Return glob expression diff --git a/lib/mutant/subject/method.rb b/lib/mutant/subject/method.rb index 8d3d106e..8c980a82 100644 --- a/lib/mutant/subject/method.rb +++ b/lib/mutant/subject/method.rb @@ -15,6 +15,28 @@ module Mutant # abstract_method :public? + # Return method name + # + # @return [Symbol] + # + # @api private + # + def name + node.name + end + + private + + # Return scope + # + # @return [Class, Module] + # + # @api private + # + def scope + context.scope + end + # Instance method subjects class Instance < self @@ -29,7 +51,7 @@ module Mutant # @api private # def public? - scope.public_method_defined?(method_name) + scope.public_method_defined?(name) end memoize :public? @@ -42,7 +64,7 @@ module Mutant # @api private # def subtype - "#{context.identification}##{node.name}" + "#{context.identification}##{name}" end end @@ -61,7 +83,7 @@ module Mutant # @api private # def public? - scope.singleton_class.public_method_defined?(method_name) + scope.singleton_class.public_method_defined?(name) end memoize :public? diff --git a/spec/unit/mutant/cli/class_methods/run_spec.rb b/spec/unit/mutant/cli/class_methods/run_spec.rb index 633d4572..2528611a 100644 --- a/spec/unit/mutant/cli/class_methods/run_spec.rb +++ b/spec/unit/mutant/cli/class_methods/run_spec.rb @@ -6,7 +6,7 @@ describe Mutant::CLI, '.run' do let(:object) { described_class } let(:argv) { mock('ARGV') } let(:attributes) { mock('Options') } - let(:runner) { mock('Runner', :fail? => failure) } + let(:runner) { mock('Runner', :success? => success) } let(:instance) { mock(described_class.name, :attributes => attributes) } before do @@ -14,8 +14,8 @@ describe Mutant::CLI, '.run' do Mutant::Runner.stub(:run => runner) end - context 'when runner does NOT fail' do - let(:failure) { false } + context 'when runner is successful' do + let(:success) { true } it { should be(0) } @@ -26,7 +26,7 @@ describe Mutant::CLI, '.run' do end context 'when runner fails' do - let(:failure) { true } + let(:success) { false } it { should be(1) } @@ -35,4 +35,5 @@ describe Mutant::CLI, '.run' do should be(1) end end + end diff --git a/spec/unit/mutant/strategy/rspec/dm2/lookup/method/instance/spec_files_spec.rb b/spec/unit/mutant/strategy/rspec/dm2/lookup/method/instance/spec_files_spec.rb index 5f1bbde1..6fdbca51 100644 --- a/spec/unit/mutant/strategy/rspec/dm2/lookup/method/instance/spec_files_spec.rb +++ b/spec/unit/mutant/strategy/rspec/dm2/lookup/method/instance/spec_files_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance, '#spec_files' do subject { object.spec_files } - let(:object) { described_class.new(mutation_subject) } - let(:mutation_subject) { mock('Subject', :method_name => method_name, :public? => is_public, :context_name => context_name) } - let(:context_name) { 'Foo' } - let(:method_name) { :bar } - let(:files) { 'Files'.freeze } + let(:object) { described_class.new(mutation_subject) } + let(:mutation_subject) { mock('Subject', :name => method_name, :public? => is_public, :context => context) } + let(:context) { mock('Context', :name => 'Foo') } + let(:method_name) { :bar } + let(:files) { 'Files'.freeze } this_example_group = 'Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance#spec_files' diff --git a/spec/unit/mutant/strategy/rspec/dm2/lookup/method/singleton/spec_files_spec.rb b/spec/unit/mutant/strategy/rspec/dm2/lookup/method/singleton/spec_files_spec.rb index 573d85eb..a576f10e 100644 --- a/spec/unit/mutant/strategy/rspec/dm2/lookup/method/singleton/spec_files_spec.rb +++ b/spec/unit/mutant/strategy/rspec/dm2/lookup/method/singleton/spec_files_spec.rb @@ -4,11 +4,11 @@ describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton, '#spec_files' subject { object.spec_files } - let(:object) { described_class.new(mutation_subject) } - let(:mutation_subject) { mock('Subject', :method_name => method_name, :public? => is_public, :context_name => context_name) } - let(:context_name) { 'Foo' } - let(:method_name) { :bar } - let(:files) { 'Files'.freeze } + let(:object) { described_class.new(mutation_subject) } + let(:mutation_subject) { mock('Subject', :name => method_name, :public? => is_public, :context => context) } + let(:method_name) { :bar } + let(:files) { 'Files'.freeze } + let(:context) { mock('Context', :name => 'Foo') } this_example_group = 'Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton#spec_files'