Expand writer methods correctly to spec files
This commit is contained in:
parent
ac951cef91
commit
aae3b25f99
2 changed files with 47 additions and 1 deletions
|
@ -65,7 +65,7 @@ module Mutant
|
||||||
def spec_file
|
def spec_file
|
||||||
matcher.method_name.to_s.
|
matcher.method_name.to_s.
|
||||||
gsub(/\?\z/, '_predicate').
|
gsub(/\?\z/, '_predicate').
|
||||||
gsub(/\=\z/, '_writer').
|
gsub(/=\z/, '_writer').
|
||||||
gsub(/!\z/, '_bang') + '_spec.rb'
|
gsub(/!\z/, '_bang') + '_spec.rb'
|
||||||
end
|
end
|
||||||
memoize :spec_file
|
memoize :spec_file
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Mutant::Strategy::Rspec::ExampleLookup, '#spec_file' do
|
||||||
|
|
||||||
|
let(:object) { described_class.new(mutation) }
|
||||||
|
let(:mutation) { mock('Mutation', :subject => mutation_subject) }
|
||||||
|
let(:mutation_subject) { mock('Subject', :matcher => matcher) }
|
||||||
|
let(:matcher) { mock('Matcher', :method_name => method_name) }
|
||||||
|
|
||||||
|
subject { object.send(:spec_file) }
|
||||||
|
|
||||||
|
shared_examples_for 'Mutant::Strategy::Rspec::ExampleLookup#spec_file' do
|
||||||
|
it_should_behave_like 'an idempotent method'
|
||||||
|
|
||||||
|
it { should eql(expected_spec_file) }
|
||||||
|
it { should be_frozen }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with writer method' do
|
||||||
|
let(:method_name) { 'foo=' }
|
||||||
|
let(:expected_spec_file) { 'foo_writer_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with bang method' do
|
||||||
|
let(:method_name) { 'foo!' }
|
||||||
|
let(:expected_spec_file) { 'foo_bang_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with predicate method' do
|
||||||
|
let(:method_name) { 'foo?' }
|
||||||
|
let(:expected_spec_file) { 'foo_predicate_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with regular method' do
|
||||||
|
let(:method_name) { 'foo' }
|
||||||
|
let(:expected_spec_file) { 'foo_spec.rb' }
|
||||||
|
|
||||||
|
it_should_behave_like 'Mutant::Strategy::Rspec::ExampleLookup#spec_file'
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue