Skip to content

Commit

Permalink
Test class Class < superclass syntax aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
davispuh authored and eregon committed Oct 9, 2020
1 parent 04716a5 commit af24519
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/class/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ def message2; "hello"; end

it "raises a TypeError when given a non-Class" do
error_msg = /superclass must be a Class/
-> { Class.new("") }.should raise_error(TypeError, error_msg)
-> { Class.new(1) }.should raise_error(TypeError, error_msg)
-> { Class.new(:symbol) }.should raise_error(TypeError, error_msg)
-> { Class.new(mock('o')) }.should raise_error(TypeError, error_msg)
-> { Class.new(Module.new) }.should raise_error(TypeError, error_msg)
-> { Class.new("") }.should raise_error(TypeError, error_msg)
-> { Class.new(1) }.should raise_error(TypeError, error_msg)
-> { Class.new(:symbol) }.should raise_error(TypeError, error_msg)
-> { Class.new(mock('o')) }.should raise_error(TypeError, error_msg)
-> { Class.new(Module.new) }.should raise_error(TypeError, error_msg)
-> { Class.new(BasicObject.new) }.should raise_error(TypeError, error_msg)
end
end

Expand Down
10 changes: 10 additions & 0 deletions language/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ def xyz
}.should raise_error(TypeError)
end

it "raises a TypeError when trying to extend non-Class" do
error_msg = /superclass must be a Class/
-> { class TestClass < ""; end }.should raise_error(TypeError, error_msg)
-> { class TestClass < 1; end }.should raise_error(TypeError, error_msg)
-> { class TestClass < :symbol; end }.should raise_error(TypeError, error_msg)
-> { class TestClass < mock('o'); end }.should raise_error(TypeError, error_msg)
-> { class TestClass < Module.new; end }.should raise_error(TypeError, error_msg)
-> { class TestClass < BasicObject.new; end }.should raise_error(TypeError, error_msg)
end

ruby_version_is ""..."3.0" do
it "allows accessing the block of the original scope" do
suppress_warning do
Expand Down

0 comments on commit af24519

Please sign in to comment.