spec/lib/fozzie/sniff_spec.rb in fozzie-0.0.27 vs spec/lib/fozzie/sniff_spec.rb in fozzie-1.0.0

- old
+ new

@@ -11,13 +11,19 @@ _monitor def self.koala(hsh = {}); hsh end def self.badger; :cares end + _monitor("my.awesome.class.bucket.name") + def self.class_method_with_non_default_bucket_name; true; end + _monitor - def foo; :foo end + def foo; :foo; end + _monitor("my.awesome.bucket.name") + def method_with_non_default_bucket_name; true; end + _monitor def sloth(a, b, c); [a,b,c] end def honeybadger; :dontcare end @@ -28,104 +34,98 @@ _monitor def self.class_method_yielding_to_block yield(:retval_from_block) if block_given? end - - self end + + FooBar end + # Turn on sniffing for the duration of this spec + before(:all) do + Fozzie.c.sniff_envs << :test + end - context "environments" do - subject { klass } - - it "is disabled in test" do - Fozzie.c.stubs(:env).returns('test') - S.expects(:time_for).with(['foo_bar', 'bar!']).never - - subject.bar! - end - - it "is enabled in development" do - Fozzie.c.stubs(:env).returns('development') - S.expects(:time_for).with(['foo_bar', 'bar!']) - - subject.bar! - end - + after(:all) do + Fozzie.c.sniff_envs.delete(:test) end context 'class methods' do subject { klass } - + it "aliases methods for monitoring" do subject.methods.grep(/bar/).should =~ [:bar!, :"bar_with_monitor!", :"bar_without_monitor!"] end it "behaves like original" do subject.bar!.should eq :bar end it "utilises Fozzie" do - S.expects(:time_for).with(['foo_bar', 'bar!']) + S.should_receive(:time_for).with(['foo_bar', 'bar!']) subject.bar! end it "handles arguments" do h = { drop: 'bear' } subject.koala(h).should eq h end it "does not monitor when mapped" do - S.expects(:time_for).with(['foo_bar', 'badger']).never + S.should_receive(:time_for).with(['foo_bar', 'badger']).never subject.badger.should eq :cares end - - it "yields to a block when given" do - subject.class_method_yielding_to_block do |value_from_block| - value_from_block - end.should eq :retval_from_block + it "optionally sets the bucket name" do + S.should_receive(:time_for).with("my.awesome.class.bucket.name") + + subject.class_method_with_non_default_bucket_name end + + it "yields to a block when given" do + subject.class_method_yielding_to_block {|val| val }.should eq :retval_from_block + end end context 'instance methods' do - subject { FooBar.new } - + subject { klass.new } + it "aliases methods for monitoring" do subject.methods.grep(/foo/).should =~ [:foo, :foo_with_monitor, :foo_without_monitor] end it "behaves like original" do subject.foo.should eq :foo end it "utilises Fozzie" do - S.expects(:time_for).with(['foo_bar', 'foo']) + S.should_receive(:time_for).with(['foo_bar', 'foo']) subject.foo end + it "optionally sets the bucket name" do + S.should_receive(:time_for).with("my.awesome.bucket.name") + + subject.method_with_non_default_bucket_name + end + it "handles arguments" do a = [:slow, :slower, :slowest] subject.sloth(*a).should eq a end it "does not monitor when mapped" do - S.expects(:time_for).with(['foo_bar', 'honeybadger']).never + S.should_receive(:time_for).with(['foo_bar', 'honeybadger']).never subject.honeybadger.should eq :dontcare end it "yields to a block when given" do - subject.method_yielding_to_block do |value_from_block| - value_from_block - end.should eq :retval_from_block + subject.method_yielding_to_block {|val| val }.should eq :retval_from_block end - end - end