Skip to content
Browse files

Refactored class and eigenclass specs to use the variable helper and …

…include_variable matcher.

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1364 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent bde5930 commit 97b20b32322e2aa7959d51ca6f12efc770fb5392 @alloy alloy committed Apr 5, 2009
Showing with 27 additions and 68 deletions.
  1. +23 −55 spec/frozen/language/class_spec.rb
  2. +4 −13 spec/frozen/language/eigenclass_spec.rb
View
78 spec/frozen/language/class_spec.rb
@@ -12,7 +12,7 @@ module ClassSpecs
ClassSpecs::A.class.should == Class
ClassSpecs::A.new.class.should == ClassSpecs::A
end
-
+
it "has no class variables" do
ClassSpecs::A.class_variables.should == []
end
@@ -45,93 +45,66 @@ class ClassSpecsNumber::MyClass
end
}.should raise_error(TypeError)
end
-
+
it "allows using self as the superclass if self is a class" do
ClassSpecs::I::J.superclass.should == ClassSpecs::I
-
+
lambda {
class ShouldNotWork < self; end
}.should raise_error(TypeError)
end
-
+
# # I do not think this is a valid spec -- rue
# it "has no class-level instance variables" do
# ClassSpecs::A.instance_variables.should == []
# end
it "allows the declaration of class variables in the body" do
- ruby_version_is "" ... "1.9" do
- ClassSpecs::B.class_variables.should == ["@@cvar"]
- end
- ruby_version_is "1.9" do
- ClassSpecs::B.class_variables.should == [:@@cvar]
- end
+ ClassSpecs::B.class_variables.should == variable("@@cvar")
ClassSpecs::B.send(:class_variable_get, :@@cvar).should == :cvar
end
-
+
it "stores instance variables defined in the class body in the class object" do
- ruby_version_is "" ... "1.9" do
- ClassSpecs::B.instance_variables.include?("@ivar").should == true
- end
- ruby_version_is "1.9" do
- ClassSpecs::B.instance_variables.include?(:@ivar).should == true
- end
+ ClassSpecs::B.instance_variables.should include_variable("@ivar")
ClassSpecs::B.instance_variable_get(:@ivar).should == :ivar
end
it "allows the declaration of class variables in a class method" do
ClassSpecs::C.class_variables.should == []
ClassSpecs::C.make_class_variable
- ruby_version_is "" ... "1.9" do
- ClassSpecs::C.class_variables.should == ["@@cvar"]
- end
- ruby_version_is "1.9" do
- ClassSpecs::C.class_variables.should == [:@@cvar]
- end
+ ClassSpecs::C.class_variables.should == variable("@@cvar")
end
it "allows the definition of class-level instance variables in a class method" do
- ruby_version_is "" ... "1.9" do
- ClassSpecs::C.instance_variables.include?("@civ").should == false
- ClassSpecs::C.make_class_instance_variable
- ClassSpecs::C.instance_variables.include?("@civ").should == true
- end
- ruby_version_is "1.9" do
- ClassSpecs::C.instance_variables.include?(:@civ).should == false
- ClassSpecs::C.make_class_instance_variable
- ClassSpecs::C.instance_variables.include?(:@civ).should == true
- end
+ ClassSpecs::C.instance_variables.should_not include_variable("@civ")
+ ClassSpecs::C.make_class_instance_variable
+ ClassSpecs::C.instance_variables.should include_variable("@civ")
end
-
+
it "allows the declaration of class variables in an instance method" do
ClassSpecs::D.class_variables.should == []
ClassSpecs::D.new.make_class_variable
- ruby_version_is "" ... "1.9" do
- ClassSpecs::D.class_variables.should == ["@@cvar"]
- end
- ruby_version_is "1.9" do
- ClassSpecs::D.class_variables.should == [:@@cvar]
- end
+ ClassSpecs::D.class_variables.should == variable("@@cvar")
end
-
+
it "allows the definition of instance methods" do
ClassSpecs::E.new.meth.should == :meth
end
-
+
it "allows the definition of class methods" do
ClassSpecs::E.cmeth.should == :cmeth
end
-
+
it "allows the definition of class methods using class << self" do
ClassSpecs::E.smeth.should == :smeth
end
-
+
it "allows the definition of Constants" do
Object.const_defined?('CONSTANT').should == false
ClassSpecs::E.const_defined?('CONSTANT').should == true
ClassSpecs::E::CONSTANT.should == :constant!
end
-
+
it "returns the value of the last statement in the body" do
class ClassSpecs::Empty; end.should == nil
class ClassSpecs::Twenty; 20; end.should == 20
@@ -142,20 +115,15 @@ class ClassSpecs::Singleton; class << self; :singleton; end; end.should == :sing
describe "An outer class definition" do
it "contains the inner classes" do
- ruby_version_is "" ... "1.9" do
- ClassSpecs::Container.constants.should include('A', 'B')
- end
- ruby_version_is "1.9" do
- ClassSpecs::Container.constants.should include(:A, :B)
- end
+ ClassSpecs::Container.constants.should include_variables('A', 'B')
end
end
describe "A Class Definitions extending an object" do
it "allows adding methods" do
ClassSpecs::O.smeth.should == :smeth
end
-
+
it "raises a TypeError when trying to extend numbers" do
lambda {
eval <<-CODE
@@ -175,11 +143,11 @@ def xyz
c.meth.should == :meth
c.another.should == :another
end
-
+
it "overwrites existing methods" do
ClassSpecs::G.new.override.should == :override
end
-
+
it "raises a TypeError when superclasses mismatch" do
lambda { class ClassSpecs::A < Array; end }.should raise_error(TypeError)
end
@@ -192,7 +160,7 @@ def self.m
end
end
ClassSpecs::M.m.should == 1
- end
+ end
end
describe "class provides hooks" do
View
17 spec/frozen/language/eigenclass_spec.rb
@@ -148,22 +148,13 @@ class << @object
end.should raise_error(NameError)
end
- ruby_version_is "" ... "1.9" do
- it "appears in the eigenclass constant list" do
- constants = class << @object; constants; end
- constants.should include("CONST")
- end
- end
-
- ruby_version_is "1.9" do
- it "appears in the eigenclass constant list" do
- constants = class << @object; constants; end
- constants.should include(:CONST)
- end
+ it "appears in the eigenclass constant list" do
+ constants = class << @object; constants; end
+ constants.should include_variable('CONST')
end
it "does not appear in the object's class constant list" do
- @object.class.constants.should_not include(:CONST)
+ @object.class.constants.should_not include_variable('CONST')
end
it "is not preserved when the object is duped" do

0 comments on commit 97b20b3

Please sign in to comment.
Something went wrong with that request. Please try again.