Sha256: 721bdf78aa1d9fb363285ad6386207690217d96d53c6863b4019fd5fc01379c4

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

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

class String
  def self.define_meta(meth, val)
    meta_def(meth) { val }
  end
end
class MyString < String; end

describe "An object" do
  it "should be able to return a passed in object that is modified by a block" do
    (returning({}) {|x| x.merge!(:foo => :bar)}).should == {:foo => :bar}
  end
  
  it "should be able to get a meta class" do
    MyString.meta_class.to_s.should == "#<Class:MyString>"
  end
  
  it "should be able to execute code in the meta-class' context" do
    (MyString.meta_eval { self }).should == MyString.meta_class
  end
  
  it "should be able to define a method on the meta-class" do
    MyString.define_meta :foo, :bar
    MyString.foo.should == :bar
  end
  
  it "should be able to define methods on its instances" do
    MyString.class_def(:foo) { :bar }
    MyString.new.foo.should == :bar
  end
  
  {[] => true,
   [1] => false,
   [nil] => false,
   nil => true,
   true => false,
   false => true,
   "" => true,
   "   " => true,
   "  hey " => false
  }.each do |obj, expected|
    it "should be able to determine whether the #{obj.class} #{obj.inspect} is blank" do
      obj.blank?.should == expected
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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