Add command method to test app
This commit is contained in:
parent
297e313b41
commit
c215c9d668
10 changed files with 167 additions and 0 deletions
|
@ -5,6 +5,10 @@ module TestApp
|
|||
true
|
||||
end
|
||||
|
||||
def command(foo)
|
||||
self
|
||||
end
|
||||
|
||||
def string
|
||||
'string'
|
||||
end
|
||||
|
|
7
test_app/spec/shared/command_method_behavior.rb
Normal file
7
test_app/spec/shared/command_method_behavior.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
shared_examples_for 'a command method' do
|
||||
it 'returns self' do
|
||||
should equal(object)
|
||||
end
|
||||
end
|
15
test_app/spec/shared/each_method_behaviour.rb
Normal file
15
test_app/spec/shared/each_method_behaviour.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# encoding: utf-8
|
||||
|
||||
shared_examples_for 'an #each method' do
|
||||
it_should_behave_like 'a command method'
|
||||
|
||||
context 'with no block' do
|
||||
subject { object.each }
|
||||
|
||||
it { should be_instance_of(to_enum.class) }
|
||||
|
||||
it 'yields the expected values' do
|
||||
subject.to_a.should eql(object.to_a)
|
||||
end
|
||||
end
|
||||
end
|
17
test_app/spec/shared/hash_method_behavior.rb
Normal file
17
test_app/spec/shared/hash_method_behavior.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# encoding: utf-8
|
||||
|
||||
shared_examples_for 'a hash method' do
|
||||
it_should_behave_like 'an idempotent method'
|
||||
|
||||
specification = proc do
|
||||
should be_instance_of(Fixnum)
|
||||
end
|
||||
|
||||
it 'is a fixnum' do
|
||||
instance_eval(&specification)
|
||||
end
|
||||
|
||||
it 'memoizes the hash code' do
|
||||
subject.should eql(object.memoized(:hash))
|
||||
end
|
||||
end
|
7
test_app/spec/shared/idempotent_method_behavior.rb
Normal file
7
test_app/spec/shared/idempotent_method_behavior.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
shared_examples_for 'an idempotent method' do
|
||||
it 'is idempotent' do
|
||||
should equal(instance_eval(&self.class.subject))
|
||||
end
|
||||
end
|
9
test_app/spec/shared/invertible_method_behaviour.rb
Normal file
9
test_app/spec/shared/invertible_method_behaviour.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
# encoding: utf-8
|
||||
|
||||
shared_examples_for 'an invertible method' do
|
||||
it_should_behave_like 'an idempotent method'
|
||||
|
||||
it 'is invertible' do
|
||||
subject.inverse.should equal(object)
|
||||
end
|
||||
end
|
16
test_app/spec/shared/method_filter_parse_behavior.rb
Normal file
16
test_app/spec/shared/method_filter_parse_behavior.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
shared_examples_for 'a method filter parse result' do
|
||||
before do
|
||||
expected_class.stub(:new => response)
|
||||
end
|
||||
|
||||
let(:response) { mock('Response') }
|
||||
|
||||
it { should be(response) }
|
||||
|
||||
it 'should initialize method filter with correct arguments' do
|
||||
expected_class.should_receive(:new).with(TestApp::Literal, :string).and_return(response)
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
|
39
test_app/spec/shared/method_match_behavior.rb
Normal file
39
test_app/spec/shared/method_match_behavior.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
shared_examples_for 'a method match' do
|
||||
subject { Mutant::Matcher::Method.parse(pattern).to_a }
|
||||
|
||||
let(:values) { defaults.merge(expectation) }
|
||||
|
||||
let(:method_name) { values.fetch(:method_name) }
|
||||
let(:method_line) { values.fetch(:method_line) }
|
||||
let(:method_arity) { values.fetch(:method_arity) }
|
||||
let(:scope) { values.fetch(:scope) }
|
||||
let(:node_class) { values.fetch(:node_class) }
|
||||
|
||||
let(:node) { mutation_subject.node }
|
||||
let(:context) { mutation_subject.context }
|
||||
let(:mutation_subject) { subject.first }
|
||||
|
||||
it 'should return one subject' do
|
||||
subject.size.should be(1)
|
||||
end
|
||||
|
||||
it 'should have correct method name' do
|
||||
name(node).should eql(method_name)
|
||||
end
|
||||
|
||||
it 'should have correct line number' do
|
||||
node.line.should eql(method_line)
|
||||
end
|
||||
|
||||
it 'should have correct arity' do
|
||||
arguments(node).required.length.should eql(method_arity)
|
||||
end
|
||||
|
||||
it 'should have correct scope in context' do
|
||||
context.send(:scope).should eql(scope)
|
||||
end
|
||||
|
||||
it 'should have the correct node class' do
|
||||
node.should be_a(node_class)
|
||||
end
|
||||
end
|
44
test_app/spec/shared/mutator_behavior.rb
Normal file
44
test_app/spec/shared/mutator_behavior.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
shared_examples_for 'a mutator' do
|
||||
subject { object.each(node) { |item| yields << item } }
|
||||
|
||||
let(:yields) { [] }
|
||||
let(:object) { described_class }
|
||||
|
||||
unless instance_methods.map(&:to_s).include?('node')
|
||||
let(:node) { source.to_ast }
|
||||
end
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
|
||||
context 'with no block' do
|
||||
subject { object.each(node) }
|
||||
|
||||
it { should be_instance_of(to_enum.class) }
|
||||
|
||||
let(:expected_mutations) do
|
||||
mutations.map do |mutation|
|
||||
if mutation.respond_to?(:to_ast)
|
||||
mutation.to_ast.to_sexp
|
||||
else
|
||||
mutation
|
||||
end
|
||||
end.to_set
|
||||
end
|
||||
|
||||
it 'generates the expected mutations' do
|
||||
subject = self.subject.map(&:to_sexp).to_set
|
||||
|
||||
unless subject == expected_mutations
|
||||
message = "Missing mutations: %s\nUnexpected mutations: %s" %
|
||||
[expected_mutations - subject, subject - expected_mutations ].map(&:to_a).map(&:inspect)
|
||||
fail message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for 'a noop mutator' do
|
||||
let(:mutations) { [] }
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
9
test_app/spec/unit/test_app/literal/command_spec.rb
Normal file
9
test_app/spec/unit/test_app/literal/command_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TestApp::Literal,'#string' do
|
||||
subject { object.command(mock) }
|
||||
|
||||
let(:object) { described_class.new }
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
end
|
Loading…
Reference in a new issue