Add standalone method expansions
This commit is contained in:
parent
e0f5b99971
commit
af33fd0366
3 changed files with 101 additions and 0 deletions
|
@ -98,6 +98,7 @@ require 'mutant/killer/static'
|
|||
require 'mutant/killer/rspec'
|
||||
require 'mutant/killer/forking'
|
||||
require 'mutant/strategy'
|
||||
require 'mutant/strategy/method_expansion'
|
||||
require 'mutant/strategy/rspec'
|
||||
require 'mutant/strategy/rspec/example_lookup'
|
||||
require 'mutant/runner'
|
||||
|
|
51
lib/mutant/strategy/method_expansion.rb
Normal file
51
lib/mutant/strategy/method_expansion.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
module Mutant
|
||||
class Strategy
|
||||
module MethodExpansion
|
||||
|
||||
# Run method name expansion
|
||||
#
|
||||
# @param [Symbol] name
|
||||
#
|
||||
# @return [Symbol]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.run(name)
|
||||
name = map(name) || expand(name)
|
||||
end
|
||||
|
||||
# Return mapped name
|
||||
#
|
||||
# @param [Symbol] name
|
||||
#
|
||||
# @return [Symbol]
|
||||
# if name was mapped
|
||||
#
|
||||
# @return [nil]
|
||||
# otherwise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.map(name)
|
||||
OPERATOR_EXPANSIONS[name]
|
||||
end
|
||||
private_class_method :map
|
||||
|
||||
# Return expanded name
|
||||
#
|
||||
# @param [Symbol] name
|
||||
#
|
||||
# @return [Symbol]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.expand(name)
|
||||
METHOD_NAME_EXPANSIONS.inject(name) do |name, (regexp, expansion)|
|
||||
name.to_s.gsub(regexp, expansion)
|
||||
end.to_sym
|
||||
end
|
||||
private_class_method :expand
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,49 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Strategy::MethodExpansion, '.run' do
|
||||
subject { object.run(name) }
|
||||
|
||||
let(:object) { described_class }
|
||||
|
||||
context 'unexpandable and unmapped name' do
|
||||
let(:name) { :foo }
|
||||
|
||||
it { should be(:foo) }
|
||||
end
|
||||
|
||||
context 'expanded name' do
|
||||
|
||||
context 'predicate' do
|
||||
let(:name) { :foo? }
|
||||
|
||||
it { should be(:foo_predicate) }
|
||||
end
|
||||
|
||||
context 'writer' do
|
||||
let(:name) { :foo= }
|
||||
|
||||
it { should be(:foo_writer) }
|
||||
end
|
||||
|
||||
context 'bang' do
|
||||
let(:name) { :foo! }
|
||||
|
||||
it { should be(:foo_bang) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'operator expansions' do
|
||||
|
||||
Mutant::OPERATOR_EXPANSIONS.each do |name, expansion|
|
||||
context "#{name}" do
|
||||
let(:name) { name }
|
||||
|
||||
it "should expand to #{expansion}" do
|
||||
should be(expansion)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue