Skip to content

Commit

Permalink
Add spec for when a class is redefined in a block
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish authored and eregon committed Jan 10, 2022
1 parent 715ebec commit 9e1c3d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fixtures/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def self.get_class_name
end
end
end

DEFINE_CLASS = -> do
class ::A; end
end
end

class Class
Expand Down
13 changes: 13 additions & 0 deletions language/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ class ClassSpecsKeywordWithSemicolon; end
eval "class ClassSpecsKeywordWithoutSemicolon end"
ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
end

it "can redefine a class when called from a block" do
ClassSpecs::DEFINE_CLASS.call
A.should be_an_instance_of(Class)

Object.send(:remove_const, :A)
defined?(A).should be_nil

ClassSpecs::DEFINE_CLASS.call
A.should be_an_instance_of(Class)
ensure
Object.send(:remove_const, :A) if defined?(::A)
end
end

describe "A class definition" do
Expand Down

0 comments on commit 9e1c3d3

Please sign in to comment.