Sha256: 14d32ff26818dd108acb844d9e5c43a8c9ce636349247d249c6f66fca31c3a3d
Contents?: true
Size: 1.8 KB
Versions: 6
Compression:
Stored size: 1.8 KB
Contents
require 'spec_helper' describe Metrics::Instruments::Counter do before(:each) do @counter = Metrics::Instruments::Counter.new end it "should create a new entity with zero as its value" do @counter.to_i.should == 0 end it "should increment its counter by the value specified" do value = 1 lambda do @counter.inc(value) end.should change{ @counter.to_i }.by(value) end it "should increment its counter by one by default" do lambda do @counter.inc end.should change{ @counter.to_i }.by(1) end it "should decrement its counter by the value specified" do value = 1 lambda do @counter.dec(value) end.should change{ @counter.to_i }.by(-value) end it "should decrement its counter by one by default" do lambda do @counter.dec end.should change{ @counter.to_i }.by(-1) end it "should alias #incr to #inc" do lambda do @counter.incr end.should change{ @counter.to_i }.by(1) end it "should alias #decr to #dec" do lambda do @counter.decr end.should change{ @counter.to_i }.by(-1) end it "should clear the counter correctly" do @counter.clear @counter.to_i.should == 0 end it "should correctly represent the value as a string" do @counter.clear @counter.to_i.should == 0 @counter.to_s.should == "0" end it "should return the new count when incrementing" do count = @counter.to_i @counter.inc(value = 1).should == count + value end it "should return the new count when decrementing" do lambda do @counter.dec(1) end.should change{ @counter.to_i }.by(-1) end context "to_json" do let(:json) { @counter.to_json } it "should serialize to its current value" do json.should == @counter.to_s end end end
Version data entries
6 entries across 6 versions & 2 rubygems