free_mutant/spec/unit/mutant/subject_spec.rb

90 lines
1.8 KiB
Ruby
Raw Normal View History

RSpec.describe Mutant::Subject do
let(:class_under_test) do
Class.new(described_class) do
def expression
2014-11-17 21:53:18 +00:00
Mutant::Expression.parse('SubjectA')
end
def match_expressions
[expression] << Mutant::Expression.parse('SubjectB')
end
end
end
let(:object) { class_under_test.new(context, node) }
let(:node) do
2014-10-05 15:04:57 +00:00
Parser::CurrentRuby.parse(<<-RUBY)
def foo
end
RUBY
end
let(:location) do
double('Location', expression: expression)
end
let(:expression) do
double('Expression', line: 'source_line')
end
let(:context) do
double(
'Context',
source_path: 'source_path',
2014-03-08 18:01:17 +00:00
source_line: 'source_line'
)
end
describe '#identification' do
subject { object.identification }
2014-10-05 15:04:57 +00:00
it { should eql('SubjectA:source_path:1') }
end
describe '#source_line' do
subject { object.source_line }
it { should be(1) }
end
describe '#source_lines' do
subject { object.source_lines }
it { should eql(1..2) }
end
2014-07-06 21:05:05 +00:00
describe '#prepare' do
subject { object.prepare }
it_should_behave_like 'a command method'
end
describe '#node' do
subject { object.node }
it { should be(node) }
it_should_behave_like 'an idempotent method'
end
2014-07-05 23:32:07 +00:00
describe '#mutations' do
subject { object.mutations }
before do
expect(Mutant::Mutator).to receive(:each).with(node).and_yield(mutation_a).and_yield(mutation_b)
end
let(:mutation_a) { double('Mutation A') }
let(:mutation_b) { double('Mutation B') }
it 'generates neutral and evil mutations' do
should eql([
Mutant::Mutation::Neutral.new(object, node),
Mutant::Mutation::Evil.new(object, mutation_a),
Mutant::Mutation::Evil.new(object, mutation_b)
])
end
end
end