From 28a7c61c6627c86ecfe4981c5649c9c13f5b5336 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:19:36 +0200 Subject: [PATCH 01/43] Add large_binomials to list of projects using mutant --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ec3b52dd..456ae670 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ The following projects adopted mutant, and aim 100% mutation coverage: * [virtus](https://github.com/solnic/virtus) * [quacky](https://github.com/benmoss/quacky) * [substation](https://github.com/snusnu/substation) +* [large_binomials](https://github.com/filipvanlaenen/large_binomials) * various small/minor stuff under https://github.com/mbj Feel free to ping me to add your project to the list! From 919b9a6cb068032f4a827088626c0b06d2dd0460 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 11:33:49 -0700 Subject: [PATCH 02/43] Add mutant gemset configuration --- .ruby-gemset | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-gemset diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 00000000..8156e054 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +mutant From 86b79302f34a01d49d98f10f81350c9d9eba9d2a Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 11:36:12 -0700 Subject: [PATCH 03/43] Upgrade gem dependencies --- Gemfile | 11 ++++++++--- Gemfile.devtools | 8 ++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 23cb128c..43bb92cc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,13 @@ +# encoding: utf-8 + source 'https://rubygems.org' gemspec -gem 'mutant', path: '.' +gem 'mutant', path: '.' -gem 'devtools', git: 'https://github.com/rom-rb/devtools.git' -eval(File.read(File.join(File.dirname(__FILE__), 'Gemfile.devtools'))) +group :development, :test do + gem 'devtools', git: 'https://github.com/rom-rb/devtools.git' +end + +eval_gemfile File.join(File.dirname(__FILE__), 'Gemfile.devtools') diff --git a/Gemfile.devtools b/Gemfile.devtools index 00c1f2e1..654cd80e 100644 --- a/Gemfile.devtools +++ b/Gemfile.devtools @@ -3,7 +3,7 @@ group :development do gem 'rake', '~> 10.1.0' gem 'rspec', '~> 2.14.1' - gem 'yard', '~> 0.8.6.2' + gem 'yard', '~> 0.8.7' end group :yard do @@ -31,7 +31,7 @@ end group :metrics do gem 'coveralls', '~> 0.6.7' - gem 'flay', '~> 2.3.1' + gem 'flay', '~> 2.4.0' gem 'flog', '~> 4.1.1' gem 'reek', '~> 1.3.1', git: 'https://github.com/troessner/reek.git' gem 'rubocop', '~> 0.10.0', git: 'https://github.com/bbatsov/rubocop.git' @@ -41,10 +41,6 @@ group :metrics do platforms :ruby_19, :ruby_20 do gem 'yard-spellcheck', '~> 0.1.5' end - - platforms :rbx do - gem 'pelusa', '~> 0.2.2' - end end group :benchmarks do From ee0c4663e329b91dd758cc831c360bf38f9154a1 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 12:15:55 -0700 Subject: [PATCH 04/43] Update Guardfile to match other ROM related gems --- Guardfile | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Guardfile b/Guardfile index b0ce4ed9..78a66cbc 100644 --- a/Guardfile +++ b/Guardfile @@ -2,17 +2,31 @@ guard :bundler do watch('Gemfile') + watch('Gemfile.lock') + watch(%w{.+.gemspec\z}) end -guard :rspec, :cli => '--fail-fast', :all_on_start => false, :all_after_pass => false do - # run all specs if the spec_helper or supporting files files are modified - watch('spec/spec_helper.rb') { 'spec/unit' } - watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec/unit' } +guard :rspec, cli: File.read('.rspec').split.push('--fail-fast').join(' '), keep_failed: false do + # Run all specs if configuration is modified + watch('.rspec') { 'spec' } + watch('Guardfile') { 'spec' } + watch('Gemfile.lock') { 'spec' } + watch('spec/spec_helper.rb') { 'spec' } - # run unit specs if associated lib code is modified - watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] } - watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec/unit' } + # Run all specs if supporting files files are modified + watch(%r{\Aspec/(?:fixtures|lib|support|shared)/.+\.rb\z}) { 'spec' } - # run a spec if it is modified + # Run unit specs if associated lib code is modified + watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}*"] } + watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}*"] } + watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' } + + # Run a spec if it is modified watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z}) end + +guard :rubocop, cli: %w[--config config/rubocop.yml] do + watch(%r{.+\.(?:rb|rake)\z}) + watch(%r{\Aconfig/rubocop\.yml\z}) { |m| File.dirname(m[0]) } + watch(%r{(?:.+/)?\.rubocop\.yml\z}) { |m| File.dirname(m[0]) } +end From 5463079393219aa54621182502eab5360e3ef60d Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 12:16:12 -0700 Subject: [PATCH 05/43] Update rubocop config to allow the current longest line in the code --- config/rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/rubocop.yml b/config/rubocop.yml index 2fde9f3d..b629f060 100644 --- a/config/rubocop.yml +++ b/config/rubocop.yml @@ -35,7 +35,7 @@ AccessControl: # Limit line length LineLength: - Max: 79 + Max: 124 # TODO: lower to 79 # Disable documentation checking until a class needs to be documented once Documentation: From ee72d6c042558e6843fa840f3e47d6659b186bc0 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 12:16:45 -0700 Subject: [PATCH 06/43] Fix rubocop warnings * Still a few more to go, but this should be the majority of them --- lib/mutant/cli.rb | 6 ++--- lib/mutant/cli/classifier.rb | 4 ++-- lib/mutant/cli/classifier/method.rb | 2 +- lib/mutant/cli/classifier/namespace.rb | 4 ++-- lib/mutant/cli/classifier/scope.rb | 2 +- lib/mutant/constants.rb | 5 ++-- lib/mutant/context/scope.rb | 2 +- lib/mutant/matcher/method.rb | 3 ++- lib/mutant/matcher/namespace.rb | 4 ++-- lib/mutant/mutation.rb | 7 +++--- lib/mutant/mutation/filter/code.rb | 2 +- lib/mutant/mutator.rb | 2 +- lib/mutant/reporter/cli/printer/mutation.rb | 11 +++++---- lib/mutant/singleton_methods.rb | 6 ++--- lib/mutant/strategy/rspec/dm2/lookup.rb | 4 ++-- lib/mutant/zombifier.rb | 8 +++---- spec/integration/mutant/rspec_killer_spec.rb | 2 +- spec/spec_helper.rb | 2 +- spec/support/compress_helper.rb | 8 +++---- .../matcher/method/instance/each_spec.rb | 24 +++++++------------ .../matcher/method/singleton/each_spec.rb | 22 +++++++---------- spec/unit/mutant/mutator/emit_new_spec.rb | 4 ++-- spec/unit/mutant/mutator/emit_spec.rb | 4 ++-- .../mutant/mutator/node/literal/nil_spec.rb | 7 ++---- .../mutant/mutator/node/literal/range_spec.rb | 4 ++-- .../mutator/node/masgn/mutation_spec.rb | 7 ++---- .../mutator/node/while/mutation_spec.rb | 2 +- .../mutant/runner/config/subjects_spec.rb | 6 +++-- .../runner/config/success_predicate_spec.rb | 1 + .../mutant/runner/mutation/killer_spec.rb | 2 +- .../runner/subject/success_predicate_spec.rb | 4 ++-- 31 files changed, 77 insertions(+), 94 deletions(-) diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index 34d6ebaf..a14b21d2 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -38,7 +38,7 @@ module Mutant # # @api private # - def initialize(arguments=[]) + def initialize(arguments = []) @filters, @matchers = [], [] @cache = Mutant::Cache.new @@ -148,7 +148,7 @@ module Mutant # # @api private # - def add_filter(klass,filter) + def add_filter(klass, filter) @filters << klass.new(filter) end @@ -267,7 +267,7 @@ module Mutant add_filter Mutation::Filter::Code, filter end.on('--fail-fast', 'Fail fast') do set_fail_fast - end.on('-d','--debug', 'Enable debugging output') do + end.on('-d', '--debug', 'Enable debugging output') do set_debug end.on_tail('-h', '--help', 'Show this message') do puts opts diff --git a/lib/mutant/cli/classifier.rb b/lib/mutant/cli/classifier.rb index f25ebe1e..f7749758 100644 --- a/lib/mutant/cli/classifier.rb +++ b/lib/mutant/cli/classifier.rb @@ -12,7 +12,7 @@ module Mutant SCOPE_PATTERN = /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze CBASE_PATTERN = /\A::/.freeze SCOPE_OPERATOR = '::'.freeze - SINGLETON_PATTERN = %r(\A(#{SCOPE_PATTERN})\z).freeze + SINGLETON_PATTERN = /\A(#{SCOPE_PATTERN})\z/.freeze REGISTRY = [] @@ -36,7 +36,7 @@ module Mutant # @api private # def self.constant_lookup(location) - location.gsub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR).inject(Object) do |parent, name| + location.gsub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR).reduce(Object) do |parent, name| parent.const_get(name) end end diff --git a/lib/mutant/cli/classifier/method.rb b/lib/mutant/cli/classifier/method.rb index dbd188f6..ff1df8bd 100644 --- a/lib/mutant/cli/classifier/method.rb +++ b/lib/mutant/cli/classifier/method.rb @@ -10,7 +10,7 @@ module Mutant '#' => Matcher::Methods::Instance }.freeze - REGEXP = %r(\A(#{SCOPE_PATTERN})([.#])(#{METHOD_NAME_PATTERN}\z)).freeze + REGEXP = /\A(#{SCOPE_PATTERN})([.#])(#{METHOD_NAME_PATTERN}\z)/.freeze # Positions of captured regexp groups SCOPE_NAME_POSITION = 1 diff --git a/lib/mutant/cli/classifier/namespace.rb b/lib/mutant/cli/classifier/namespace.rb index f86b0193..f065a788 100644 --- a/lib/mutant/cli/classifier/namespace.rb +++ b/lib/mutant/cli/classifier/namespace.rb @@ -29,14 +29,14 @@ module Mutant # Recursive namespace classifier class Recursive < self - REGEXP = %r(\A(#{SCOPE_PATTERN})\*\z).freeze + REGEXP = /\A(#{SCOPE_PATTERN})\*\z/.freeze MATCHER = Matcher::Namespace register end # Recursive # Recursive namespace classifier class Flat < self - REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze + REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze MATCHER = Matcher::Scope register end # Flat diff --git a/lib/mutant/cli/classifier/scope.rb b/lib/mutant/cli/classifier/scope.rb index 32df9aae..81c4d350 100644 --- a/lib/mutant/cli/classifier/scope.rb +++ b/lib/mutant/cli/classifier/scope.rb @@ -5,7 +5,7 @@ module Mutant # Scope classifier class Scope < self - REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze + REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze private diff --git a/lib/mutant/constants.rb b/lib/mutant/constants.rb index 2334da08..12132552 100644 --- a/lib/mutant/constants.rb +++ b/lib/mutant/constants.rb @@ -17,8 +17,7 @@ module Mutant ].to_set.freeze # Set of node types that are not valid when emitted standalone - NOT_STANDALONE = [ :splat, :block_pass ].to_set.freeze - + NOT_STANDALONE = [:splat, :block_pass].to_set.freeze OPERATOR_EXPANSIONS = { :<=> => :spaceship_operator, @@ -50,7 +49,7 @@ module Mutant :'!' => :negation_operator }.freeze - INDEX_OPERATORS = [ :[], :[]= ].freeze + INDEX_OPERATORS = [:[], :[]=].freeze UNARY_METHOD_OPERATORS = [ :~@, :+@, :-@, :'!' diff --git a/lib/mutant/context/scope.rb b/lib/mutant/context/scope.rb index c3135994..ed2793be 100644 --- a/lib/mutant/context/scope.rb +++ b/lib/mutant/context/scope.rb @@ -12,7 +12,7 @@ module Mutant # @api private # def root(node) - nesting.reverse.inject(node) do |current, scope| + nesting.reverse.reduce(node) do |current, scope| self.class.wrap(scope, current) end end diff --git a/lib/mutant/matcher/method.rb b/lib/mutant/matcher/method.rb index be32992a..596b45de 100644 --- a/lib/mutant/matcher/method.rb +++ b/lib/mutant/matcher/method.rb @@ -6,7 +6,8 @@ module Mutant # Methods within rbx kernel directory are precompiled and their source # cannot be accessed via reading source location - BLACKLIST = %r(\A#{Regexp.union('kernel/', '(eval)')}).freeze + SKIP_METHODS = %w[kernel/ (eval)].freeze + BLACKLIST = /\A#{Regexp.union(*SKIP_METHODS)}/.freeze # Enumerate matches # diff --git a/lib/mutant/matcher/namespace.rb b/lib/mutant/matcher/namespace.rb index 9f38f38f..b03435dd 100644 --- a/lib/mutant/matcher/namespace.rb +++ b/lib/mutant/matcher/namespace.rb @@ -34,7 +34,7 @@ module Mutant # @api private # def pattern - %r(\A#{Regexp.escape(namespace.name)}(?:::)?) + /\A#{Regexp.escape(namespace.name)}(?:::)?/ end memoize :pattern @@ -62,7 +62,7 @@ module Mutant # def emit_scope(scope) name = scope.name - # FIXME Fix nokogiri to return a string here + # FIXME: Fix nokogiri to return a string here return unless name.kind_of?(String) if pattern =~ name yield scope diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index 05595d0c..e505f25d 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -42,10 +42,9 @@ module Mutant # Insert mutated node # - # FIXME: - # Cache subject visibility in a better way! Ideally dont mutate it implicitly. - # Also subject.public? should NOT be a public interface it is a detail of method - # mutations. + # FIXME: Cache subject visibility in a better way! Ideally dont mutate it + # implicitly. Also subject.public? should NOT be a public interface it + # is a detail of method mutations. # # @return [self] # diff --git a/lib/mutant/mutation/filter/code.rb b/lib/mutant/mutation/filter/code.rb index 598d3edc..084e7bf2 100644 --- a/lib/mutant/mutation/filter/code.rb +++ b/lib/mutant/mutation/filter/code.rb @@ -21,7 +21,7 @@ module Mutant mutation.code.eql?(code) end - PATTERN = %r(\Acode:([a-f0-9]{1,6})\z).freeze + PATTERN = /\Acode:([a-f0-9]{1,6})\z/.freeze # Test if class handles string # diff --git a/lib/mutant/mutator.rb b/lib/mutant/mutator.rb index 6bc3f58e..ba96d316 100644 --- a/lib/mutant/mutator.rb +++ b/lib/mutant/mutator.rb @@ -12,7 +12,7 @@ module Mutant # # @api private # - def self.each(node, parent=nil, &block) + def self.each(node, parent = nil, &block) return to_enum(__method__, node, parent) unless block_given? Registry.lookup(node).new(node, parent, block) diff --git a/lib/mutant/reporter/cli/printer/mutation.rb b/lib/mutant/reporter/cli/printer/mutation.rb index 7c3c3f24..dba73fa4 100644 --- a/lib/mutant/reporter/cli/printer/mutation.rb +++ b/lib/mutant/reporter/cli/printer/mutation.rb @@ -54,11 +54,12 @@ module Mutant # Reporter for noop mutations class Noop < self - MESSAGE = - "Parsed subject AST:\n" \ - "%s\n" \ - "Unparsed source:\n" \ - "%s\n" + MESSAGE = [ + 'Parsed subject AST:', + '%s', + 'Unparsed source:', + '%s', + ].join("\n") private diff --git a/lib/mutant/singleton_methods.rb b/lib/mutant/singleton_methods.rb index 179ff79d..6e773aa3 100644 --- a/lib/mutant/singleton_methods.rb +++ b/lib/mutant/singleton_methods.rb @@ -12,13 +12,13 @@ module Mutant # def self.singleton_subclass_instance(name, superclass, &block) klass = Class.new(superclass) do - - def inspect; self.class.name; end + def inspect + self.class.name + end define_singleton_method(:name) do "#{superclass.name}::#{name}".freeze end - end klass.class_eval(&block) superclass.const_set(name, klass.new) diff --git a/lib/mutant/strategy/rspec/dm2/lookup.rb b/lib/mutant/strategy/rspec/dm2/lookup.rb index 4cd0640e..aa98ecdd 100644 --- a/lib/mutant/strategy/rspec/dm2/lookup.rb +++ b/lib/mutant/strategy/rspec/dm2/lookup.rb @@ -38,13 +38,13 @@ module Mutant # @api private # def self.handle(subject_class) - REGISTRY[subject_class]=self + REGISTRY[subject_class] = self end private_class_method :handle # Build lookup object # - # @param [Subjecŧ] subject + # @param [Subject] subject # # @return [Lookup] # diff --git a/lib/mutant/zombifier.rb b/lib/mutant/zombifier.rb index 70c1af58..ab97fbc9 100644 --- a/lib/mutant/zombifier.rb +++ b/lib/mutant/zombifier.rb @@ -141,10 +141,10 @@ module Mutant # def self.find_uncached(logical_name) file_name = - unless logical_name.end_with?('.rb') - "#{logical_name}.rb" - else + if logical_name.end_with?('.rb') logical_name + else + "#{logical_name}.rb" end $LOAD_PATH.each do |path| @@ -248,7 +248,7 @@ module Mutant # @api private # def root_file - File.find(name) || raise("No root file!") + File.find(name) or raise 'No root file!' end memoize :root_file diff --git a/spec/integration/mutant/rspec_killer_spec.rb b/spec/integration/mutant/rspec_killer_spec.rb index 182930a3..13ec5ebd 100644 --- a/spec/integration/mutant/rspec_killer_spec.rb +++ b/spec/integration/mutant/rspec_killer_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Mutant,'rspec integration' do +describe Mutant, 'rspec integration' do around do |example| Dir.chdir(TestApp.root) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1e8c9795..9a147158 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ require 'mutant' require 'devtools' Devtools.init_spec_helper -$: << File.join(TestApp.root,'lib') +$LOAD_PATH << File.join(TestApp.root, 'lib') require 'test_app' diff --git a/spec/support/compress_helper.rb b/spec/support/compress_helper.rb index 7bc827af..3e96dc7e 100644 --- a/spec/support/compress_helper.rb +++ b/spec/support/compress_helper.rb @@ -1,10 +1,8 @@ module CompressHelper def strip_indent(string) - lines = string.lines - match = /\A( *)/.match(lines.first) + lines = string.lines + match = /\A( *)/.match(lines.first) whitespaces = match[1].to_s.length - stripped = lines.map do |line| - line[whitespaces..-1] - end.join + lines.map { |line| line[whitespaces..-1] }.join end end diff --git a/spec/unit/mutant/matcher/method/instance/each_spec.rb b/spec/unit/mutant/matcher/method/instance/each_spec.rb index d1eda4d4..1e552382 100644 --- a/spec/unit/mutant/matcher/method/instance/each_spec.rb +++ b/spec/unit/mutant/matcher/method/instance/each_spec.rb @@ -1,23 +1,17 @@ require 'spec_helper' describe Mutant::Matcher::Method::Instance, '#each' do - let(:cache) { Fixtures::AST_CACHE } - let(:object) { described_class.new(cache, scope, method) } - let(:method) { scope.instance_method(method_name) } - - let(:yields) { [] } - - let(:namespace) do - klass = self.class - end - - let(:scope) { self.class::Foo } - subject { object.each { |subject| yields << subject } } - let(:type) { :def } - let(:method_name) { :bar } - let(:method_arity) { 0 } + let(:cache) { Fixtures::AST_CACHE } + let(:object) { described_class.new(cache, scope, method) } + let(:method) { scope.instance_method(method_name) } + let(:yields) { [] } + let(:namespace) { self.class } + let(:scope) { self.class::Foo } + let(:type) { :def } + let(:method_name) { :bar } + let(:method_arity) { 0 } def name node.children[0] diff --git a/spec/unit/mutant/matcher/method/singleton/each_spec.rb b/spec/unit/mutant/matcher/method/singleton/each_spec.rb index 1c178862..8bfb422e 100644 --- a/spec/unit/mutant/matcher/method/singleton/each_spec.rb +++ b/spec/unit/mutant/matcher/method/singleton/each_spec.rb @@ -1,22 +1,16 @@ require 'spec_helper' describe Mutant::Matcher::Method::Singleton, '#each' do - let(:object) { described_class.new(cache, scope, method) } - let(:method) { scope.method(method_name) } - let(:cache) { Fixtures::AST_CACHE } - - let(:yields) { [] } - - let(:namespace) do - klass = self.class - end - - let(:scope) { self.class::Foo } - subject { object.each { |subject| yields << subject } } - let(:type) { :defs } - let(:method_arity) { 0 } + let(:object) { described_class.new(cache, scope, method) } + let(:method) { scope.method(method_name) } + let(:cache) { Fixtures::AST_CACHE } + let(:yields) { [] } + let(:namespace) { self.class } + let(:scope) { self.class::Foo } + let(:type) { :defs } + let(:method_arity) { 0 } def name node.children[1] diff --git a/spec/unit/mutant/mutator/emit_new_spec.rb b/spec/unit/mutant/mutator/emit_new_spec.rb index 09e23b34..2cf652d4 100644 --- a/spec/unit/mutant/mutator/emit_new_spec.rb +++ b/spec/unit/mutant/mutator/emit_new_spec.rb @@ -4,7 +4,7 @@ describe Mutant::Mutator, '#emit_new' do subject { object.send(:emit_new) { generated } } class Block - def arguments; @arguments; end + attr_reader :arguments def called? defined?(@arguments) @@ -23,7 +23,7 @@ describe Mutant::Mutator, '#emit_new' do let(:class_under_test) do Class.new(described_class) do def dispatch - #noop + # noop end end end diff --git a/spec/unit/mutant/mutator/emit_spec.rb b/spec/unit/mutant/mutator/emit_spec.rb index 5d0b7713..30e3e231 100644 --- a/spec/unit/mutant/mutator/emit_spec.rb +++ b/spec/unit/mutant/mutator/emit_spec.rb @@ -4,7 +4,7 @@ describe Mutant::Mutator, '#emit' do subject { object.send(:emit, generated) } class Block - def arguments; @arguments; end + attr_reader :arguments def called? defined?(@arguments) @@ -23,7 +23,7 @@ describe Mutant::Mutator, '#emit' do let(:class_under_test) do Class.new(described_class) do def dispatch - #noop + # noop end end end diff --git a/spec/unit/mutant/mutator/node/literal/nil_spec.rb b/spec/unit/mutant/mutator/node/literal/nil_spec.rb index bf568f93..759ae273 100644 --- a/spec/unit/mutant/mutator/node/literal/nil_spec.rb +++ b/spec/unit/mutant/mutator/node/literal/nil_spec.rb @@ -1,11 +1,8 @@ require 'spec_helper' describe Mutant::Mutator::Node::Literal, 'nil' do - let(:source) { 'nil' } - - let(:mutations) do - [ '::Object.new' ] - end + let(:source) { 'nil' } + let(:mutations) { ['::Object.new'] } it_should_behave_like 'a mutator' end diff --git a/spec/unit/mutant/mutator/node/literal/range_spec.rb b/spec/unit/mutant/mutator/node/literal/range_spec.rb index 5fc40037..2b5b167c 100644 --- a/spec/unit/mutant/mutator/node/literal/range_spec.rb +++ b/spec/unit/mutant/mutator/node/literal/range_spec.rb @@ -9,7 +9,7 @@ describe Mutant::Mutator::Node::Literal, 'range' do mutations << 'nil' mutations << '1...100' mutations << '(0.0 / 0.0)..100' - #mutations << [:dot2, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] + # mutations << [:dot2, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] mutations << '1..(1.0 / 0.0)' mutations << '1..(0.0 / 0.0)' end @@ -25,7 +25,7 @@ describe Mutant::Mutator::Node::Literal, 'range' do mutations << 'nil' mutations << '1..100' mutations << '(0.0 / 0.0)...100' - #mutations << [:dot3, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] + # mutations << [:dot3, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] mutations << '1...(1.0 / 0.0)' mutations << '1...(0.0 / 0.0)' end diff --git a/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb b/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb index f4dd06d5..1fb730de 100644 --- a/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb @@ -6,11 +6,8 @@ describe Mutant::Mutator, 'masgn' do Mutant::Random.stub(:hex_string => 'random') end - let(:source) { 'a, b = c, d' } - - let(:mutations) do - mutants = [] - end + let(:source) { 'a, b = c, d' } + let(:mutations) { [] } it_should_behave_like 'a mutator' end diff --git a/spec/unit/mutant/mutator/node/while/mutation_spec.rb b/spec/unit/mutant/mutator/node/while/mutation_spec.rb index e4d9ddd7..9441e8c1 100644 --- a/spec/unit/mutant/mutator/node/while/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/while/mutation_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Mutant::Mutator::Node::While do context 'with more than one statement' do - let(:source) { "while true; foo; bar; end" } + let(:source) { 'while true; foo; bar; end' } let(:mutations) do mutations = [] diff --git a/spec/unit/mutant/runner/config/subjects_spec.rb b/spec/unit/mutant/runner/config/subjects_spec.rb index b5cf814f..6cce1580 100644 --- a/spec/unit/mutant/runner/config/subjects_spec.rb +++ b/spec/unit/mutant/runner/config/subjects_spec.rb @@ -33,16 +33,18 @@ describe Mutant::Runner::Config, '#subjects' do context 'without earily stop' do let(:stop_a) { false } let(:stop_b) { false } + it { should eql([runner_a, runner_b]) } + it_should_behave_like 'an idempotent method' end - context 'with earily stop' do let(:stop_a) { true } let(:stop_b) { false } + it { should eql([runner_a]) } + it_should_behave_like 'an idempotent method' end - end diff --git a/spec/unit/mutant/runner/config/success_predicate_spec.rb b/spec/unit/mutant/runner/config/success_predicate_spec.rb index 99f626b1..43a655a5 100644 --- a/spec/unit/mutant/runner/config/success_predicate_spec.rb +++ b/spec/unit/mutant/runner/config/success_predicate_spec.rb @@ -34,6 +34,7 @@ describe Mutant::Runner::Config, '#success?' do let(:stop_b) { false } let(:success_a) { true } let(:success_b) { true } + it { should be(true) } end diff --git a/spec/unit/mutant/runner/mutation/killer_spec.rb b/spec/unit/mutant/runner/mutation/killer_spec.rb index 48e29daa..2396d691 100644 --- a/spec/unit/mutant/runner/mutation/killer_spec.rb +++ b/spec/unit/mutant/runner/mutation/killer_spec.rb @@ -27,7 +27,7 @@ describe Mutant::Runner::Mutation, '#killer' do end it 'should call configuration to identify strategy' do - config.should_receive(:strategy).with().and_return(strategy) + config.should_receive(:strategy).with(no_args).and_return(strategy) should be(killer) end diff --git a/spec/unit/mutant/runner/subject/success_predicate_spec.rb b/spec/unit/mutant/runner/subject/success_predicate_spec.rb index 8f4316a6..cdf413a7 100644 --- a/spec/unit/mutant/runner/subject/success_predicate_spec.rb +++ b/spec/unit/mutant/runner/subject/success_predicate_spec.rb @@ -5,13 +5,13 @@ describe Mutant::Runner::Subject, '#success?' do let(:object) { described_class.new(config, mutation_subject) } - let(:mutation_subject) { + let(:mutation_subject) do double( 'Subject', :class => Mutant::Subject, :mutations => [mutation_a, mutation_b] ) - } + end let(:reporter) { double('Reporter') } let(:config) { double('Config', :reporter => reporter) } From 7a84ffd187da67cdf2f94311c0e709281fda5072 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 12:20:01 -0700 Subject: [PATCH 07/43] Update metrics thresholds --- config/flay.yml | 2 +- config/flog.yml | 2 +- config/reek.yml | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config/flay.yml b/config/flay.yml index f752d954..2c66ea31 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 737 +total_score: 753 diff --git a/config/flog.yml b/config/flog.yml index 3f7325dc..50ba1616 100644 --- a/config/flog.yml +++ b/config/flog.yml @@ -1,2 +1,2 @@ --- -threshold: 19.8 +threshold: 21.2 diff --git a/config/reek.yml b/config/reek.yml index 59157553..2b0820d7 100644 --- a/config/reek.yml +++ b/config/reek.yml @@ -24,9 +24,9 @@ DuplicateMethodCall: FeatureEnvy: enabled: true exclude: - - Mutant::Matcher::Method::Singleton#receiver? - - Mutant::Matcher::Method::Instance#match? - Mutant::CLI#parse + - Mutant::Matcher::Method::Instance#match? + - Mutant::Matcher::Method::Singleton#receiver? - Mutant::Mutation::Evil#success? - Mutant::Mutation::Neutral#success? - Mutant::Reporter::CLI#subject_results @@ -46,9 +46,9 @@ NestedIterators: enabled: true exclude: - Mutant#self.singleton_subclass_instance + - Mutant::CLI#parse - Mutant::Mutator::Util::Array::Element#dispatch - Mutant::Reporter::CLI::Printer::Config::Runner#generic_stats - - Mutant::CLI#parse max_allowed_nesting: 1 ignore_iterators: [] NilCheck: @@ -76,12 +76,13 @@ TooManyMethods: TooManyStatements: enabled: true exclude: + - Mutant#self.singleton_subclass_instance - Mutant::CLI#parse + - Mutant::Killer::Rspec#run - Mutant::Reporter::CLI#colorized_diff - Mutant::Reporter::CLI::Printer::Config::Runner#run - - Mutant#self.singleton_subclass_instance - - Mutant::Zombifier::File#self.find_uncached - Mutant::Runner#dispatch + - Mutant::Zombifier::File#self.find_uncached max_statements: 6 UncommunicativeMethodName: enabled: true @@ -123,8 +124,8 @@ UnusedParameters: UtilityFunction: enabled: true exclude: - - Mutant::NodeHelpers#s - Mutant::CLI#reporter - Mutant::Mutation::Evil#success? - Mutant::Mutation::Neutral#success? + - Mutant::NodeHelpers#s max_helper_calls: 0 From bec85b6431f7acfaea8c82f7d2827789a1e39ff7 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 13:19:42 -0700 Subject: [PATCH 08/43] Remove unnecessary code and whitespace from specs --- spec/unit/mutant/mutator/node/cbase/mutation_spec.rb | 5 ----- spec/unit/mutant/mutator/node/const/mutation_spec.rb | 5 ----- spec/unit/mutant/mutator/node/define/mutation_spec.rb | 1 - spec/unit/mutant/mutator/node/if/mutation_spec.rb | 1 - spec/unit/mutant/mutator/node/masgn/mutation_spec.rb | 5 ----- .../mutant/mutator/node/named_value/access/mutation_spec.rb | 1 - .../node/named_value/constant_assignment/mutation_spec.rb | 1 - .../node/named_value/variable_assignment/mutation_spec.rb | 1 - 8 files changed, 20 deletions(-) diff --git a/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb b/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb index 1ef7bef0..1bce9d32 100644 --- a/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb @@ -1,11 +1,6 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::Access, 'cbase' do - - before do - Mutant::Random.stub(:hex_string => :random) - end - let(:source) { '::A' } let(:mutations) do diff --git a/spec/unit/mutant/mutator/node/const/mutation_spec.rb b/spec/unit/mutant/mutator/node/const/mutation_spec.rb index 605939e4..b8cc470b 100644 --- a/spec/unit/mutant/mutator/node/const/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/const/mutation_spec.rb @@ -1,11 +1,6 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::Access, 'const' do - - before do - Mutant::Random.stub(:hex_string => :random) - end - let(:source) { 'A::B' } let(:mutations) do diff --git a/spec/unit/mutant/mutator/node/define/mutation_spec.rb b/spec/unit/mutant/mutator/node/define/mutation_spec.rb index 254ebcb8..50fc8924 100644 --- a/spec/unit/mutant/mutator/node/define/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/define/mutation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Mutant::Mutator, 'def' do - context 'empty' do let(:source) { 'def foo; end' } diff --git a/spec/unit/mutant/mutator/node/if/mutation_spec.rb b/spec/unit/mutant/mutator/node/if/mutation_spec.rb index 849a2072..bf05ae88 100644 --- a/spec/unit/mutant/mutator/node/if/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/if/mutation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Mutant::Mutator, 'if' do - before do Mutant::Random.stub(:hex_string => 'random') end diff --git a/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb b/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb index 1fb730de..f9be3d7a 100644 --- a/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/masgn/mutation_spec.rb @@ -1,11 +1,6 @@ require 'spec_helper' describe Mutant::Mutator, 'masgn' do - - before do - Mutant::Random.stub(:hex_string => 'random') - end - let(:source) { 'a, b = c, d' } let(:mutations) { [] } diff --git a/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb index 680f6b80..5c68e815 100644 --- a/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do - before do Mutant::Random.stub(:hex_string => :random) end diff --git a/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb index ea693398..e55b0700 100644 --- a/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do - before do Mutant::Random.stub(:hex_string => :random) end diff --git a/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb index 59449390..4fff2fee 100644 --- a/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do - before do Mutant::Random.stub(:hex_string => :random) end From 25bc3b9bc038db4e961388782ae3204f303f653b Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 13:20:09 -0700 Subject: [PATCH 09/43] Add block_pass mutator --- lib/mutant.rb | 1 + lib/mutant/mutator/node/block_pass.rb | 25 +++++++++++++++++++ lib/mutant/mutator/node/generic.rb | 2 +- .../mutator/node/block_pass/mutation_spec.rb | 12 +++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/mutant/mutator/node/block_pass.rb create mode 100644 spec/unit/mutant/mutator/node/block_pass/mutation_spec.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 92426015..7363e410 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -57,6 +57,7 @@ require 'mutant/mutator/node/literal/nil' require 'mutant/mutator/node/argument' require 'mutant/mutator/node/arguments' require 'mutant/mutator/node/begin' +require 'mutant/mutator/node/block_pass' require 'mutant/mutator/node/cbase' require 'mutant/mutator/node/connective/binary' require 'mutant/mutator/node/const' diff --git a/lib/mutant/mutator/node/block_pass.rb b/lib/mutant/mutator/node/block_pass.rb new file mode 100644 index 00000000..65615c7f --- /dev/null +++ b/lib/mutant/mutator/node/block_pass.rb @@ -0,0 +1,25 @@ +module Mutant + class Mutator + class Node + + # Mutation emitter to handle block_pass nodes + class BlockPass < self + + handle(:block_pass) + + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + # noop, for now + end + + end # BlockPass + end # Node + end # Mutator +end # Mutant diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 149b9782..a648e848 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -11,7 +11,7 @@ module Mutant :defined, :next, :break, :match, :ensure, :dstr, :dsym, :yield, :rescue, :redo, :defined?, - :blockarg, :block_pass, :op_asgn, :and_asgn, + :blockarg, :op_asgn, :and_asgn, :regopt, :restarg, :resbody, :retry, :arg_expr, :kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty, :alias, :for, :xstr, :back_ref, :nth_ref, :class, diff --git a/spec/unit/mutant/mutator/node/block_pass/mutation_spec.rb b/spec/unit/mutant/mutator/node/block_pass/mutation_spec.rb new file mode 100644 index 00000000..628a824c --- /dev/null +++ b/spec/unit/mutant/mutator/node/block_pass/mutation_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Mutant::Mutator::Node::NamedValue::Access, 'block_pass' do + let(:source) { 'foo(&bar)' } + + let(:mutations) do + mutants = [] + mutants << 'foo' + end + + it_should_behave_like 'a mutator' +end From dc417d1cc84643950af8c084ed9de29950d9f98c Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 13:25:43 -0700 Subject: [PATCH 10/43] Move block_pass and cbase mutators into a noop class --- lib/mutant.rb | 3 +-- lib/mutant/mutator/node/block_pass.rb | 25 ------------------- lib/mutant/mutator/node/{cbase.rb => noop.rb} | 10 ++++---- 3 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 lib/mutant/mutator/node/block_pass.rb rename lib/mutant/mutator/node/{cbase.rb => noop.rb} (64%) diff --git a/lib/mutant.rb b/lib/mutant.rb index 7363e410..078394dc 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -57,13 +57,12 @@ require 'mutant/mutator/node/literal/nil' require 'mutant/mutator/node/argument' require 'mutant/mutator/node/arguments' require 'mutant/mutator/node/begin' -require 'mutant/mutator/node/block_pass' -require 'mutant/mutator/node/cbase' require 'mutant/mutator/node/connective/binary' require 'mutant/mutator/node/const' require 'mutant/mutator/node/named_value/access' require 'mutant/mutator/node/named_value/constant_assignment' require 'mutant/mutator/node/named_value/variable_assignment' +require 'mutant/mutator/node/noop' require 'mutant/mutator/node/while' require 'mutant/mutator/node/super' require 'mutant/mutator/node/zsuper' diff --git a/lib/mutant/mutator/node/block_pass.rb b/lib/mutant/mutator/node/block_pass.rb deleted file mode 100644 index 65615c7f..00000000 --- a/lib/mutant/mutator/node/block_pass.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Mutant - class Mutator - class Node - - # Mutation emitter to handle block_pass nodes - class BlockPass < self - - handle(:block_pass) - - private - - # Emit mutations - # - # @return [undefined] - # - # @api private - # - def dispatch - # noop, for now - end - - end # BlockPass - end # Node - end # Mutator -end # Mutant diff --git a/lib/mutant/mutator/node/cbase.rb b/lib/mutant/mutator/node/noop.rb similarity index 64% rename from lib/mutant/mutator/node/cbase.rb rename to lib/mutant/mutator/node/noop.rb index fb6a1989..5f6178f7 100644 --- a/lib/mutant/mutator/node/cbase.rb +++ b/lib/mutant/mutator/node/noop.rb @@ -2,10 +2,10 @@ module Mutant class Mutator class Node - # Mutation emitter to handle cbase nodes - class Cbase < self + # Mutation emitter to handle noop nodes + class Noop < self - handle(:cbase) + handle(:block_pass, :cbase) private @@ -16,10 +16,10 @@ module Mutant # @api private # def dispatch - # noop, for now + # noop end - end # Cbase + end # Noop end # Node end # Mutator end # Mutant From d6af179adca3c4aab1e85675d8a4d6c7b6df9f7c Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:23:04 -0700 Subject: [PATCH 11/43] Fix specs to use a string for the random hex string --- spec/unit/mutant/mutator/node/block/mutation_spec.rb | 4 ++-- .../mutant/mutator/node/named_value/access/mutation_spec.rb | 2 +- .../node/named_value/constant_assignment/mutation_spec.rb | 2 +- .../node/named_value/variable_assignment/mutation_spec.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/unit/mutant/mutator/node/block/mutation_spec.rb b/spec/unit/mutant/mutator/node/block/mutation_spec.rb index fb7e815b..e27088b0 100644 --- a/spec/unit/mutant/mutator/node/block/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/block/mutation_spec.rb @@ -21,7 +21,7 @@ describe Mutant::Mutator, 'block' do let(:source) { 'foo { |a, b| }' } before do - Mutant::Random.stub(:hex_string => :random) + Mutant::Random.stub(:hex_string => 'random') end let(:mutations) do @@ -41,7 +41,7 @@ describe Mutant::Mutator, 'block' do context 'with block pattern args' do before do - Mutant::Random.stub(:hex_string => :random) + Mutant::Random.stub(:hex_string => 'random') end let(:source) { 'foo { |(a, b), c| }' } diff --git a/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb index 5c68e815..75d02795 100644 --- a/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do before do - Mutant::Random.stub(:hex_string => :random) + Mutant::Random.stub(:hex_string => 'random') end context 'global variable' do diff --git a/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb index e55b0700..66454a71 100644 --- a/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do before do - Mutant::Random.stub(:hex_string => :random) + Mutant::Random.stub(:hex_string => 'random') end let(:source) { 'A = true' } diff --git a/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb index 4fff2fee..219d2924 100644 --- a/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do before do - Mutant::Random.stub(:hex_string => :random) + Mutant::Random.stub(:hex_string => 'random') end context 'global variable' do From dc0f0d2ff134f925dd2b5e3186b62a9007dab66e Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:23:21 -0700 Subject: [PATCH 12/43] Fix described classes in specs --- spec/unit/mutant/mutator/node/cbase/mutation_spec.rb | 2 +- spec/unit/mutant/mutator/node/const/mutation_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb b/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb index 1bce9d32..b0239fb0 100644 --- a/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/cbase/mutation_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Mutant::Mutator::Node::NamedValue::Access, 'cbase' do +describe Mutant::Mutator::Node::Noop, 'cbase' do let(:source) { '::A' } let(:mutations) do diff --git a/spec/unit/mutant/mutator/node/const/mutation_spec.rb b/spec/unit/mutant/mutator/node/const/mutation_spec.rb index b8cc470b..250f439e 100644 --- a/spec/unit/mutant/mutator/node/const/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/const/mutation_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Mutant::Mutator::Node::NamedValue::Access, 'const' do +describe Mutant::Mutator::Node::Const, 'const' do let(:source) { 'A::B' } let(:mutations) do From 19b02494ec4682963e3199f8f26c1ceb0662686e Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:25:03 -0700 Subject: [PATCH 13/43] Add restarg to the list of non-standalone nodes --- lib/mutant/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/constants.rb b/lib/mutant/constants.rb index 12132552..a4fec844 100644 --- a/lib/mutant/constants.rb +++ b/lib/mutant/constants.rb @@ -17,7 +17,7 @@ module Mutant ].to_set.freeze # Set of node types that are not valid when emitted standalone - NOT_STANDALONE = [:splat, :block_pass].to_set.freeze + NOT_STANDALONE = [:splat, :restarg, :block_pass].to_set.freeze OPERATOR_EXPANSIONS = { :<=> => :spaceship_operator, From 0f4a653749c909fbdf0904ab5d6e2ab8396b9da1 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:47:22 -0700 Subject: [PATCH 14/43] Remove match node which is no longer provided by parser --- lib/mutant/mutator/node/generic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index a648e848..6645b742 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -9,7 +9,7 @@ module Mutant # your contribution is that close! handle( :defined, - :next, :break, :match, :ensure, + :next, :break, :ensure, :dstr, :dsym, :yield, :rescue, :redo, :defined?, :blockarg, :op_asgn, :and_asgn, :regopt, :restarg, :resbody, :retry, :arg_expr, From 3a6f928089f56b236a2d714ef270e5af7597b4f6 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:56:50 -0700 Subject: [PATCH 15/43] Remove defined node which is no longer provided by parser * The new node is named defined? which is already in the generic node list. --- lib/mutant/mutator/node/generic.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 6645b742..fa6feccd 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -8,7 +8,6 @@ module Mutant # These nodes still need a dedicated mutator, # your contribution is that close! handle( - :defined, :next, :break, :ensure, :dstr, :dsym, :yield, :rescue, :redo, :defined?, :blockarg, :op_asgn, :and_asgn, From 147cbbc87d47178c85bb1ac5e5257b05455dc6b1 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 14:58:23 -0700 Subject: [PATCH 16/43] Update flay threshold --- config/flay.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/flay.yml b/config/flay.yml index 2c66ea31..d15b0894 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 753 +total_score: 751 From cfedd1f307d77c2243be3500e22fa33c251ab697 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:13:44 -0700 Subject: [PATCH 17/43] Fix spec to use proper constant --- spec/integration/mutant/test_mutator_handles_types_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/mutant/test_mutator_handles_types_spec.rb b/spec/integration/mutant/test_mutator_handles_types_spec.rb index e04c7958..c82a0815 100644 --- a/spec/integration/mutant/test_mutator_handles_types_spec.rb +++ b/spec/integration/mutant/test_mutator_handles_types_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Mutant do specify 'mutant should not crash for any node parser can generate' do Mutant::NODE_TYPES.each do |type| - Mutant::Mutator::Node::Registry.lookup(Mutant::NodeHelpers.s(type)) + Mutant::Mutator::Registry.lookup(Mutant::NodeHelpers.s(type)) end end end From 7985d19345e54bb17fc95f1ee1d7ca81ffda6652 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:14:03 -0700 Subject: [PATCH 18/43] Add missing while node to list of possible nodes --- lib/mutant/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/constants.rb b/lib/mutant/constants.rb index a4fec844..d9ba9415 100644 --- a/lib/mutant/constants.rb +++ b/lib/mutant/constants.rb @@ -77,7 +77,7 @@ module Mutant :xstr, :def, :defs, :case, :when, :ivar, :lvar, :cvar, :gvar, :back_ref, :const, :nth_ref, :class, :sclass, :yield, :match_with_lvasgn, :match_current_line, :irange, :erange, - :or_asgn, :kwbegin, :and_asgn + :or_asgn, :kwbegin, :and_asgn, :while ].to_set.freeze end # Mutant From 7ff35cc7b20f712057a8fd84abbe28229542b468 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:14:39 -0700 Subject: [PATCH 19/43] Fix the mutator registry to be more strict about nodes --- lib/mutant/mutator/registry.rb | 58 +++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/lib/mutant/mutator/registry.rb b/lib/mutant/mutator/registry.rb index 157a576b..afd5c0d0 100644 --- a/lib/mutant/mutator/registry.rb +++ b/lib/mutant/mutator/registry.rb @@ -2,16 +2,12 @@ module Mutant class Mutator # Registry for mutators module Registry - # Return registry state - # - # @return [Hash] - # - # @api private - # - def self.registry - @registry ||= {} - end - private_class_method :registry + + # Raised when the type is an invalid type + InvalidTypeError = Class.new(TypeError) + + # Raised when the type is a duplicate + DuplicateTypeError = Class.new(ArgumentError) # Register mutator class for AST node class # @@ -23,7 +19,8 @@ module Mutant # @return [self] # def self.register(type, mutator_class) - raise "duplicate type registration: #{type}" if registry.key?(type) + assert_valid_type(type) + assert_unique_type(type) registry[type] = mutator_class self end @@ -46,6 +43,45 @@ module Mutant end end + # Return registry state + # + # @return [Hash] + # + # @api private + # + def self.registry + @registry ||= {} + end + private_class_method :registry + + # Assert the node type is valid + # + # @raise [InvalidTypeError] + # raised when the node type is invalid + # + # @api private + # + def self.assert_valid_type(type) + unless NODE_TYPES.include?(type) || type.kind_of?(Class) + raise InvalidTypeError, "invalid type registration: #{type}" + end + end + private_class_method :assert_valid_type + + # Assert the node type is unique and not already registered + # + # @raise [DuplcateTypeError] + # raised when the node type is a duplicate + # + # @api private + # + def self.assert_unique_type(type) + if registry.key?(type) + raise DuplicateTypeError, "duplicate type registration: #{type}" + end + end + private_class_method :assert_unique_type + end # Registry end # Mutator end # Mutant From f78418bdb5fe277338aa9493f1694dacd6215422 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:19:01 -0700 Subject: [PATCH 20/43] Fix YARD docs --- lib/mutant/mutation/evil.rb | 4 ++-- lib/mutant/mutation/neutral.rb | 8 ++++---- lib/mutant/mutator/registry.rb | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/mutant/mutation/evil.rb b/lib/mutant/mutation/evil.rb index 2ca1ce2c..2a93c1e4 100644 --- a/lib/mutant/mutation/evil.rb +++ b/lib/mutant/mutation/evil.rb @@ -30,9 +30,9 @@ module Mutant killer.killed? end - # Indicate if a killer should treat a kill as problematic. + # Indicate if a killer should treat a kill as problematic # - # @return [false] Killing evil mutants is not problematic. + # @return [false] Killing evil mutants is not problematic # # @api private # diff --git a/lib/mutant/mutation/neutral.rb b/lib/mutant/mutation/neutral.rb index c4f77e67..0104cdc6 100644 --- a/lib/mutant/mutation/neutral.rb +++ b/lib/mutant/mutation/neutral.rb @@ -10,12 +10,12 @@ module Mutant SYMBOL = 'noop' - # Indicate if a killer should treat a kill as problematic. + # Indicate if a killer should treat a kill as problematic # # @return [false] Killing noop mutants is a serious problem. Failures # in noop may indicate a broken test suite, but they can also be an # indication mutant has altered the runtime environment in a subtle - # way and tickled an odd bug. + # way and tickled an odd bug # # @api private # @@ -52,9 +52,9 @@ module Mutant !killer.killed? end - # Indicate if a killer should treat a kill as problematic. + # Indicate if a killer should treat a kill as problematic # - # @return [true] Neutral mutants must die. + # @return [true] Neutral mutants must die # # @api private # diff --git a/lib/mutant/mutator/registry.rb b/lib/mutant/mutator/registry.rb index afd5c0d0..163468ae 100644 --- a/lib/mutant/mutator/registry.rb +++ b/lib/mutant/mutator/registry.rb @@ -56,6 +56,8 @@ module Mutant # Assert the node type is valid # + # @return [undefined] + # # @raise [InvalidTypeError] # raised when the node type is invalid # @@ -70,6 +72,8 @@ module Mutant # Assert the node type is unique and not already registered # + # @return [undefined] + # # @raise [DuplcateTypeError] # raised when the node type is a duplicate # From 7c06d163cff51b52933a819dda213a96f0a99aff Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:19:11 -0700 Subject: [PATCH 21/43] Add gitignore from ROM style gems --- .gitignore | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8c8ba099..cb4132ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,38 @@ -/.rbx -/Gemfile.lock -/tmp -/coverage -/test_app/.rbx -/.bundle +## MAC OS +.DS_Store + +## TEXTMATE +*.tmproj +tmtags + +## EMACS +*~ +\#* +.\#* + +## VIM +*.sw[op] + +## Rubinius +*.rbc +.rbx + +## PROJECT::GENERAL +*.gem +coverage +profiling +turbulence +rdoc +pkg +tmp +doc +log +.yardoc +measurements + +## BUNDLER +.bundle +Gemfile.lock + +## PROJECT::SPECIFIC /vendor From c7f7470a4e2c972a7427f35616540419935e8a90 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:20:27 -0700 Subject: [PATCH 22/43] Update metrics threshold --- config/flay.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/flay.yml b/config/flay.yml index d15b0894..da73e5ca 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 751 +total_score: 757 From 9234b01f84a1ffc66d8f3c59476fc66ef33936aa Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 18:57:52 +0200 Subject: [PATCH 23/43] Fix sytle issues in Mutant::Differ --- lib/mutant/differ.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mutant/differ.rb b/lib/mutant/differ.rb index 718cd73d..5df95f9a 100644 --- a/lib/mutant/differ.rb +++ b/lib/mutant/differ.rb @@ -19,10 +19,16 @@ module Mutant when 0 nil when 1 - output = Diff::LCS::Hunk.new(old, new, diffs.first, max_length, 0).diff(:unified) + output = + Diff::LCS::Hunk.new( + old, new, diffs.first, max_length, 0 + ).diff(:unified) output << "\n" else - $stderr.puts 'Mutation resulted in more than one diff, should not happen! PLS report a bug!' + $stderr.puts( + 'Mutation resulted in more than one diff, should not happen! ' + + 'PLS report a bug!' + ) nil end end From 07ddb9b70ebe926f2435c3da9e90f551f4f1be4e Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 18:58:14 +0200 Subject: [PATCH 24/43] Fix style issue in Printer::Config --- lib/mutant/reporter/cli/printer/config.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mutant/reporter/cli/printer/config.rb b/lib/mutant/reporter/cli/printer/config.rb index 0551580e..48fac422 100644 --- a/lib/mutant/reporter/cli/printer/config.rb +++ b/lib/mutant/reporter/cli/printer/config.rb @@ -130,8 +130,9 @@ module Mutant def generic_stats object.subjects.each_with_object(Hash.new(0)) do |runner, stats| Walker.run(runner.subject.node) do |node| - next unless Mutator::Registry.lookup(node) == Mutator::Node::Generic - stats[node.type] += 1 + if Mutator::Registry.lookup(node) == Mutator::Node::Generic + stats[node.type] += 1 + end end end end From a9ae9932eca2d4b924a765f23893f04430850791 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:00:13 +0200 Subject: [PATCH 25/43] Fix style issue in Mutant::CLI* --- lib/mutant/cli/classifier.rb | 15 ++++++++++----- lib/mutant/cli/classifier/method.rb | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/mutant/cli/classifier.rb b/lib/mutant/cli/classifier.rb index f7749758..8bbaf6e9 100644 --- a/lib/mutant/cli/classifier.rb +++ b/lib/mutant/cli/classifier.rb @@ -8,8 +8,10 @@ module Mutant SCOPE_NAME_PATTERN = /[A-Za-z][A-Za-z_0-9]*/.freeze OPERATOR_PATTERN = Regexp.union(*OPERATOR_METHODS.map(&:to_s)).freeze - METHOD_NAME_PATTERN = /([_A-Za-z][A-Za-z0-9_]*[!?=]?|#{OPERATOR_PATTERN})/.freeze - SCOPE_PATTERN = /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze + METHOD_NAME_PATTERN = + /([_A-Za-z][A-Za-z0-9_]*[!?=]?|#{OPERATOR_PATTERN})/.freeze + SCOPE_PATTERN = + /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze CBASE_PATTERN = /\A::/.freeze SCOPE_OPERATOR = '::'.freeze SINGLETON_PATTERN = /\A(#{SCOPE_PATTERN})\z/.freeze @@ -36,9 +38,12 @@ module Mutant # @api private # def self.constant_lookup(location) - location.gsub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR).reduce(Object) do |parent, name| - parent.const_get(name) - end + location + .gsub(CBASE_PATTERN, EMPTY_STRING) + .split(SCOPE_OPERATOR) + .reduce(Object) do |parent, name| + parent.const_get(name) + end end # Return matchers for input diff --git a/lib/mutant/cli/classifier/method.rb b/lib/mutant/cli/classifier/method.rb index ff1df8bd..c4353a0e 100644 --- a/lib/mutant/cli/classifier/method.rb +++ b/lib/mutant/cli/classifier/method.rb @@ -10,7 +10,8 @@ module Mutant '#' => Matcher::Methods::Instance }.freeze - REGEXP = /\A(#{SCOPE_PATTERN})([.#])(#{METHOD_NAME_PATTERN}\z)/.freeze + REGEXP = + %r(\A(#{SCOPE_PATTERN})([.#])(#{METHOD_NAME_PATTERN}\z)).freeze # Positions of captured regexp groups SCOPE_NAME_POSITION = 1 From c64bb2a6d3dbad02d5548abe9139fed5dadb8fd4 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:02:01 +0200 Subject: [PATCH 26/43] Fix style issues in Mutant::Reporter* --- lib/mutant/reporter/cli/printer/mutation.rb | 18 +++++++++++------- lib/mutant/reporter/cli/printer/subject.rb | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/mutant/reporter/cli/printer/mutation.rb b/lib/mutant/reporter/cli/printer/mutation.rb index dba73fa4..90d2f60d 100644 --- a/lib/mutant/reporter/cli/printer/mutation.rb +++ b/lib/mutant/reporter/cli/printer/mutation.rb @@ -54,12 +54,12 @@ module Mutant # Reporter for noop mutations class Noop < self - MESSAGE = [ - 'Parsed subject AST:', - '%s', - 'Unparsed source:', - '%s', - ].join("\n") + MESSAGE = [ + 'Parsed subject AST:', + '%s', + 'Unparsed source:', + '%s', + ].join("\n") private @@ -70,7 +70,11 @@ module Mutant # @api private # def details - sprintf(MESSAGE, mutation.subject.node.inspect, mutation.original_source) + sprintf( + MESSAGE, + mutation.subject.node.inspect, + mutation.original_source + ) end end # Noop diff --git a/lib/mutant/reporter/cli/printer/subject.rb b/lib/mutant/reporter/cli/printer/subject.rb index c6c7d960..e2360fe1 100644 --- a/lib/mutant/reporter/cli/printer/subject.rb +++ b/lib/mutant/reporter/cli/printer/subject.rb @@ -59,6 +59,8 @@ module Mutant object.subject end + FORMAT = '(%02d/%02d) %3d%% - %0.02fs'.freeze + # Print stats # # @return [undefned @@ -66,7 +68,7 @@ module Mutant # @api private # def print_stats - status('(%02d/%02d) %3d%% - %0.02fs', amount_kills, amount_mutations, coverage, time) + status(FORMAT, amount_kills, amount_mutations, coverage, time) end # Print progress bar finish From 1505a109809c95aaa2362874663e0198a7bce08c Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:04:42 +0200 Subject: [PATCH 27/43] Fix style issues in Mutant::Mutantion* --- lib/mutant/mutation.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index e505f25d..bda5cf08 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -1,7 +1,8 @@ module Mutant # Represent a mutated node with its subject class Mutation - include AbstractType, Adamantium::Flat, Concord::Public.new(:subject, :node) + include AbstractType, Adamantium::Flat + include Concord::Public.new(:subject, :node) # Return mutated root node # From 2710a31d7070cb2d6c9449a0db1c518ad9e0cfed Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:05:17 +0200 Subject: [PATCH 28/43] Fix style issues in Mutant::Subject --- lib/mutant/subject.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mutant/subject.rb b/lib/mutant/subject.rb index 00763518..c8562cc2 100644 --- a/lib/mutant/subject.rb +++ b/lib/mutant/subject.rb @@ -1,7 +1,8 @@ module Mutant # Subject of a mutation class Subject - include AbstractType, Adamantium::Flat, Enumerable, Concord::Public.new(:context, :node) + include AbstractType, Adamantium::Flat, Enumerable + include Concord::Public.new(:context, :node) # Return mutations # From ddd669c2c218ad999a68570ba211780c35f89611 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:07:38 +0200 Subject: [PATCH 29/43] Fix style issues in Mutant::Mutator --- lib/mutant/mutator.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/mutant/mutator.rb b/lib/mutant/mutator.rb index ba96d316..f608320b 100644 --- a/lib/mutant/mutator.rb +++ b/lib/mutant/mutator.rb @@ -135,17 +135,13 @@ module Mutant # Call block until it generates a mutation # - # The primary use of this method is to give the random generated object - # a nice interface for retring generation when generation accidentally generated the - # input - # # @yield # Execute block until object is generated where new?(object) returns true # # @return [self] # # @raise [RuntimeError] - # raises RuntimeError in case no new ast node can be generated after MAX_TRIES. + # raises RuntimeError when no new node can be generated after MAX_TRIES. # # @api private # From 506b9f81d6946226346c8aafe0c694c7b7d1fee4 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:24:00 +0200 Subject: [PATCH 30/43] Fix style issues in Mutant::Loader --- config/rubocop.yml | 10 ++++++++++ lib/mutant/loader.rb | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config/rubocop.yml b/config/rubocop.yml index b629f060..600bce4e 100644 --- a/config/rubocop.yml +++ b/config/rubocop.yml @@ -33,6 +33,16 @@ CollectionMethods: AccessControl: Enabled: false +MethodLength: + CountComments: false + Max: 17 # TODO: Bring down to 10 + +RegexpLiteral: # I do not agree %r(\A) is more readable than /\A/ + Enabled: false + +Eval: + Enabled: false # Mutant must use Kernel#eval to inject mutated source + # Limit line length LineLength: Max: 124 # TODO: lower to 79 diff --git a/lib/mutant/loader.rb b/lib/mutant/loader.rb index 002a5047..18b57e3d 100644 --- a/lib/mutant/loader.rb +++ b/lib/mutant/loader.rb @@ -40,7 +40,12 @@ module Mutant # @api private # def run - eval(source, TOPLEVEL_BINDING, @subject.source_path.to_s, @subject.source_line) + eval( + source, + TOPLEVEL_BINDING, + @subject.source_path.to_s, + @subject.source_line + ) end # Return source From e7debcb8014ce3316f8894be2355eccc7008d20f Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:28:08 +0200 Subject: [PATCH 31/43] Fix style issues in Killer::Rspec --- lib/mutant/killer/rspec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mutant/killer/rspec.rb b/lib/mutant/killer/rspec.rb index c05fb454..2cdb4199 100644 --- a/lib/mutant/killer/rspec.rb +++ b/lib/mutant/killer/rspec.rb @@ -18,11 +18,13 @@ module Mutant def run mutation.insert # TODO: replace with real streams from configuration - # Note: we assume the only interesting output from a failed rspec run is stderr. require 'stringio' + # Note: We assume interesting output from a failed rspec run is stderr. rspec_err = StringIO.new - killed = !::RSpec::Core::Runner.run(command_line_arguments, nil, rspec_err).zero? + exit_code = ::RSpec::Core::Runner.run(cli_arguments, nil, rspec_err) + + killed = !exit_code.zero? if killed and mutation.should_survive? rspec_err.rewind @@ -41,7 +43,7 @@ module Mutant # # @api private # - def command_line_arguments + def cli_arguments %W( --fail-fast ) + strategy.spec_files(mutation.subject) From 19610aaca6134af219bcbed49bbd5fd7a68b714a Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:55:33 +0200 Subject: [PATCH 32/43] Fix style in Mutant::Zombifier --- lib/mutant/zombifier.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mutant/zombifier.rb b/lib/mutant/zombifier.rb index ab97fbc9..29b29837 100644 --- a/lib/mutant/zombifier.rb +++ b/lib/mutant/zombifier.rb @@ -4,7 +4,7 @@ module Mutant # Excluded from zombification, reasons # - # * Relies dynamic require, zombifier does not know how to recurse here (racc) + # * Relies dynamic require, zombifier does not know how to recurse (racc) # * Unparser bug (optparse) # * Toplevel reference/cbase nodes in code (rspec) # * Creates useless toplevel modules that get vendored under ::Zombie (set) @@ -218,7 +218,9 @@ module Mutant children = node.type == :begin ? node.children : [node] children.select do |node| children = node.children - node.type == :send && children.at(RECEIVER_INDEX).nil? && children.at(SELECTOR_INDEX) == :require + node.type == :send && + children.at(RECEIVER_INDEX).nil? && + children.at(SELECTOR_INDEX) == :require end end From 745eb0c7030e3af165187967865cff55370d8365 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:56:02 +0200 Subject: [PATCH 33/43] Fix style in Mutant::Killer --- lib/mutant/killer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mutant/killer.rb b/lib/mutant/killer.rb index 282206b6..f2291e94 100644 --- a/lib/mutant/killer.rb +++ b/lib/mutant/killer.rb @@ -1,7 +1,8 @@ module Mutant # Abstract base class for mutant killers class Killer - include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?) + include Adamantium::Flat, AbstractType + include Equalizer.new(:strategy, :mutation, :killed?) # Return strategy # From 0faf7b0a84e61043da21f4e5ec5915203c0d2527 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:57:06 +0200 Subject: [PATCH 34/43] Fix style issues in Mutant::NodeHelpers --- lib/mutant/node_helpers.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/mutant/node_helpers.rb b/lib/mutant/node_helpers.rb index 63043297..4e317358 100644 --- a/lib/mutant/node_helpers.rb +++ b/lib/mutant/node_helpers.rb @@ -15,10 +15,14 @@ module Mutant end module_function :s - NAN = s(:begin, s(:send, s(:float, 0.0), :/, s(:args, s(:float, 0.0)))) - NEGATIVE_INFINITY = s(:begin, s(:send, s(:float, -1.0), :/, s(:args, s(:float, 0.0)))) - INFINITY = s(:begin, s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0)))) - NEW_OBJECT = s(:send, s(:const, s(:cbase), :Object), :new) + NAN = + s(:begin, s(:send, s(:float, 0.0), :/, s(:args, s(:float, 0.0)))) + INFINITY = + s(:begin, s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0)))) + NEW_OBJECT = + s(:send, s(:const, s(:cbase), :Object), :new) + NEGATIVE_INFINITY = + s(:begin, s(:send, s(:float, -1.0), :/, s(:args, s(:float, 0.0)))) RAISE = s(:send, nil, :raise) From 907fc47b98e818db967c066cc2cf1e4eb78836a0 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:58:53 +0200 Subject: [PATCH 35/43] Fix style issues in Mutant::CLI --- lib/mutant/cli.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index a14b21d2..bf80ee73 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -197,15 +197,15 @@ module Mutant # @api private # def parse(arguments) - opts = OptionParser.new do |opts| - opts.banner = 'usage: mutant STRATEGY [options] MATCHERS ...' - opts.separator '' - opts.separator 'Strategies:' + opts = OptionParser.new do |builder| + builder.banner = 'usage: mutant STRATEGY [options] MATCHERS ...' + builder.separator '' + builder.separator 'Strategies:' - opts.on('--zombie', 'Run mutant zombified') + builder.on('--zombie', 'Run mutant zombified') - add_strategies(opts) - add_options(opts) + add_strategies(builder) + add_options(builder) end matchers = @@ -246,7 +246,7 @@ module Mutant set_strategy Strategy::Rspec::Unit end.on('--rspec-full', 'executes all specs under ./spec') do set_strategy Strategy::Rspec::Full - end.on('--rspec-dm2', 'executes spec/unit/namespace/class/method_spec.rb') do + end.on('--rspec-dm2', 'executes spec/unit/$nesting/$method_spec.rb') do set_strategy Strategy::Rspec::DM2 end end From 8a9828762df7107d3b34f36e3a885aaddc7b68de Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 19:59:25 +0200 Subject: [PATCH 36/43] Fix stlye in Mutant::Matcher::Methods --- lib/mutant/matcher/methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/matcher/methods.rb b/lib/mutant/matcher/methods.rb index 6f73cdd7..6f26f8fb 100644 --- a/lib/mutant/matcher/methods.rb +++ b/lib/mutant/matcher/methods.rb @@ -1,6 +1,6 @@ module Mutant class Matcher - # Abstract base class for matcher that returns method subjects extracted from scope + # Abstract base class for matcher that returns method subjects from scope class Methods < self include AbstractType, Concord::Public.new(:cache, :scope) From 83f263deb81895551a94a1a39bacaa9c6b6fa83b Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 20:00:53 +0200 Subject: [PATCH 37/43] Fix style in Mutant::Matcher::Method::Instance --- lib/mutant/matcher/method/instance.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mutant/matcher/method/instance.rb b/lib/mutant/matcher/method/instance.rb index b351df3e..cceed857 100644 --- a/lib/mutant/matcher/method/instance.rb +++ b/lib/mutant/matcher/method/instance.rb @@ -16,7 +16,8 @@ module Mutant # @api private # def self.build(cache, scope, method) - if scope.ancestors.include?(::Adamantium) and scope.memoized?(method.name) + name = method.name + if scope.ancestors.include?(::Adamantium) and scope.memoized?(name) return Memoized.new(cache, scope, method) end super From e73e270386d6f57a7fbf1863bb53c517e325ac87 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 20:07:57 +0200 Subject: [PATCH 38/43] Fix style in Mutant::Matcher::Method --- lib/mutant/matcher/method.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/mutant/matcher/method.rb b/lib/mutant/matcher/method.rb index 596b45de..1e8195d5 100644 --- a/lib/mutant/matcher/method.rb +++ b/lib/mutant/matcher/method.rb @@ -26,7 +26,12 @@ module Mutant if subject yield subject else - $stderr.puts "Cannot find definition of: #{identification} in #{source_location.join(':')}" + message = sprinf( + 'Cannot find definition of: %s in %s', + identification, + source_location.join(':') + ) + $stderr.puts(message) end end @@ -48,7 +53,11 @@ module Mutant def skip? location = source_location if location.nil? or BLACKLIST.match(location.first) - $stderr.puts "#{method.inspect} does not have valid source location so mutant is unable to emit matcher" + message = sprintf( + '%s does not have valid source location unable to emit matcher', + method.inspect + ) + $stderr.puts(message) return true end From 6bdbdb719e85f11008622f72d1ff23026e754fc9 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 20:11:21 +0200 Subject: [PATCH 39/43] Fix style in Mutant::Matcher::Method::Singleton --- lib/mutant/matcher/method/singleton.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mutant/matcher/method/singleton.rb b/lib/mutant/matcher/method/singleton.rb index db6f6b40..f9b91d8a 100644 --- a/lib/mutant/matcher/method/singleton.rb +++ b/lib/mutant/matcher/method/singleton.rb @@ -92,7 +92,11 @@ module Mutant when :const receiver_name?(receiver) else - $stderr.puts "Can only match self or const, got #{receiver.type}, unable to match receiver of defs node" + message = sprintf( + 'Can only match :defs on :self or :const got %s unable to match', + receiver.type.inspect + ) + $stderr.puts(message) false end end From b087a6e4d8554f0eed12360cfc4ad77645a242cb Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 20:14:29 +0200 Subject: [PATCH 40/43] Fix style in Mutant::Color --- lib/mutant/color.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mutant/color.rb b/lib/mutant/color.rb index 44c63049..cb5ceb8e 100644 --- a/lib/mutant/color.rb +++ b/lib/mutant/color.rb @@ -27,7 +27,8 @@ module Mutant "\e[#{@code}m#{text}\e[0m" end - NONE = Class.new(self) do + Mutant.singleton_subclass_instance('NONE', self) do + # Format null color # # @param [String] text @@ -49,13 +50,14 @@ module Mutant # # @api private # - def initialize(*) + def initialize end - end.new.freeze + end RED = Color.new(31) GREEN = Color.new(32) BLUE = Color.new(34) + end # Color end # Mutant From 46f90aa328267f4486556bb0ddee9256cb6217db Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 28 Jul 2013 23:52:05 +0200 Subject: [PATCH 41/43] Fix all style warnings under spec/**/*.rb --- config/rubocop.yml | 12 ++++ spec/integration/mutant/rspec_killer_spec.rb | 9 ++- spec/shared/mutator_behavior.rb | 17 +++-- .../unit/mutant/cli/class_methods/new_spec.rb | 23 +++--- .../unit/mutant/cli/class_methods/run_spec.rb | 10 ++- .../classifier/class_methods/build_spec.rb | 3 +- spec/unit/mutant/context/root_spec.rb | 4 +- spec/unit/mutant/differ/diff_spec.rb | 70 +++++++++++++++++-- .../killer/rspec/class_methods/new_spec.rb | 23 ++++-- .../loader/eval/class_methods/run_spec.rb | 15 ++-- spec/unit/mutant/matcher/each_spec.rb | 7 +- .../instance/class_methods/build_spec.rb | 4 +- .../matcher/method/instance/each_spec.rb | 15 ++-- .../matcher/method/singleton/each_spec.rb | 17 +++-- .../matcher/methods/instance/each_spec.rb | 9 ++- .../matcher/methods/singleton/each_spec.rb | 9 ++- .../mutant/matcher/namespace/each_spec.rb | 8 ++- spec/unit/mutant/mutator/emit_new_spec.rb | 7 +- .../mutant/mutator/node/literal/range_spec.rb | 2 - .../runner/config/success_predicate_spec.rb | 18 +++-- .../runner/subject/success_predicate_spec.rb | 17 +++-- .../lookup/method/instance/spec_files_spec.rb | 41 ++++++++--- .../method/singleton/spec_files_spec.rb | 40 ++++++++--- .../shared/method_filter_parse_behavior.rb | 4 +- test_app/spec/shared/mutator_behavior.rb | 47 ------------- 25 files changed, 292 insertions(+), 139 deletions(-) delete mode 100644 test_app/spec/shared/mutator_behavior.rb diff --git a/config/rubocop.yml b/config/rubocop.yml index 600bce4e..93d34398 100644 --- a/config/rubocop.yml +++ b/config/rubocop.yml @@ -55,6 +55,18 @@ Documentation: IfUnlessModifier: Enabled: false +# Mutant needs to define methods like def bar; end in specs +Semicolon: + Enabled: false + +# Mutant needs to define multiple methods on same line in specs +EmptyLineBetweenDefs: + Enabled: false + +# Mutant needs to define singleton methods like Foo.bar in specs +ClassMethods: + Enabled: false + # Allow case equality operator (in limited use within the specs) CaseEquality: Enabled: false diff --git a/spec/integration/mutant/rspec_killer_spec.rb b/spec/integration/mutant/rspec_killer_spec.rb index 13ec5ebd..bf2678af 100644 --- a/spec/integration/mutant/rspec_killer_spec.rb +++ b/spec/integration/mutant/rspec_killer_spec.rb @@ -11,14 +11,17 @@ describe Mutant, 'rspec integration' do let(:strategy) { Mutant::Strategy::Rspec::DM2 } specify 'allows to kill mutations' do - Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal#string').should be(true) + cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal#string' + Kernel.system(cli).should be(true) end specify 'fails to kill mutations when they are not covered' do - Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal#uncovered_string').should be(false) + cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal#uncovered_string' + Kernel.system(cli).should be(false) end specify 'fails when some mutations when are not covered' do - Kernel.system('bundle exec mutant --rspec-dm2 ::TestApp::Literal').should be(false) + cli = 'bundle exec mutant --rspec-dm2 ::TestApp::Literal' + Kernel.system(cli).should be(false) end end diff --git a/spec/shared/mutator_behavior.rb b/spec/shared/mutator_behavior.rb index 620cc224..2fd3d518 100644 --- a/spec/shared/mutator_behavior.rb +++ b/spec/shared/mutator_behavior.rb @@ -32,7 +32,7 @@ class Subject again = Unparser.generate(parsed) unless generated == again # mostly an unparser bug! - fail "Untransitive:\n%s\n---\n%s" % [generated, again] + fail sprintf("Untransitive:\n%s\n---\n%s", generated, again) end self end @@ -74,16 +74,25 @@ shared_examples_for 'a mutator' do message = [] if missing.any? - message << 'Missing mutations (%i):' % missing.length + message << sprintf('Missing mutations (%i):', missing.length) message.concat(missing) end if unexpected.any? - message << 'Unexpected mutations (%i):' % unexpected.length + message << sprintf('Unexpected mutations (%i):', unexpected.length) message.concat(unexpected) end - fail "Original:\n#{generate(node)}\n-----\n#{message.join("\n-----\n")}" if message.any? + if message.any? + + message = sprintf( + "Original:\n%s\n-----\n%s", + generate(node), + message.join("\n-----\n") + ) + + fail message + end end end end diff --git a/spec/unit/mutant/cli/class_methods/new_spec.rb b/spec/unit/mutant/cli/class_methods/new_spec.rb index 38eff251..8ca8b662 100644 --- a/spec/unit/mutant/cli/class_methods/new_spec.rb +++ b/spec/unit/mutant/cli/class_methods/new_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' shared_examples_for 'an invalid cli run' do it 'should raise error' do - expect { subject }.to raise_error(Mutant::CLI::Error, expected_message) + expect do + subject + end.to raise_error(Mutant::CLI::Error, expected_message) end end @@ -28,6 +30,9 @@ describe Mutant::CLI, '.new' do let(:expected_strategy) { Mutant::Strategy::Rspec::Unit } let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) } + let(:ns) { Mutant::CLI::Classifier } + let(:cache) { Mutant::Cache.new } + let(:cli) { object.new(arguments) } subject { cli } @@ -70,21 +75,23 @@ describe Mutant::CLI, '.new' do end context 'with explicit method matcher' do - let(:arguments) { %w(--rspec-unit TestApp::Literal#float) } - let(:expected_matcher) { Mutant::CLI::Classifier::Method.new(Mutant::Cache.new, 'TestApp::Literal#float') } + let(:arguments) { %w(--rspec-unit TestApp::Literal#float) } + let(:expected_matcher) { ns::Method.new(cache, 'TestApp::Literal#float') } it_should_behave_like 'a cli parser' end context 'with namespace matcher' do - let(:arguments) { %w(--rspec-unit ::TestApp*) } - let(:expected_matcher) { Mutant::CLI::Classifier::Namespace::Recursive.new(Mutant::Cache.new, '::TestApp*') } + let(:matcher) { '::TestApp*' } + let(:arguments) { %W(--rspec-unit #{matcher}) } + let(:expected_matcher) { ns::Namespace::Recursive.new(cache, matcher) } it_should_behave_like 'a cli parser' end context 'with code filter' do - let(:arguments) { %w(--rspec-unit --code faa --code bbb TestApp::Literal#float) } + let(:matcher) { 'TestApp::Literal#float' } + let(:arguments) { %W(--rspec-unit --code faa --code bbb #{matcher}) } let(:filters) do [ @@ -93,8 +100,8 @@ describe Mutant::CLI, '.new' do ] end - let(:expected_matcher) { Mutant::CLI::Classifier::Method.new(Mutant::Cache.new, 'TestApp::Literal#float') } - let(:expected_filter) { Mutant::Mutation::Filter::Whitelist.new(filters) } + let(:expected_matcher) { ns::Method.new(cache, 'TestApp::Literal#float') } + let(:expected_filter) { Mutant::Mutation::Filter::Whitelist.new(filters) } it_should_behave_like 'a cli parser' end diff --git a/spec/unit/mutant/cli/class_methods/run_spec.rb b/spec/unit/mutant/cli/class_methods/run_spec.rb index c466381b..a8ff0a13 100644 --- a/spec/unit/mutant/cli/class_methods/run_spec.rb +++ b/spec/unit/mutant/cli/class_methods/run_spec.rb @@ -21,7 +21,10 @@ describe Mutant::CLI, '.run' do it { should be(0) } it 'should run with attributes' do - Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner) + Mutant::Runner::Config + .should_receive(:run) + .with(config) + .and_return(runner) should be(0) end end @@ -32,7 +35,10 @@ describe Mutant::CLI, '.run' do it { should be(1) } it 'should run with attributes' do - Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner) + Mutant::Runner::Config + .should_receive(:run) + .with(config) + .and_return(runner) should be(1) end end diff --git a/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb b/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb index 7d883ce0..81c21ae1 100644 --- a/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb +++ b/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb @@ -9,7 +9,8 @@ describe Mutant::CLI::Classifier, '.build' do shared_examples_for this_spec do it 'shoud return expected instance' do - should eql(expected_class.new(cache, expected_class::REGEXP.match(input))) + regexp = expected_class::REGEXP + should eql(expected_class.new(cache, regexp.match(input))) end let(:expected_class) { Mutant::CLI::Classifier::Method } diff --git a/spec/unit/mutant/context/root_spec.rb b/spec/unit/mutant/context/root_spec.rb index b3039587..f1b3d4b6 100644 --- a/spec/unit/mutant/context/root_spec.rb +++ b/spec/unit/mutant/context/root_spec.rb @@ -6,6 +6,8 @@ describe Mutant::Context, '#root' do let(:object) { described_class.allocate } it 'should raise error' do - expect { subject }.to raise_error('Mutant::Context#root is not implemented') + expect do + subject + end.to raise_error('Mutant::Context#root is not implemented') end end diff --git a/spec/unit/mutant/differ/diff_spec.rb b/spec/unit/mutant/differ/diff_spec.rb index 5f5c18c8..063fc5f1 100644 --- a/spec/unit/mutant/differ/diff_spec.rb +++ b/spec/unit/mutant/differ/diff_spec.rb @@ -9,7 +9,16 @@ describe Mutant::Differ, '#diff' do let(:old) { %w(foo bar) } let(:new) { %w(baz bar) } - it { should eql("@@ -1,3 +1,3 @@\n-foo\n+baz\n bar\n") } + let(:expectation) do + strip_indent(<<-STR) + @@ -1,3 +1,3 @@ + -foo + +baz + bar + STR + end + + it { should eql(expectation) } it_should_behave_like 'an idempotent method' end @@ -18,7 +27,16 @@ describe Mutant::Differ, '#diff' do let(:old) { %w(foo bar) } let(:new) { %w(foo baz bar) } - it { should eql("@@ -1,3 +1,4 @@\n foo\n+baz\n bar\n") } + let(:expectation) do + strip_indent(<<-STR) + @@ -1,3 +1,4 @@ + foo + +baz + bar + STR + end + + it { should eql(expectation) } it_should_behave_like 'an idempotent method' end @@ -27,7 +45,21 @@ describe Mutant::Differ, '#diff' do let(:old) { %w(foo bar baz boz a b c) } let(:new) { %w(foo bar baz boz a b c other) } - it { should eql("@@ -1,8 +1,9 @@\n foo\n bar\n baz\n boz\n a\n b\n c\n+other\n") } + let(:expectation) do + strip_indent(<<-STR) + @@ -1,8 +1,9 @@ + foo + bar + baz + boz + a + b + c + +other + STR + end + + it { should eql(expectation) } it_should_behave_like 'an idempotent method' end @@ -36,7 +68,21 @@ describe Mutant::Differ, '#diff' do let(:old) { %w(other foo bar baz boz a b c) } let(:new) { %w(foo bar baz boz a b c) } - it { should eql("@@ -1,9 +1,8 @@\n-other\n foo\n bar\n baz\n boz\n a\n b\n c\n") } + let(:expectation) do + strip_indent(<<-STR) + @@ -1,9 +1,8 @@ + -other + foo + bar + baz + boz + a + b + c + STR + end + + it { should eql(expectation) } it_should_behave_like 'an idempotent method' end @@ -45,7 +91,21 @@ describe Mutant::Differ, '#diff' do let(:old) { %w(foo bar baz boz a b c) } let(:new) { %w(other foo bar baz boz a b c) } - it { should eql("@@ -1,8 +1,9 @@\n+other\n foo\n bar\n baz\n boz\n a\n b\n c\n") } + let(:expectation) do + strip_indent(<<-STR) + @@ -1,8 +1,9 @@ + +other + foo + bar + baz + boz + a + b + c + STR + end + + it { should eql(expectation) } it_should_behave_like 'an idempotent method' end diff --git a/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb b/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb index 252cdb65..b7d72840 100644 --- a/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb +++ b/spec/unit/mutant/killer/rspec/class_methods/new_spec.rb @@ -4,13 +4,28 @@ describe Mutant::Killer::Rspec, '.new' do subject { object.new(strategy, mutation) } - let(:strategy) { double('Strategy', :spec_files => ['foo'], :error_stream => $stderr, :output_stream => $stdout) } - let(:context) { double('Context') } - let(:mutation) { double('Mutation', :subject => mutation_subject, :should_survive? => false) } - let(:mutation_subject) { double('Mutation Subject') } + let(:context) { double('Context') } + let(:mutation_subject) { double('Mutation Subject') } let(:object) { described_class } + let(:mutation) do + double( + 'Mutation', + :subject => mutation_subject, + :should_survive? => false + ) + end + + let(:strategy) do + double( + 'Strategy', + :spec_files => ['foo'], + :error_stream => $stderr, + :output_stream => $stdout + ) + end + before do mutation.stub(:insert) mutation.stub(:reset) diff --git a/spec/unit/mutant/loader/eval/class_methods/run_spec.rb b/spec/unit/mutant/loader/eval/class_methods/run_spec.rb index 87c89615..ce6cdc88 100644 --- a/spec/unit/mutant/loader/eval/class_methods/run_spec.rb +++ b/spec/unit/mutant/loader/eval/class_methods/run_spec.rb @@ -4,10 +4,13 @@ describe Mutant::Loader::Eval, '.run' do subject { object.run(node, mutation_subject) } - let(:object) { described_class } - let(:mutation_subject) { double('Subject', :source_path => path, :source_line => line) } - let(:path) { 'test.rb' } - let(:line) { 1 } + let(:object) { described_class } + let(:path) { 'test.rb' } + let(:line) { 1 } + + let(:mutation_subject) do + double('Subject', :source_path => path, :source_line => line) + end let(:source) do <<-RUBY @@ -36,6 +39,8 @@ describe Mutant::Loader::Eval, '.run' do it 'should set file and line correctly' do subject - ::SomeNamespace::Bar.instance_method(:some_method).source_location.should eql(['test.rb', 3]) + ::SomeNamespace::Bar + .instance_method(:some_method) + .source_location.should eql(['test.rb', 3]) end end diff --git a/spec/unit/mutant/matcher/each_spec.rb b/spec/unit/mutant/matcher/each_spec.rb index 673db61c..338e2961 100644 --- a/spec/unit/mutant/matcher/each_spec.rb +++ b/spec/unit/mutant/matcher/each_spec.rb @@ -9,6 +9,11 @@ describe Mutant::Matcher, '#each' do let(:object) { described_class.allocate } it 'should raise error' do - expect { subject }.to raise_error(NotImplementedError, 'Mutant::Matcher#each is not implemented') + expect do + subject + end.to raise_error( + NotImplementedError, + 'Mutant::Matcher#each is not implemented' + ) end end diff --git a/spec/unit/mutant/matcher/method/instance/class_methods/build_spec.rb b/spec/unit/mutant/matcher/method/instance/class_methods/build_spec.rb index e6c33ed0..b36f2f8d 100644 --- a/spec/unit/mutant/matcher/method/instance/class_methods/build_spec.rb +++ b/spec/unit/mutant/matcher/method/instance/class_methods/build_spec.rb @@ -28,13 +28,13 @@ describe Mutant::Matcher::Method::Instance, '.build' do context 'with unmemoized method' do let(:method_name) { :bar } - it { should eql(Mutant::Matcher::Method::Instance.new(cache, scope, method)) } + it { should eql(described_class.new(cache, scope, method)) } end context 'with memoized method' do let(:method_name) { :foo } - it { should eql(Mutant::Matcher::Method::Instance::Memoized.new(cache, scope, method)) } + it { should eql(described_class::Memoized.new(cache, scope, method)) } end end end diff --git a/spec/unit/mutant/matcher/method/instance/each_spec.rb b/spec/unit/mutant/matcher/method/instance/each_spec.rb index 1e552382..0aa43716 100644 --- a/spec/unit/mutant/matcher/method/instance/each_spec.rb +++ b/spec/unit/mutant/matcher/method/instance/each_spec.rb @@ -36,11 +36,14 @@ describe Mutant::Matcher::Method::Instance, '#each' do context 'on differend lines' do let(:base) { __LINE__ } class self::Foo - def bar; end - def bar(arg); end + def bar + end + + def bar(arg) + end end - let(:method_line) { 3 } + let(:method_line) { 5 } let(:method_arity) { 1 } it_should_behave_like 'a method matcher' @@ -77,7 +80,8 @@ describe Mutant::Matcher::Method::Instance, '#each' do let(:base) { __LINE__ } class self::Foo class Bar - def baz; end + def baz + end end end @@ -92,7 +96,8 @@ describe Mutant::Matcher::Method::Instance, '#each' do let(:base) { __LINE__ } module self::Foo class Bar - def baz; end + def baz + end end end diff --git a/spec/unit/mutant/matcher/method/singleton/each_spec.rb b/spec/unit/mutant/matcher/method/singleton/each_spec.rb index 8bfb422e..08471581 100644 --- a/spec/unit/mutant/matcher/method/singleton/each_spec.rb +++ b/spec/unit/mutant/matcher/method/singleton/each_spec.rb @@ -40,7 +40,8 @@ describe Mutant::Matcher::Method::Singleton, '#each' do let(:base) { __LINE__ } module self::Namespace class Foo - def Foo.bar; end + def Foo.bar + end end end @@ -54,12 +55,15 @@ describe Mutant::Matcher::Method::Singleton, '#each' do context 'outside namespace' do let(:base) { __LINE__ } module self::Namespace - class Foo; end; - def Foo.bar; end + class Foo + end + + def Foo.bar + end end let(:method_name) { :bar } - let(:method_line) { 3 } + let(:method_line) { 5 } let(:scope) { self.class::Namespace::Foo } it_should_behave_like 'a method matcher' @@ -72,7 +76,10 @@ describe Mutant::Matcher::Method::Singleton, '#each' do module self::Namespace module Foo; end module Bar - def self.baz; end; def Foo.baz(arg); end + def self.baz + end + def Foo.baz(arg) + end end end diff --git a/spec/unit/mutant/matcher/methods/instance/each_spec.rb b/spec/unit/mutant/matcher/methods/instance/each_spec.rb index e3a455cc..1e022ae1 100644 --- a/spec/unit/mutant/matcher/methods/instance/each_spec.rb +++ b/spec/unit/mutant/matcher/methods/instance/each_spec.rb @@ -46,9 +46,12 @@ describe Mutant::Matcher::Methods::Instance, '#each' do before do matcher = Mutant::Matcher::Method::Instance - matcher.stub(:new).with(cache, Foo, Foo.instance_method(:method_a)).and_return([subject_a]) - matcher.stub(:new).with(cache, Foo, Foo.instance_method(:method_b)).and_return([subject_b]) - matcher.stub(:new).with(cache, Foo, Foo.instance_method(:method_c)).and_return([subject_c]) + matcher.stub(:new) + .with(cache, Foo, Foo.instance_method(:method_a)).and_return([subject_a]) + matcher.stub(:new) + .with(cache, Foo, Foo.instance_method(:method_b)).and_return([subject_b]) + matcher.stub(:new) + .with(cache, Foo, Foo.instance_method(:method_c)).and_return([subject_c]) end it 'should yield expected subjects' do diff --git a/spec/unit/mutant/matcher/methods/singleton/each_spec.rb b/spec/unit/mutant/matcher/methods/singleton/each_spec.rb index 6cb1cb75..2dad2aea 100644 --- a/spec/unit/mutant/matcher/methods/singleton/each_spec.rb +++ b/spec/unit/mutant/matcher/methods/singleton/each_spec.rb @@ -40,9 +40,12 @@ describe Mutant::Matcher::Methods::Singleton, '#each' do before do matcher = Mutant::Matcher::Method::Singleton - matcher.stub(:new).with(cache, Foo, Foo.method(:method_a)).and_return([subject_a]) - matcher.stub(:new).with(cache, Foo, Foo.method(:method_b)).and_return([subject_b]) - matcher.stub(:new).with(cache, Foo, Foo.method(:method_c)).and_return([subject_c]) + matcher.stub(:new) + .with(cache, Foo, Foo.method(:method_a)).and_return([subject_a]) + matcher.stub(:new) + .with(cache, Foo, Foo.method(:method_b)).and_return([subject_b]) + matcher.stub(:new) + .with(cache, Foo, Foo.method(:method_c)).and_return([subject_c]) end it 'should yield expected subjects' do diff --git a/spec/unit/mutant/matcher/namespace/each_spec.rb b/spec/unit/mutant/matcher/namespace/each_spec.rb index f10c63c7..f9942476 100644 --- a/spec/unit/mutant/matcher/namespace/each_spec.rb +++ b/spec/unit/mutant/matcher/namespace/each_spec.rb @@ -14,8 +14,12 @@ describe Mutant::Matcher::Namespace, '#each' do let(:subject_b) { double('SubjectB') } before do - Mutant::Matcher::Methods::Singleton.stub(:each).with(cache, singleton_a).and_yield(subject_a) - Mutant::Matcher::Methods::Instance.stub(:each).with(cache, singleton_a).and_yield(subject_b) + Mutant::Matcher::Methods::Singleton.stub(:each) + .with(cache, singleton_a) + .and_yield(subject_a) + Mutant::Matcher::Methods::Instance.stub(:each) + .with(cache, singleton_a) + .and_yield(subject_b) ObjectSpace.stub(:each_object => [singleton_a, singleton_b]) end diff --git a/spec/unit/mutant/mutator/emit_new_spec.rb b/spec/unit/mutant/mutator/emit_new_spec.rb index 2cf652d4..e689092f 100644 --- a/spec/unit/mutant/mutator/emit_new_spec.rb +++ b/spec/unit/mutant/mutator/emit_new_spec.rb @@ -46,7 +46,12 @@ describe Mutant::Mutator, '#emit_new' do let(:generated) { input } it 'should raise error' do - expect { subject }.to raise_error(RuntimeError, 'New AST could not be generated after 3 attempts') + expect do + subject + end.to raise_error( + RuntimeError, + 'New AST could not be generated after 3 attempts' + ) end end end diff --git a/spec/unit/mutant/mutator/node/literal/range_spec.rb b/spec/unit/mutant/mutator/node/literal/range_spec.rb index 2b5b167c..94212698 100644 --- a/spec/unit/mutant/mutator/node/literal/range_spec.rb +++ b/spec/unit/mutant/mutator/node/literal/range_spec.rb @@ -9,7 +9,6 @@ describe Mutant::Mutator::Node::Literal, 'range' do mutations << 'nil' mutations << '1...100' mutations << '(0.0 / 0.0)..100' - # mutations << [:dot2, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] mutations << '1..(1.0 / 0.0)' mutations << '1..(0.0 / 0.0)' end @@ -25,7 +24,6 @@ describe Mutant::Mutator::Node::Literal, 'range' do mutations << 'nil' mutations << '1..100' mutations << '(0.0 / 0.0)...100' - # mutations << [:dot3, [:negate, [:call, [:lit, 1.0], :/, [:arglist, [:lit, 0.0]]]], [:lit, 100]] mutations << '1...(1.0 / 0.0)' mutations << '1...(0.0 / 0.0)' end diff --git a/spec/unit/mutant/runner/config/success_predicate_spec.rb b/spec/unit/mutant/runner/config/success_predicate_spec.rb index 43a655a5..0b437e64 100644 --- a/spec/unit/mutant/runner/config/success_predicate_spec.rb +++ b/spec/unit/mutant/runner/config/success_predicate_spec.rb @@ -14,12 +14,18 @@ describe Mutant::Runner::Config, '#success?' do ) end - let(:reporter) { double('Reporter') } - let(:strategy) { double('Strategy') } - let(:subject_a) { double('Subject A') } - let(:subject_b) { double('Subject B') } - let(:runner_a) { double('Runner A', :stop? => stop_a, :success? => success_a) } - let(:runner_b) { double('Runner B', :stop? => stop_b, :success? => success_b) } + let(:reporter) { double('Reporter') } + let(:strategy) { double('Strategy') } + let(:subject_a) { double('Subject A') } + let(:subject_b) { double('Subject B') } + + let(:runner_a) do + double('Runner A', :stop? => stop_a, :success? => success_a) + end + + let(:runner_b) do + double('Runner B', :stop? => stop_b, :success? => success_b) + end before do reporter.stub(:report => reporter) diff --git a/spec/unit/mutant/runner/subject/success_predicate_spec.rb b/spec/unit/mutant/runner/subject/success_predicate_spec.rb index cdf413a7..58d21519 100644 --- a/spec/unit/mutant/runner/subject/success_predicate_spec.rb +++ b/spec/unit/mutant/runner/subject/success_predicate_spec.rb @@ -13,13 +13,18 @@ describe Mutant::Runner::Subject, '#success?' do ) end - let(:reporter) { double('Reporter') } - let(:config) { double('Config', :reporter => reporter) } - let(:mutation_a) { double('Mutation A') } - let(:mutation_b) { double('Mutation B') } + let(:reporter) { double('Reporter') } + let(:config) { double('Config', :reporter => reporter) } + let(:mutation_a) { double('Mutation A') } + let(:mutation_b) { double('Mutation B') } - let(:runner_a) { double('Runner A', :success? => success_a, :stop? => stop_a) } - let(:runner_b) { double('Runner B', :success? => success_b, :stop? => stop_b) } + let(:runner_a) do + double('Runner A', :success? => success_a, :stop? => stop_a) + end + + let(:runner_b) do + double('Runner B', :success? => success_b, :stop? => stop_b) + end before do reporter.stub(:report => reporter) 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 d0577a44..ab1ce701 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 @@ -1,24 +1,40 @@ require 'spec_helper' -describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance, '#spec_files' do +singleton = Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance + +describe singleton, '#spec_files' do subject { object.spec_files } - let(:object) { described_class.new(mutation_subject) } - let(:mutation_subject) { double('Subject', :name => method_name, :public? => is_public, :context => context) } - let(:context) { double('Context', :name => 'Foo') } - let(:method_name) { :bar } - let(:files) { 'Files'.freeze } + let(:object) { described_class.new(mutation_subject) } + let(:context) { double('Context', :name => 'Foo') } + let(:method_name) { :bar } + let(:files) { 'Files'.freeze } - this_example_group = 'Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance#spec_files' + let(:mutation_subject) do + double( + 'Subject', + :name => method_name, + :public? => is_public, + :context => context + ) + end + + this_example_group = description shared_examples_for this_example_group do it_should_behave_like 'an idempotent method' before do if is_public - Mutant::Strategy::MethodExpansion.should_receive(:run).with(method_name).and_return(:expanded_name) + Mutant::Strategy::MethodExpansion + .should_receive(:run) + .with(method_name) + .and_return(:expanded_name) end - Dir.should_receive(:glob).with(expected_glob_expression).and_return(files) + + Dir.should_receive(:glob) + .with(expected_glob_expression) + .and_return(files) end it { should be(files) } @@ -42,8 +58,11 @@ describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Instance, '#spec_files' d end context 'initialize' do - let(:method_name) { :initialize } - let(:expected_glob_expression) { '{spec/unit/foo/*_spec.rb,spec/unit/foo/class_methods/new_spec.rb}' } + let(:method_name) { :initialize } + + let(:expected_glob_expression) do + '{spec/unit/foo/*_spec.rb,spec/unit/foo/class_methods/new_spec.rb}' + end it_should_behave_like this_example_group end 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 f48fa6fc..3023bac3 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 @@ -1,25 +1,40 @@ require 'spec_helper' -describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton, '#spec_files' do +singleton = Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton + +describe singleton, '#spec_files' do subject { object.spec_files } - let(:object) { described_class.new(mutation_subject) } - let(:mutation_subject) { double('Subject', :name => method_name, :public? => is_public, :context => context) } - let(:method_name) { :bar } - let(:files) { 'Files'.freeze } - let(:context) { double('Context', :name => 'Foo') } + let(:object) { described_class.new(mutation_subject) } + let(:method_name) { :bar } + let(:files) { 'Files'.freeze } + let(:context) { double('Context', :name => 'Foo') } - this_example_group = 'Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton#spec_files' + let(:mutation_subject) do + double( + 'Subject', + :name => method_name, + :public? => is_public, + :context => context + ) + end + + this_example_group = description shared_examples_for this_example_group do it_should_behave_like 'an idempotent method' before do if is_public - Mutant::Strategy::MethodExpansion.should_receive(:run).with(method_name).and_return(:expanded_name) + Mutant::Strategy::MethodExpansion + .should_receive(:run) + .with(method_name) + .and_return(:expanded_name) end - Dir.should_receive(:glob).with(expected_glob_expression).and_return(files) + Dir.should_receive(:glob) + .with(expected_glob_expression) + .and_return(files) end it { should be(files) } @@ -27,8 +42,11 @@ describe Mutant::Strategy::Rspec::DM2::Lookup::Method::Singleton, '#spec_files' end context 'with public method' do - let(:is_public) { true } - let(:expected_glob_expression) { 'spec/unit/foo/class_methods/expanded_name_spec.rb' } + let(:is_public) { true } + + let(:expected_glob_expression) do + 'spec/unit/foo/class_methods/expanded_name_spec.rb' + end it_should_behave_like this_example_group end diff --git a/test_app/spec/shared/method_filter_parse_behavior.rb b/test_app/spec/shared/method_filter_parse_behavior.rb index e72e8736..99cb867e 100644 --- a/test_app/spec/shared/method_filter_parse_behavior.rb +++ b/test_app/spec/shared/method_filter_parse_behavior.rb @@ -8,7 +8,9 @@ shared_examples_for 'a method filter parse result' do it { should be(response) } it 'should initialize method filter with correct arguments' do - expected_class.should_receive(:new).with(TestApp::Literal, :string).and_return(response) + expected_class.should_receive(:new) + .with(TestApp::Literal, :string) + .and_return(response) subject end end diff --git a/test_app/spec/shared/mutator_behavior.rb b/test_app/spec/shared/mutator_behavior.rb deleted file mode 100644 index 75337730..00000000 --- a/test_app/spec/shared/mutator_behavior.rb +++ /dev/null @@ -1,47 +0,0 @@ -shared_examples_for 'a mutator' do - subject { object.each(node) { |item| yields << item } } - - let(:yields) { [] } - let(:object) { described_class } - - unless instance_methods.map(&:to_s).include?('node') - let(:node) { source.to_ast } - end - - it_should_behave_like 'a command method' - - context 'with no block' do - subject { object.each(node) } - - it { should be_instance_of(to_enum.class) } - - let(:expected_mutations) do - mutations.map do |mutation| - if mutation.respond_to?(:to_ast) - mutation.to_ast.to_sexp - else - mutation - end - end.to_set - end - - it 'generates the expected mutations' do - subject = self.subject.map(&:to_sexp).to_set - - unless subject == expected_mutations - message = "Missing mutations: %s\nUnexpected mutations: %s" % - [ - expected_mutations - subject, - subject - expected_mutations - ].map(&:to_a).map(&:inspect) - fail message - end - end - end -end - -shared_examples_for 'a noop mutator' do - let(:mutations) { [] } - - it_should_behave_like 'a mutator' -end From 3dde50023b4523d7303cb043d9e142860e97821e Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 15:27:53 -0700 Subject: [PATCH 42/43] Update metrics thresholds --- config/flay.yml | 2 +- config/flog.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/flay.yml b/config/flay.yml index da73e5ca..9892b938 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 757 +total_score: 773 diff --git a/config/flog.yml b/config/flog.yml index 50ba1616..d39172f7 100644 --- a/config/flog.yml +++ b/config/flog.yml @@ -1,2 +1,2 @@ --- -threshold: 21.2 +threshold: 20.5 From d54230eaa51c4b7f576b7e9b3b6880eb314d1ceb Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 29 Jul 2013 00:34:25 +0200 Subject: [PATCH 43/43] Fix misspelled method name --- lib/mutant/matcher/method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mutant/matcher/method.rb b/lib/mutant/matcher/method.rb index 1e8195d5..2ca3fdf3 100644 --- a/lib/mutant/matcher/method.rb +++ b/lib/mutant/matcher/method.rb @@ -26,7 +26,7 @@ module Mutant if subject yield subject else - message = sprinf( + message = sprintf( 'Cannot find definition of: %s in %s', identification, source_location.join(':')