Fix rubocop warnings

* Still a few more to go, but this should be the majority of them
This commit is contained in:
Dan Kubb 2013-07-28 12:16:45 -07:00
parent 5463079393
commit ee72d6c042
31 changed files with 77 additions and 94 deletions

View file

@ -12,7 +12,7 @@ module Mutant
SCOPE_PATTERN = /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze SCOPE_PATTERN = /(?:::)?#{SCOPE_NAME_PATTERN}(?:::#{SCOPE_NAME_PATTERN})*/.freeze
CBASE_PATTERN = /\A::/.freeze CBASE_PATTERN = /\A::/.freeze
SCOPE_OPERATOR = '::'.freeze SCOPE_OPERATOR = '::'.freeze
SINGLETON_PATTERN = %r(\A(#{SCOPE_PATTERN})\z).freeze SINGLETON_PATTERN = /\A(#{SCOPE_PATTERN})\z/.freeze
REGISTRY = [] REGISTRY = []
@ -36,7 +36,7 @@ module Mutant
# @api private # @api private
# #
def self.constant_lookup(location) 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) parent.const_get(name)
end end
end end

View file

@ -10,7 +10,7 @@ module Mutant
'#' => Matcher::Methods::Instance '#' => Matcher::Methods::Instance
}.freeze }.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 # Positions of captured regexp groups
SCOPE_NAME_POSITION = 1 SCOPE_NAME_POSITION = 1

View file

