Fix rubocop warnings
* Still a few more to go, but this should be the majority of them
This commit is contained in:
parent
5463079393
commit
ee72d6c042
31 changed files with 77 additions and 94 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = [
|
||||
:~@, :+@, :-@, :'!'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
#
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Add table
Reference in a new issue