spec/lib/tabs_spec.rb in tabs-0.7.1 vs spec/lib/tabs_spec.rb in tabs-0.8.0

- old
+ new

@@ -1,11 +1,11 @@ require "spec_helper" describe Tabs do include Tabs::Storage - describe "#create_metric" do + describe ".create_metric" do it "raises an error if the type is invalid" do lambda { Tabs.create_metric("foo", "foobar") }.should raise_error(Tabs::UnknownTypeError) end @@ -31,30 +31,30 @@ expect(Tabs.list_metrics).to include("baz") end end - describe "#get_metric" do + describe ".get_metric" do it "returns the expected metric object" do Tabs.create_metric("foo", "counter") expect(Tabs.get_metric("foo")).to be_a_kind_of(Tabs::Metrics::Counter) end end - describe "#list_metrics" do + describe ".list_metrics" do it "returns the list_metrics of metric names" do Tabs.create_metric("foo", "counter") Tabs.create_metric("bar", "value") expect(Tabs.list_metrics).to eq(["foo", "bar"]) end end - describe "#metric_exists?" do + describe ".metric_exists?" do it "returns true if the metric exists" do Tabs.create_metric("foo", "counter") expect(Tabs.metric_exists?("foo")).to be_true end @@ -63,37 +63,49 @@ expect(Tabs.metric_exists?("foo")).to be_false end end - describe "#drop_metric" do + describe ".drop_metric" do before do Tabs.create_metric("foo", "counter") end it "removes the metric from the list_metrics" do - Tabs.drop_metric("foo") + Tabs.drop_metric!("foo") expect(Tabs.list_metrics).to_not include("foo") end it "results in metric_exists? returning false" do - Tabs.drop_metric("foo") + Tabs.drop_metric!("foo") expect(Tabs.metric_exists?("foo")).to be_false end it "calls drop! on the metric" do metric = stub(:metric) Tabs.stub(get_metric: metric) metric.should_receive(:drop!) - Tabs.drop_metric("foo") + Tabs.drop_metric!("foo") end end - describe "#increment_counter" do + describe ".drop_all_metrics" do + it "drops all metrics" do + Tabs.create_metric("foo", "counter") + Tabs.create_metric("bar", "value") + Tabs.drop_all_metrics! + expect(Tabs.metric_exists?("foo")).to be_false + expect(Tabs.metric_exists?("bar")).to be_false + end + + end + + describe ".increment_counter" do + it "raises a Tabs::MetricTypeMismatchError if the metric is the wrong type" do Tabs.create_metric("foo", "value") lambda { Tabs.increment_counter("foo") }.should raise_error(Tabs::MetricTypeMismatchError) end @@ -110,11 +122,11 @@ Tabs.increment_counter("foo") end end - describe "#record_value" do + describe ".record_value" do it "creates the metric if it doesn't exist" do expect(Tabs.metric_exists?("foo")).to be_false lambda { Tabs.record_value("foo", 38) }.should_not raise_error expect(Tabs.metric_exists?("foo")).to be_true @@ -132,21 +144,21 @@ Tabs.record_value("foo", 42) end end - describe "#list_metrics" do + describe ".list_metrics" do it "lists all metrics that are defined" do Tabs.create_metric("foo", "counter") Tabs.create_metric("bar", "counter") Tabs.create_metric("baz", "counter") expect(Tabs.list_metrics).to eq(["foo", "bar", "baz"]) end end - describe "#metric_type" do + describe ".metric_type" do it "returns the type of a counter metric" do Tabs.create_metric("foo", "counter") expect(Tabs.metric_type("foo")).to eq("counter") end