Remove legacy guards for non rbx environment in specs

This commit is contained in:
Markus Schirp 2012-08-10 20:23:39 +02:00
parent 9755009966
commit e238890f2c
3 changed files with 232 additions and 238 deletions

View file

@ -1,23 +1,21 @@
require 'spec_helper' require 'spec_helper'
if "".respond_to?(:to_ast) class CodeLoadingSubject
class CodeLoadingSubject def x
def x true
true end
end end
end
describe Mutant, 'code loading' do
describe Mutant, 'code loading' do let(:context) { Mutant::Context::Constant.build(CodeLoadingSubject) }
let(:context) { Mutant::Context::Constant.build(CodeLoadingSubject) } let(:node) { 'def foo; :bar; end'.to_ast }
let(:node) { 'def foo; :bar; end'.to_ast } let(:root) { context.root(node) }
let(:root) { context.root(node) }
subject { Mutant::Loader.load(root) }
subject { Mutant::Loader.load(root) }
before { subject }
before { subject }
it 'should add the method to subject' do
it 'should add the method to subject' do CodeLoadingSubject.new.foo.should be(:bar)
CodeLoadingSubject.new.foo.should be(:bar)
end
end end
end end

View file

@ -1,171 +1,192 @@
require 'spec_helper' require 'spec_helper'
if "".respond_to?(:to_ast) describe Mutant, 'method matching' do
describe Mutant, 'method matching' do after do
after do if defined?(::Foo)
if defined?(::Foo) Object.send(:remove_const, 'Foo')
Object.send(:remove_const, 'Foo') end
end end
before do
eval(body)
File.stub(:read => body)
end
let(:defaults) { {} }
context 'on instance methods' do
let(:pattern) { 'Foo#bar' }
let(:defaults) do
{
:constant => Foo,
:node_class => Rubinius::AST::Define,
:method_name => :bar,
:method_arity => 0
}
end end
before do context 'when method is defined once' do
eval(body) let(:body) do
File.stub(:read => body) <<-RUBY
end class Foo
def bar; end
let(:defaults) { {} } end
RUBY
context 'on instance methods' do
let(:pattern) { 'Foo#bar' }
let(:defaults) do
{
:constant => Foo,
:node_class => Rubinius::AST::Define,
:method_name => :bar,
:method_arity => 0
}
end end
context 'when method is defined once' do let(:expectation) do
{ :method_line => 2 }
end
it_should_behave_like 'a method match'
end
context 'when method is defined multiple times' do
context 'on differend lines' do
let(:body) do let(:body) do
<<-RUBY <<-RUBY
class Foo class Foo
def bar; end def bar; end
def bar(arg); end
end end
RUBY RUBY
end end
let(:expectation) do let(:expectation) do
{ :method_line => 2 } {
:method_line => 3,
:method_arity => 1
}
end end
it_should_behave_like 'a method match' it_should_behave_like 'a method match'
end end
context 'when method is defined multiple times' do context 'on the same line' do
context 'on differend lines' do
let(:body) do
<<-RUBY
class Foo
def bar; end
def bar(arg); end
end
RUBY
end
let(:expectation) do
{
:method_line => 3,
:method_arity => 1
}
end
it_should_behave_like 'a method match'
end
context 'on the same line' do
let(:body) do
<<-RUBY
class Foo
def bar; end; def bar(arg); end
end
RUBY
end
let(:expectation) do
{
:method_line => 2,
:method_arity => 1
}
end
it_should_behave_like 'a method match'
end
context 'on the same line with differend scope' do
let(:body) do
<<-RUBY
class Foo
def self.bar; end; def bar(arg); end
end
RUBY
end
let(:expectation) do
{
:method_line => 2,
:method_arity => 1
}
end
it_should_behave_like 'a method match'
end
context 'when nested' do
let(:pattern) { 'Foo::Bar#baz' }
context 'in class' do
let(:body) do
<<-RUBY
class Foo
class Bar
def baz; end
end
end
RUBY
end
let(:expectation) do
{
:method_line => 3,
:method_name => :baz,
:constant => Foo::Bar
}
end
it_should_behave_like 'a method match'
end
context 'in module' do
let(:body) do
<<-RUBY
module Foo
class Bar
def baz; end
end
end
RUBY
end
let(:expectation) do
{
:method_line => 3,
:method_name => :baz,
:constant => Foo::Bar
}
end
it_should_behave_like 'a method match'
end
end
end
end
context 'on singleton methods' do
let(:pattern) { 'Foo.bar' }
let(:defaults) do
{
:constant => Foo,
:node_class => Rubinius::AST::DefineSingletonScope,
:method_arity => 0
}
end
context 'when defined on self' do
let(:body) do let(:body) do
<<-RUBY <<-RUBY
class Foo class Foo
def self.bar; end def bar; end; def bar(arg); end
end
RUBY
end
let(:expectation) do
{
:method_line => 2,
:method_arity => 1
}
end
it_should_behave_like 'a method match'
end
context 'on the same line with differend scope' do
let(:body) do
<<-RUBY
class Foo
def self.bar; end; def bar(arg); end
end
RUBY
end
let(:expectation) do
{
:method_line => 2,
:method_arity => 1
}
end
it_should_behave_like 'a method match'
end
context 'when nested' do
let(:pattern) { 'Foo::Bar#baz' }
context 'in class' do
let(:body) do
<<-RUBY
class Foo
class Bar
def baz; end
end
end
RUBY
end
let(:expectation) do
{
:method_line => 3,
:method_name => :baz,
:constant => Foo::Bar
}
end
it_should_behave_like 'a method match'
end
context 'in module' do
let(:body) do
<<-RUBY
module Foo
class Bar
def baz; end
end
end
RUBY
end
let(:expectation) do
{
:method_line => 3,
:method_name => :baz,
:constant => Foo::Bar
}
end
it_should_behave_like 'a method match'
end
end
end
end
context 'on singleton methods' do
let(:pattern) { 'Foo.bar' }
let(:defaults) do
{
:constant => Foo,
:node_class => Rubinius::AST::DefineSingletonScope,
:method_arity => 0
}
end
context 'when defined on self' do
let(:body) do
<<-RUBY
class Foo
def self.bar; end
end
RUBY
end
let(:expectation) do
{
:method_name => :bar,
:method_line => 2,
}
end
it_should_behave_like 'a method match'
end
context 'when defined on constant' do
context 'inside namespace' do
let(:body) do
<<-RUBY
class Foo
def Foo.bar; end
end end
RUBY RUBY
end end
@ -181,73 +202,50 @@ if "".respond_to?(:to_ast)
it_should_behave_like 'a method match' it_should_behave_like 'a method match'
end end
context 'when defined on constant' do context 'outside namespace' do
let(:body) do
context 'inside namespace' do <<-RUBY
let(:body) do class Foo; end;
<<-RUBY def Foo.bar; end
class Foo RUBY
def Foo.bar; end
end
RUBY
end
let(:expectation) do
{
:method_name => :bar,
:method_line => 2,
}
end
it_should_behave_like 'a method match'
end end
context 'outside namespace' do
let(:body) do
<<-RUBY
class Foo; end;
def Foo.bar; end
RUBY
end
let(:expectation) do
let(:expectation) do {
{ :method_name => :bar,
:method_name => :bar, :method_line => 2,
:method_line => 2, }
}
end
it_should_behave_like 'a method match'
end end
it_should_behave_like 'a method match'
end end
end
context 'when defined multiple times in the same line' do context 'when defined multiple times in the same line' do
context 'with method on differend scope' do context 'with method on differend scope' do
let(:body) do let(:body) do
<<-RUBY <<-RUBY
module Foo; end module Foo; end
module Bar module Bar
def self.baz; end; def Foo.baz(arg); end def self.baz; end; def Foo.baz(arg); end
end end
RUBY RUBY
end
let(:pattern) { 'Bar.baz' }
let(:expectation) do
{
:constant => Bar,
:method_name => :baz,
:method_line => 4,
:method_arity => 0
}
end
it_should_behave_like 'a method match'
end end
let(:pattern) { 'Bar.baz' }
let(:expectation) do
{
:constant => Bar,
:method_name => :baz,
:method_line => 4,
:method_arity => 0
}
end
it_should_behave_like 'a method match'
end end
end end
end end

View file

@ -1,24 +1,22 @@
require 'spec_helper' require 'spec_helper'
if "".respond_to?(:to_ast) describe Mutant::Context::Constant, '#root' do
describe Mutant::Context::Constant, '#root' do subject { object.root(node) }
subject { object.root(node) }
let(:object) { described_class.build(SampleSubjects::ExampleModule) } let(:object) { described_class.build(SampleSubjects::ExampleModule) }
let(:node) { mock('Node') } let(:node) { mock('Node') }
let(:constant) { subject.body } let(:constant) { subject.body }
let(:scope) { constant.body } let(:scope) { constant.body }
let(:scope_body) { scope.body } let(:scope_body) { scope.body }
it { should be_a(Rubinius::AST::Script) } it { should be_a(Rubinius::AST::Script) }
it 'should wrap the ast under constant' do it 'should wrap the ast under constant' do
scope.should be_kind_of(Rubinius::AST::ModuleScope) scope.should be_kind_of(Rubinius::AST::ModuleScope)
end end
it 'should place the ast under scope' do it 'should place the ast under scope' do
scope_body.should be(node) scope_body.should be(node)
end
end end
end end