2012-08-01 08:58:24 -04:00
|
|
|
shared_examples_for 'a mutator' do
|
2012-08-01 07:27:35 -04:00
|
|
|
subject { object.each(node) { |item| yields << item } }
|
|
|
|
|
|
|
|
let(:yields) { [] }
|
|
|
|
let(:object) { described_class }
|
2012-08-13 14:40:00 -04:00
|
|
|
|
|
|
|
unless instance_methods.map(&:to_s).include?('node')
|
|
|
|
let(:node) { source.to_ast }
|
|
|
|
end
|
2012-08-01 07:27:35 -04:00
|
|
|
|
|
|
|
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
|
2012-12-06 06:32:16 -05:00
|
|
|
generated = self.subject.map(&:to_sexp).to_set
|
2012-08-01 07:27:35 -04:00
|
|
|
|
2012-12-06 06:32:16 -05:00
|
|
|
missing = (expected_mutations - generated).to_a
|
|
|
|
unexpected = (generated - generated).to_a
|
|
|
|
|
|
|
|
unless generated == expected_mutations
|
|
|
|
message = "Missing mutations: %s\nUnexpected mutations: %s" % [missing, unexpected].map(&:inspect)
|
2012-08-01 07:27:35 -04:00
|
|
|
fail message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-08-01 08:58:24 -04:00
|
|
|
shared_examples_for 'a noop mutator' do
|
2012-08-01 07:53:28 -04:00
|
|
|
let(:mutations) { [] }
|
2012-08-01 07:27:35 -04:00
|
|
|
|
2012-08-01 08:58:24 -04:00
|
|
|
it_should_behave_like 'a mutator'
|
2012-08-01 07:53:28 -04:00
|
|
|
end
|