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) }
|
|
|
|
|
2012-12-10 18:17:19 -05:00
|
|
|
def assert_transitive(ast)
|
|
|
|
generated = ToSource.to_source(ast)
|
|
|
|
parsed = generated.to_ast
|
|
|
|
again = ToSource.to_source(parsed)
|
|
|
|
unless generated == again
|
|
|
|
fail "Untransitive:\n%s\n---\n%s" % [generated, again]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-07 17:27:21 -05:00
|
|
|
unless instance_methods.include?(:expected_mutations)
|
|
|
|
let(:expected_mutations) do
|
|
|
|
mutations.map do |mutation|
|
|
|
|
case mutation
|
|
|
|
when String
|
2012-12-10 18:17:19 -05:00
|
|
|
ast = mutation.to_ast
|
|
|
|
assert_transitive(ast)
|
|
|
|
ast
|
2012-12-07 17:27:21 -05:00
|
|
|
when Rubinius::AST::Node
|
2012-12-10 18:17:19 -05:00
|
|
|
assert_transitive(mutation)
|
2012-12-07 17:27:21 -05:00
|
|
|
mutation
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end.map do |node|
|
|
|
|
ToSource.to_source(node)
|
|
|
|
end.to_set
|
|
|
|
end
|
2012-08-01 07:27:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates the expected mutations' do
|
2012-12-29 10:00:27 -05:00
|
|
|
generated = self.subject.map { |mutation| ToSource.to_source(mutation) }.to_set
|
2012-08-01 07:27:35 -04:00
|
|
|
|
2012-12-06 06:32:16 -05:00
|
|
|
missing = (expected_mutations - generated).to_a
|
2012-12-06 13:51:44 -05:00
|
|
|
unexpected = (generated - expected_mutations).to_a
|
2012-12-06 06:32:16 -05:00
|
|
|
|
|
|
|
unless generated == expected_mutations
|
2013-01-09 14:43:06 -05:00
|
|
|
fail "Missing mutations:\n%s\nUnexpected mutations:\n%s" % [missing.join("\n----\n"), unexpected.join("\n----\n")]
|
2012-08-01 07:27:35 -04:00
|
|
|
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
|