Skip to content

Commit

Permalink
Add specs for inherited / block yield order for Class.new
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink authored and brixen committed Jan 23, 2012
1 parent 50398c1 commit e8de564
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/class/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ def self.inherited(subclass)
class B < A; end
class B < A; end # reopen
class C < B; end

class D
def self.inherited(subclass)
ScratchPad << self
end
end
end
end
28 changes: 28 additions & 0 deletions core/class/new_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Class.new with a block given" do
it "uses the given block as the class' body" do
Expand Down Expand Up @@ -38,6 +39,33 @@ def message2; "hello"; end
klass.new.message.should == "text"
klass.new.message2.should == "hello"
end

ruby_version_is ""..."1.9" do

it "runs the inherited hook before yielding the block" do
ScratchPad.record []
klass = Class.new(CoreClassSpecs::Inherited::D) do
ScratchPad << self
end

ScratchPad.recorded.should == [klass, CoreClassSpecs::Inherited::D]
end

end

ruby_version_is "1.9" do

it "runs the inherited hook after yielding the block" do
ScratchPad.record []
klass = Class.new(CoreClassSpecs::Inherited::D) do
ScratchPad << self
end

ScratchPad.recorded.should == [CoreClassSpecs::Inherited::D, klass]
end

end

end

describe "Class.new" do
Expand Down

0 comments on commit e8de564

Please sign in to comment.