spec/lib/fozzie/sniff_spec.rb in fozzie-0.0.21 vs spec/lib/fozzie/sniff_spec.rb in fozzie-0.0.22
- old
+ new
@@ -1,11 +1,10 @@
require 'spec_helper'
require 'fozzie/sniff'
describe Fozzie::Sniff do
-
- subject do
+ let(:klass) do
class FooBar
_monitor
def self.bar!; :bar end
@@ -20,17 +19,28 @@
_monitor
def sloth(a, b, c); [a,b,c] end
def honeybadger; :dontcare end
- end
+ _monitor
+ def method_yielding_to_block
+ yield(:retval_from_block) if block_given?
+ end
- FooBar
+ _monitor
+ def self.class_method_yielding_to_block
+ yield(:retval_from_block) if block_given?
+ end
+
+ self
+ end
end
- context "environments" do
+ 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!
@@ -44,14 +54,14 @@
end
end
context 'class methods' do
- let!(:env) { Fozzie.c.stubs(:env).returns('development') }
-
+ subject { klass }
+
it "aliases methods for monitoring" do
- subject.methods.grep(/bar/).should eq [:bar!, :"bar_with_monitor!", :"bar_without_monitor!"]
+ subject.methods.grep(/bar/).should =~ [:bar!, :"bar_with_monitor!", :"bar_without_monitor!"]
end
it "behaves like original" do
subject.bar!.should eq :bar
end
@@ -71,37 +81,51 @@
S.expects(: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
+ end
+
end
context 'instance methods' do
-
+ subject { FooBar.new }
+
it "aliases methods for monitoring" do
- subject.new.methods.grep(/foo/).should eq [:foo, :foo_with_monitor, :foo_without_monitor]
+ subject.methods.grep(/foo/).should =~ [:foo, :foo_with_monitor, :foo_without_monitor]
end
it "behaves like original" do
- subject.new.foo.should eq :foo
+ subject.foo.should eq :foo
end
it "utilises Fozzie" do
S.expects(:time_for).with(['foo_bar', 'foo'])
- subject.new.foo
+ subject.foo
end
it "handles arguments" do
a = [:slow, :slower, :slowest]
- subject.new.sloth(*a).should eq a
+ subject.sloth(*a).should eq a
end
it "does not monitor when mapped" do
S.expects(:time_for).with(['foo_bar', 'honeybadger']).never
- subject.new.honeybadger.should eq :dontcare
+ 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
+ end
+
end
-end
\ No newline at end of file
+end