From a0933916ca76b0406a6d42ca03a5a52908ae6bc2 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 14 Jan 2013 12:54:53 +0100 Subject: [PATCH] Simplify method matching integration spec Should be converted to a unit spec soon --- .../mutant/method_matching_spec.rb | 62 ++++++++++++++++--- spec/shared/method_match_behavior.rb | 39 ------------ 2 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 spec/shared/method_match_behavior.rb diff --git a/spec/integration/mutant/method_matching_spec.rb b/spec/integration/mutant/method_matching_spec.rb index 77e07946..3e219a19 100644 --- a/spec/integration/mutant/method_matching_spec.rb +++ b/spec/integration/mutant/method_matching_spec.rb @@ -7,6 +7,48 @@ describe Mutant, 'method matching' do end end + this_example = 'Mutant method matching' + + shared_examples_for this_example do + subject { p 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 + before do #eval(body, TOPLEVEL_BINDING, __FILE__, 0) eval(body) @@ -47,7 +89,7 @@ describe Mutant, 'method matching' do { :method_line => 2 } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'when method is defined multiple times' do @@ -68,7 +110,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'on the same line' do @@ -87,7 +129,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'on the same line with differend scope' do @@ -106,7 +148,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'when nested' do @@ -131,7 +173,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'in module' do @@ -153,7 +195,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end end end @@ -194,7 +236,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'when defined on constant' do @@ -216,7 +258,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end context 'outside namespace' do @@ -235,7 +277,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end end @@ -262,7 +304,7 @@ describe Mutant, 'method matching' do } end - it_should_behave_like 'a method match' + it_should_behave_like this_example end end end diff --git a/spec/shared/method_match_behavior.rb b/spec/shared/method_match_behavior.rb deleted file mode 100644 index 7257e7ac..00000000 --- a/spec/shared/method_match_behavior.rb +++ /dev/null @@ -1,39 +0,0 @@ -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