Sha256: ae6427dac81083c843ca7135db172459ac04b056f01950f8bed776432d4a1a15

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'

# Class cattr_reader

class ClassWithCAttrReader
  cattr_reader      :bacon
  def initialize;   @@bacon = "chunky";   end
end

describe "Core Class with cattr_reader", :shared => true do

  it "should read value from attribute" do
    @klass.bacon.should == "chunky"
  end

  it "should not write to attribute" do
    lambda {
      @klass.bacon = "soggy"
    }.should raise_error(NoMethodError)
  end

end

describe Class, "with cattr_reader" do

  before do
    @klass = ClassWithCAttrReader.new.class
  end
  it_should_behave_like "Core Class with cattr_reader"

end

describe Class, "with cattr_reader (instantiated)" do

  before do
    @klass = ClassWithCAttrReader.new
  end
  it_should_behave_like "Core Class with cattr_reader"

end

# Class cattr_writer

class ClassWithCAttrWriter
  cattr_writer      :bacon
  def self.chunky?; @@bacon == "chunky";  end
  def chunky?;      self.class.chunky?;   end
end

describe "Core Class with cattr_writer", :shared => true do

  it "should write value to attribute" do
    @klass.should be_chunky
  end

  it "should not read attribute" do
    lambda {
      @klass.bacon
    }.should raise_error(NoMethodError)
  end

end

describe Class, "with cattr_writer" do

  before do
    @klass = ClassWithCAttrWriter.new.class
    @klass.bacon = "chunky"
  end
  it_should_behave_like "Core Class with cattr_writer"

end

describe Class, "with cattr_writer (instantiated)" do

  before do
    @klass = ClassWithCAttrWriter.new
    @klass.bacon = "chunky"
  end
  it_should_behave_like "Core Class with cattr_writer"

end

class ClassWithAttrInitialize
  attr_initialize :dog, :muppet
  attr_accessor   :dog, :muppet
end

describe ClassWithAttrInitialize do

  it "should initialize with values" do
    c = ClassWithAttrInitialize.new("louie", "bert")
    c.dog.should    == "louie"
    c.muppet.should == "bert"
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
merb-0.5.0 spec/merb/core_ext/class_spec.rb
merb-0.5.1 spec/merb/core_ext/class_spec.rb
merb-0.5.2 spec/merb/core_ext/class_spec.rb
merb-0.5.3 spec/merb/core_ext/class_spec.rb