lib/busted.rb in busted-0.0.2 vs lib/busted.rb in busted-0.1.0
- old
+ new
@@ -1,40 +1,34 @@
-require "busted/version"
+require "busted/profiler"
module Busted
extend self
- def cache?(serial = nil, &blk)
- starting = count serial
- yield
- ending = count serial
- ending > starting
+ def run(options = {}, &block)
+ Profiler.run options, &block
end
- def method_cache?(&blk)
- cache? :method, &blk
+ def method_cache_invalidations(&block)
+ run(&block)[:invalidations][:method]
end
- def constant_cache?(&blk)
- cache? :constant, &blk
+ def constant_cache_invalidations(&block)
+ run(&block)[:invalidations][:constant]
end
- def class_cache?(&blk)
- cache? :class, &blk
+ def cache?(counter = nil, &block)
+ total = if counter
+ send :"#{counter}_cache_invalidations", &block
+ else
+ run(&block)[:invalidations].values.inject :+
+ end
+ total > 0
end
- private
+ def method_cache?(&block)
+ cache? :method, &block
+ end
- def count(serial)
- stat = RubyVM.stat
- case serial
- when :method
- stat[:method_serial]
- when :constant
- stat[:constant_serial]
- when :class
- stat[:class_serial]
- else
- stat[:method_serial] + stat[:constant_serial] + stat[:class_serial]
- end
+ def constant_cache?(&block)
+ cache? :constant, &block
end
end