Sha256: 150699b3f40793143fa59b16f32eadc81cb99f9b771a0394a8c42baf0361ab04

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require File.join(File.dirname(__FILE__), "/../spec_helper")

describe MonitoredHash do
  
  before do
    @e = Echo.new
    @m = MonitoredHash.new
    @m[4] = 4
    @m.add_observer(@e)
  end
  
  it "should be observable" do
    MonitoredHash.included_modules.should be_include(Observable)
  end
  
  it "should broadcast itself on assign" do
    @m[1] = 2
    @e.latest.should eql(@m)
    @m[1].should eql(2)
  end
  
  it "should broadcast itself on delete" do
    @m.delete(4)
    @e.latest.should eql(@m)
    @m[4].should be_nil
  end
  
  it "should broadcast itself on shift" do
    @m.shift
    @e.latest.should eql(@m)
    @m[4].should be_nil
  end
  
  it "should broadcast itself on reject!" do
    @m.reject! {|k,v| k == 4 }
    @e.latest.should eql(@m)
    @m[4].should be_nil
  end
  
  it "should broadcast itself on clear" do
    @m.clear
    @e.latest.should eql(@m)
    @m[4].should be_nil
  end
  
  it "should broadcast itself on merge!" do
    @m.merge!({2 => 22})
    @e.latest.should eql(@m)
    @m[2].should eql(22)
  end
  
  it "should broadcast itself on replace" do
    @m.replace({2 => 22})
    @e.latest.should eql(@m)
    @m[2].should eql(22)
  end
  
  it "should broadcast itself on store" do
    @m.store(3,3)
    @e.latest.should eql(@m)
    @m[3].should eql(3)
  end
  
  it "should broadcast itself on update" do
    @m.update({3 => 3})
    @e.latest.should eql(@m)
    @m[3].should eql(3)
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
davidrichards-repositories-0.0.3 spec/repositories/monitored_hash_spec.rb
davidrichards-repositories-0.0.4 spec/repositories/monitored_hash_spec.rb
davidrichards-repositories-0.0.5 spec/repositories/monitored_hash_spec.rb
davidrichards-repositories-0.0.6 spec/repositories/monitored_hash_spec.rb