#561 new
Evan Phoenix

Write spec for class var behavior

Reported by Evan Phoenix | May 18th, 2008 @ 07:22 PM | in 1.0 preview

module B
  def blah
    @@blah ||= []
    p @@blah.include?(1)
  end
end

class A
  extend B
end

A.blah

This code creates class variable @@blah on B, not A. Rubinius recently fixed it's handling of this, but a spec needs to be written to document the behavior.

Comments and changes to this ticket

  • Patrick Farley

    Patrick Farley June 9th, 2008 @ 10:45 PM

    Rubinius behavior still seems to be different.

    describe "Module" do

    it "should assign ownership of class variables to the Modules metaclass when class variables are defined as part of method evaluation" do

    declare_class_variable = Module.new do

    def define_class_var

    @@class_var = :value

    end

    end

    access_class_variable = Module.new do

    extend declare_class_variable

    end

    access_class_variable.define_class_var

    declare_class_variable.class_variable_defined?("@@class_var").should == false

    access_class_variable.class_variable_defined?("@@class_var").should == false

    declare_class_variable.instance_eval("class << self; self; end").class_variable_defined?("@@class_var").should == true

    end

    end

    patrick-farleys-computer:~/rubinius/code pfarley$ mspec/bin/mspec -tr spec/core/module/class_variable_spec.rb

    ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.1]

    .

    Finished in 0.005960 seconds

    1 file, 1 example, 3 expectations, 0 failures, 0 errors

    patrick-farleys-computer:~/rubinius/code pfarley$ mspec/bin/mspec spec/core/module/class_variable_spec.rb

    F

    1)

    Module should assign ownership of class variables to the Modules metaclass when class variables are defined as part of method evaluation FAILED

    Expected true

    to equal false

    Expectation.fail_with at /Users/pfarley/rubinius/code/mspec/lib/mspec/expectations/expectations.rb:10

    Finished in 0.047044 seconds

    1 file, 1 example, 1 expectation, 1 failure, 0 errors

  • Patrick Farley
  • Ryan Davis

    Ryan Davis June 23rd, 2008 @ 03:39 PM

    • → Assigned user changed from “” to “Ryan Davis”

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket