From ee72d6c042558e6843fa840f3e47d6659b186bc0 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Sun, 28 Jul 2013 12:16:45 -0700 Subject: [PATCH] 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) }