Sha256: d528e6a52803a1fe7ce1c7e595c08f5b06740e1fba62769ce8f484130a3f1e51

Contents?: true

Size: 1.21 KB

Versions: 52

Compression:

Stored size: 1.21 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

describe "Class#new" do
  it "returns a new instance of self" do
    klass = Class.new
    klass.new.is_a?(klass).should == true
  end

  it "invokes #initialize on the new instance with the given args" do
    klass = Class.new do
      def initialize(*args)
        @initialized = true
        @args = args
      end

      def args
        @args
      end

      def initialized?
        @initialized || false
      end
    end

    klass.new.initialized?.should == true
    klass.new(1, 2, 3).args.should == [1, 2, 3]
  end

  it "passes the block to #initialize" do
    klass = Class.new do
      def initialize
        yield
      end
    end

    klass.new { break 42 }.should == 42
  end
end

describe "Class#initialize" do
  it "raises a TypeError when called on already initialized classes" do
    lambda{
      Fixnum.send :initialize
    }.should raise_error(TypeError)

    lambda{
      Object.send :initialize
    }.should raise_error(TypeError)
  end

  ruby_version_is "1.9" do
    # See [redmine:2601]
    it "raises a TypeError when called on BasicObject" do
      lambda{
        BasicObject.send :initialize
      }.should raise_error(TypeError)
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/class/initialize_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/class/initialize_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/class/initialize_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/class/initialize_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/class/initialize_spec.rb