spec/lib/fozzie/interface_spec.rb in fozzie-0.0.16 vs spec/lib/fozzie/interface_spec.rb in fozzie-0.0.17
- old
+ new
@@ -9,30 +9,55 @@
Fozzie.c.namespaces.each do |k|
Kernel.const_get(k).should eq Fozzie::Interface.instance
end
end
+ it "downcases any stat value" do
+ subject.expects(:send_to_socket)
+ .with {|bin| bin.match /\.foo/ }
+
+ subject.increment("FOO")
+ end
+
+ it "replaces invalid stat value chars" do
+ subject.expects(:send_to_socket)
+ .with {|bin| bin.match /\.foo_/ }
+ .times(4)
+
+ subject.increment("FOO:")
+ subject.increment("FOO@")
+ subject.increment("FOO|")
+ subject.increment(["FOO|"])
+ end
+
+ it "converts any values to strings for stat value, ignoring nil" do
+ subject.expects(:send_to_socket)
+ .with {|bin| bin.match /\.foo.1._.bar/ }
+
+ subject.increment([:foo, 1, nil, "@", "BAR"])
+ end
+
it "times a given block" do
subject.expects(:timing).with() {|b, val, timing| b == 'data.bin' && (1000..1200).include?(val) }.twice
subject.time_for('data.bin') { sleep 1 }
subject.time_to_do('data.bin') { sleep 1 }
end
it "registers a commit" do
- subject.expects(:timing).with('event.commit', anything).twice
+ subject.expects(:timing).with(['event', 'commit', nil], anything).twice
subject.commit
subject.committed
end
it "registers a build" do
- subject.expects(:timing).with('event.build', anything).twice
+ subject.expects(:timing).with(['event', 'build', nil], anything).twice
subject.build
subject.built
end
it "registers a deploy" do
- subject.expects(:timing).with('event.deploy', anything).twice
+ subject.expects(:timing).with(['event', 'deploy', nil], anything).twice
subject.deploy
subject.deployed
end
it "ensures block is called on socket error" do
@@ -59,54 +84,54 @@
end
describe "#increment_on" do
it "registers success" do
- subject.expects(:increment).with("event.increment.success", 1)
+ subject.expects(:increment).with(["event.increment", "success"], 1)
subject.increment_on('event.increment', true).should == true
end
it "registers failure" do
- subject.expects(:increment).with("event.increment.fail", 1)
+ subject.expects(:increment).with(["event.increment", "fail"], 1)
subject.increment_on('event.increment', false).should == false
end
it "simply questions the passed val with if" do
a = mock()
a.expects(:save).returns({})
- subject.expects(:increment).with("event.increment.success", 1)
+ subject.expects(:increment).with(["event.increment", "success"], 1)
subject.increment_on('event.increment', a.save).should == {}
end
it "registers fail on nil return" do
a = mock()
a.expects(:save).returns(nil)
- subject.expects(:increment).with("event.increment.fail", 1)
+ subject.expects(:increment).with(["event.increment", "fail"], 1)
subject.increment_on('event.increment', a.save).should == nil
end
describe "performing actions" do
it "registers success" do
a = mock()
a.expects(:save).returns(true)
- subject.expects(:increment).with("event.increment.success", 1)
+ subject.expects(:increment).with(["event.increment", "success"], 1)
subject.increment_on('event.increment', a.save).should == true
end
it "registers failure" do
a = mock()
a.expects(:save).returns(false)
- subject.expects(:increment).with("event.increment.fail", 1)
+ subject.expects(:increment).with(["event.increment", "fail"], 1)
subject.increment_on('event.increment', a.save).should == false
end
it "registers positive even when nested" do
a = mock()
a.expects(:save).returns(true)
subject.expects(:timing).with('event.run', any_parameters)
- subject.expects(:increment).with("event.increment.success", 1)
+ subject.expects(:increment).with(["event.increment", "success"], 1)
res = subject.time_to_do "event.run" do
subject.increment_on('event.increment', a.save)
end
res.should == true
@@ -114,19 +139,19 @@
it "registers negative even when nested" do
a = mock()
a.expects(:save).returns(false)
subject.expects(:timing).with('event.run', any_parameters)
- subject.expects(:increment).with("event.increment.fail", 1)
+ subject.expects(:increment).with(["event.increment", "fail"], 1)
res = subject.time_to_do "event.run" do
subject.increment_on('event.increment', a.save)
end
res.should == false
end
it "allows passing of arrays for stat key" do
- subject.expects(:timing).with('event.commit', any_parameters)
+ subject.expects(:timing).with(['event', 'commit'], any_parameters)
subject.time_to_do %w{event commit} do; end
end
end
\ No newline at end of file