spec/lib/tabs_spec.rb in tabs-0.9.1 vs spec/lib/tabs_spec.rb in tabs-1.0.0

- old
+ new

@@ -80,11 +80,11 @@ Tabs.drop_metric!("foo") expect(Tabs.metric_exists?("foo")).to be_false end it "calls drop! on the metric" do - metric = stub(:metric) + metric = double(:metric) Tabs.stub(get_metric: metric) metric.should_receive(:drop!) Tabs.drop_metric!("foo") end @@ -136,10 +136,11 @@ Tabs.create_metric("foo", "counter") lambda { Tabs.record_value("foo", 27) }.should raise_error(Tabs::MetricTypeMismatchError) end it "calls record on the metric" do + Timecop.freeze(Time.now.utc) metric = Tabs.create_metric("foo", "value") Tabs.stub(get_metric: metric) metric.should_receive(:record).with(42, Time.now.utc) Tabs.record_value("foo", 42) end @@ -172,8 +173,34 @@ it "returns the type of a task metric" do Tabs.create_metric("baz", "task") expect(Tabs.metric_type("baz")).to eq("task") end + end + + describe ".drop_resolution_for_metric!" do + it "raises unknown metric error if metric does not exist" do + expect{ Tabs.drop_resolution_for_metric!(:invalid, :minute) }.to raise_error(Tabs::UnknownMetricError) + end + + it "raises resolution missing error if resolution not registered" do + Tabs.create_metric("baz", "value") + expect{ Tabs.drop_resolution_for_metric!("baz", :invalid) }.to raise_error(Tabs::ResolutionMissingError) + end + + it "does not allow you to call drop_by_resolution if task metric" do + metric = Tabs.create_metric("baz", "task") + metric.should_not_receive(:drop_by_resolution!) + Tabs.drop_resolution_for_metric!("baz", :minute) + end + + it "drops the metric by resolution" do + now = Time.utc(2000,1,1) + metric = Tabs.create_metric("baz", "value") + metric.record(42, now) + Tabs.drop_resolution_for_metric!("baz", :minute) + minute_key = Tabs::Metrics::Value.new("baz").storage_key(:minute, now) + expect(Tabs::Storage.exists(minute_key)).to be_false + end end end