@ -29,14 +29,14 @@ module Mutant
# Recursive namespace classifier # Recursive namespace classifier
class Recursive < self class Recursive < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\*\z).freeze REGEXP = /\A(#{SCOPE_PATTERN})\*\z/.freeze
MATCHER = Matcher::Namespace MATCHER = Matcher::Namespace
register register
end # Recursive end # Recursive
# Recursive namespace classifier # Recursive namespace classifier
class Flat < self class Flat < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
MATCHER = Matcher::Scope MATCHER = Matcher::Scope
register register
end # Flat end # Flat

View file

@ -5,7 +5,7 @@ module Mutant
# Scope classifier # Scope classifier
class Scope < self class Scope < self
REGEXP = %r(\A(#{SCOPE_PATTERN})\z).freeze REGEXP = /\A(#{SCOPE_PATTERN})\z/.freeze
private private

View file

@ -19,7 +19,6 @@ module Mutant
# Set of node types that are not valid when emitted standalone # 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 = { OPERATOR_EXPANSIONS = {
:<=> => :spaceship_operator, :<=> => :spaceship_operator,
:=== => :case_equality_operator, :=== => :case_equality_operator,

View file

@ -12,7 +12,7 @@ module Mutant
# @api private # @api private
# #
def root(node) def root(node)
nesting.reverse.inject(node) do |current, scope| nesting.reverse.reduce(node) do |current, scope|
self.class.wrap(scope, current) self.class.wrap(scope, current)
end end
end end

View file

@ -6,7 +6,8 @@ module Mutant
# Methods within rbx kernel directory are precompiled and their source # Methods within rbx kernel directory are precompiled and their source
# cannot be accessed via reading source location # 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 # Enumerate matches
# #

View file

@ -34,7 +34,7 @@ module Mutant
# @api private # @api private
# #
def pattern def pattern
%r(\A#{Regexp.escape(namespace.name)}(?:::)?) /\A#{Regexp.escape(namespace.name)}(?:::)?/
end end
memoize :pattern memoize :pattern
@ -62,7 +62,7 @@ module Mutant
# #
def emit_scope(scope) def emit_scope(scope)
name = scope.name 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) return unless name.kind_of?(String)
if pattern =~ name if pattern =~ name
yield scope yield scope

View file

@ -42,10 +42,9 @@ module Mutant
# Insert mutated node # Insert mutated node
# #
# FIXME: # FIXME: Cache subject visibility in a better way! Ideally dont mutate it
# Cache subject visibility in a better way! Ideally dont mutate it implicitly. # implicitly. Also subject.public? should NOT be a public interface it
# Also subject.public? should NOT be a public interface it is a detail of method # is a detail of method mutations.
# mutations.
# #
# @return [self] # @return [self]
# #

View file

@ -21,7 +21,7 @@ module Mutant
mutation.code.eql?(code) mutation.code.eql?(code)
end 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 # Test if class handles string
# #

View file

@ -54,11 +54,12 @@ module Mutant
# Reporter for noop mutations # Reporter for noop mutations
class Noop < self class Noop < self
MESSAGE = MESSAGE = [
"Parsed subject AST:\n" \ 'Parsed subject AST:',
"%s\n" \ '%s',
"Unparsed source:\n" \ 'Unparsed source:',
"%s\n" '%s',
].join("\n")
private private

View file

@ -12,13 +12,13 @@ module Mutant
# #
def self.singleton_subclass_instance(name, superclass, &block) def self.singleton_subclass_instance(name, superclass, &block)
klass = Class.new(superclass) do klass = Class.new(superclass) do
def inspect
def inspect; self.class.name; end self.class.name
end
define_singleton_method(:name) do define_singleton_method(:name) do
"#{superclass.name}::#{name}".freeze "#{superclass.name}::#{name}".freeze
end end
end end
klass.class_eval(&block) klass.class_eval(&block)
superclass.const_set(name, klass.new) superclass.const_set(name, klass.new)

View file

@ -44,7 +44,7 @@ module Mutant
# Build lookup object # Build lookup object
# #
# @param [Subjecŧ] subject # @param [Subject] subject
# #
# @return [Lookup] # @return [Lookup]
# #

View file

@ -141,10 +141,10 @@ module Mutant
# #
def self.find_uncached(logical_name) def self.find_uncached(logical_name)
file_name = file_name =
unless logical_name.end_with?('.rb') if logical_name.end_with?('.rb')
"#{logical_name}.rb"
else
logical_name logical_name
else
"#{logical_name}.rb"
end end
$LOAD_PATH.each do |path| $LOAD_PATH.each do |path|
@ -248,7 +248,7 @@ module Mutant
# @api private # @api private
# #
def root_file def root_file
File.find(name) || raise("No root file!") File.find(name) or raise 'No root file!'
end end
memoize :root_file memoize :root_file

View file

@ -2,7 +2,7 @@ require 'mutant'
require 'devtools' require 'devtools'
Devtools.init_spec_helper Devtools.init_spec_helper
$: << File.join(TestApp.root,'lib') $LOAD_PATH << File.join(TestApp.root, 'lib')
require 'test_app' require 'test_app'

View file

@ -3,8 +3,6 @@ module CompressHelper
lines = string.lines lines = string.lines
match = /\A( *)/.match(lines.first) match = /\A( *)/.match(lines.first)
whitespaces = match[1].to_s.length whitespaces = match[1].to_s.length
stripped = lines.map do |line| lines.map { |line| line[whitespaces..-1] }.join
line[whitespaces..-1]
end.join
end end
end end

View file

@ -1,20 +1,14 @@
require 'spec_helper' require 'spec_helper'
describe Mutant::Matcher::Method::Instance, '#each' do describe Mutant::Matcher::Method::Instance, '#each' do
subject { object.each { |subject| yields << subject } }
let(:cache) { Fixtures::AST_CACHE } let(:cache) { Fixtures::AST_CACHE }
let(:object) { described_class.new(cache, scope, method) } let(:object) { described_class.new(cache, scope, method) }
let(:method) { scope.instance_method(method_name) } let(:method) { scope.instance_method(method_name) }
let(:yields) { [] } let(:yields) { [] }
let(:namespace) { self.class }
let(:namespace) do
klass = self.class
end
let(:scope) { self.class::Foo } let(:scope) { self.class::Foo }
subject { object.each { |subject| yields << subject } }
let(:type) { :def } let(:type) { :def }
let(:method_name) { :bar } let(:method_name) { :bar }
let(:method_arity) { 0 } let(:method_arity) { 0 }

View file

@ -1,20 +1,14 @@
require 'spec_helper' require 'spec_helper'
describe Mutant::Matcher::Method::Singleton, '#each' do describe Mutant::Matcher::Method::Singleton, '#each' do
subject { object.each { |subject| yields << subject } }
let(:object) { described_class.new(cache, scope, method) } let(:object) { described_class.new(cache, scope, method) }
let(:method) { scope.method(method_name) } let(:method) { scope.method(method_name) }
let(:cache) { Fixtures::AST_CACHE } let(:cache) { Fixtures::AST_CACHE }
let(:yields) { [] } let(:yields) { [] }
let(:namespace) { self.class }
let(:namespace) do
klass = self.class
end
let(:scope) { self.class::Foo } let(:scope) { self.class::Foo }
subject { object.each { |subject| yields << subject } }
let(:type) { :defs } let(:type) { :defs }
let(:method_arity) { 0 } let(:method_arity) { 0 }

View file

@ -4,7 +4,7 @@ describe Mutant::Mutator, '#emit_new' do
subject { object.send(:emit_new) { generated } } subject { object.send(:emit_new) { generated } }
class Block class Block
def arguments; @arguments; end attr_reader :arguments
def called? def called?
defined?(@arguments) defined?(@arguments)

View file

@ -4,7 +4,7 @@ describe Mutant::Mutator, '#emit' do
subject { object.send(:emit, generated) } subject { object.send(:emit, generated) }
class Block class Block
def arguments; @arguments; end attr_reader :arguments
def called? def called?
defined?(@arguments) defined?(@arguments)

View file

@ -2,10 +2,7 @@ require 'spec_helper'
describe Mutant::Mutator::Node::Literal, 'nil' do describe Mutant::Mutator::Node::Literal, 'nil' do
let(:source) { 'nil' } let(:source) { 'nil' }
let(:mutations) { ['::Object.new'] }
let(:mutations) do
[ '::Object.new' ]
end
it_should_behave_like 'a mutator' it_should_behave_like 'a mutator'
end end

View file

@ -7,10 +7,7 @@ describe Mutant::Mutator, 'masgn' do
end end
let(:source) { 'a, b = c, d' } let(:source) { 'a, b = c, d' }
let(:mutations) { [] }
let(:mutations) do
mutants = []
end
it_should_behave_like 'a mutator' it_should_behave_like 'a mutator'
end end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe Mutant::Mutator::Node::While do describe Mutant::Mutator::Node::While do
context 'with more than one statement' 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 let(:mutations) do
mutations = [] mutations = []

View file

@ -33,16 +33,18 @@ describe Mutant::Runner::Config, '#subjects' do
context 'without earily stop' do context 'without earily stop' do
let(:stop_a) { false } let(:stop_a) { false }
let(:stop_b) { false } let(:stop_b) { false }
it { should eql([runner_a, runner_b]) } it { should eql([runner_a, runner_b]) }
it_should_behave_like 'an idempotent method' it_should_behave_like 'an idempotent method'
end end
context 'with earily stop' do context 'with earily stop' do
let(:stop_a) { true } let(:stop_a) { true }
let(:stop_b) { false } let(:stop_b) { false }
it { should eql([runner_a]) } it { should eql([runner_a]) }
it_should_behave_like 'an idempotent method' it_should_behave_like 'an idempotent method'
end end
end end

View file

@ -34,6 +34,7 @@ describe Mutant::Runner::Config, '#success?' do
let(:stop_b) { false } let(:stop_b) { false }
let(:success_a) { true } let(:success_a) { true }
let(:success_b) { true } let(:success_b) { true }
it { should be(true) } it { should be(true) }
end end

View file

@ -27,7 +27,7 @@ describe Mutant::Runner::Mutation, '#killer' do
end end
it 'should call configuration to identify strategy' do 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) should be(killer)
end end

View file

@ -5,13 +5,13 @@ describe Mutant::Runner::Subject, '#success?' do
let(:object) { described_class.new(config, mutation_subject) } let(:object) { described_class.new(config, mutation_subject) }
let(:mutation_subject) { let(:mutation_subject) do
double( double(
'Subject', 'Subject',
:class => Mutant::Subject, :class => Mutant::Subject,
:mutations => [mutation_a, mutation_b] :mutations => [mutation_a, mutation_b]
) )
} end
let(:reporter) { double('Reporter') } let(:reporter) { double('Reporter') }
let(:config) { double('Config', :reporter => reporter) } let(:config) { double('Config', :reporter => reporter) }