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'
if "".respond_to?(:to_ast)
class CodeLoadingSubject
def x
true
end
end
describe Mutant, 'code loading' do
let(:context) { Mutant::Context::Constant.build(CodeLoadingSubject) }
let(:node) { 'def foo; :bar; end'.to_ast }
let(:root) { context.root(node) }
subject { Mutant::Loader.load(root) }
before { subject }
it 'should add the method to subject' do
CodeLoadingSubject.new.foo.should be(:bar)
end
class CodeLoadingSubject
def x
true
end
end
describe Mutant, 'code loading' do
let(:context) { Mutant::Context::Constant.build(CodeLoadingSubject) }
let(:node) { 'def foo; :bar; end'.to_ast }
let(:root) { context.root(node) }
subject { Mutant::Loader.load(root) }
before { subject }
it 'should add the method to subject' do
CodeLoadingSubject.new.foo.should be(:bar)
end
end

View file

@ -1,171 +1,192 @@
require 'spec_helper'
if "".respond_to?(:to_ast)
describe Mutant, 'method matching' do
after do
if defined?(::Foo)
Object.send(:remove_const, 'Foo')
end
describe Mutant, 'method matching' do
after do
if defined?(::Foo)
Object.send(:remove_const, 'Foo')
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
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
}
context 'when method is defined once' do
let(:body) do
<<-RUBY
class Foo
def bar; end
end
RUBY
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
<<-RUBY
class Foo
def bar; end
def bar(arg); end
end
RUBY
end
let(:expectation) do
{ :method_line => 2 }
{
:method_line => 3,
:method_arity => 1
}
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
<<-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
context 'on the same line' do
let(:body) do
<<-RUBY
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
RUBY
end
@ -181,73 +202,50 @@ if "".respond_to?(:to_ast)
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
RUBY
end
let(:expectation) do
{
:method_name => :bar,
:method_line => 2,
}
end
it_should_behave_like 'a method match'
context 'outside namespace' do
let(:body) do
<<-RUBY
class Foo; end;
def Foo.bar; end
RUBY
end
context 'outside namespace' do
let(:body) do
<<-RUBY
class Foo; end;
def Foo.bar; end
RUBY
end
let(:expectation) do
{
:method_name => :bar,
:method_line => 2,
}
end
it_should_behave_like 'a method match'
let(:expectation) do
{
:method_name => :bar,
:method_line => 2,
}
end
it_should_behave_like 'a method match'
end
end
context 'when defined multiple times in the same line' do
context 'with method on differend scope' do
let(:body) do
<<-RUBY
module Foo; end
context 'when defined multiple times in the same line' do
context 'with method on differend scope' do
let(:body) do
<<-RUBY
module Foo; end
module Bar
def self.baz; end; def Foo.baz(arg); end
end
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'
module Bar
def self.baz; end; def Foo.baz(arg); end
end
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
end

View file

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