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
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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -19,7 +19,6 @@ module Mutant
# Set of node types that are not valid when emitted standalone
NOT_STANDALONE = [:splat, :block_pass].to_set.freeze
OPERATOR_EXPANSIONS = {
:<=> => :spaceship_operator,
:=== => :case_equality_operator,

View file

@ -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

View file

@ -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
#

View file

@ -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

View file

@ -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]
#

View file

@ -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
#

View file

@ -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

View file

@ -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)

View file

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

View file

@ -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

View file

@ -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'

View file

@ -3,8 +3,6 @@ module CompressHelper
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

View file

@ -1,20 +1,14 @@
require 'spec_helper'
describe Mutant::Matcher::Method::Instance, '#each' do
subject { object.each { |subject| yields << subject } }
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(:namespace) { self.class }
let(:scope) { self.class::Foo }
subject { object.each { |subject| yields << subject } }
let(:type) { :def }
let(:method_name) { :bar }
let(:method_arity) { 0 }

View file

@ -1,20 +1,14 @@
require 'spec_helper'
describe Mutant::Matcher::Method::Singleton, '#each' do
subject { object.each { |subject| yields << subject } }
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(:namespace) { self.class }
let(:scope) { self.class::Foo }
subject { object.each { |subject| yields << subject } }
let(:type) { :defs }
let(:method_arity) { 0 }

View file

@ -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)

View file

@ -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)

View file

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

View file

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

View file

@ -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 = []

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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) }