Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert to minispec

  • Loading branch information...
commit da416c1de2e61db6ad1dd325d9455c0fea9ff65f 1 parent 89fadd5
@copiousfreetime authored
View
2  Rakefile
@@ -8,7 +8,7 @@ This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
This.ruby_gemspec do |spec|
spec.add_development_dependency( 'rake' , '~> 10.0.3')
- spec.add_development_dependency( 'rspec' , '~> 2.13.0' )
+ spec.add_development_dependency( 'minitest' , '~> 4.6.2' )
spec.add_development_dependency( 'rdoc' , '~> 4.0' )
spec.add_development_dependency( 'json' , '~> 1.7.7' )
spec.add_development_dependency( 'rake-compiler', '~> 0.8.3' )
View
4 spec/hitimes_spec.rb
@@ -5,10 +5,10 @@
d = Hitimes.measure do
sleep 0.2
end
- d.should be_within(0.02).of(0.2)
+ d.must_be_close_to(0.2, 0.002)
end
it "raises an error if measure is called with no block" do
- lambda{ Hitimes.measure }.should raise_error( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
+ lambda{ Hitimes.measure }.must_raise( Hitimes::Error )
end
end
View
66 spec/interval_spec.rb
@@ -3,54 +3,54 @@
describe Hitimes::Interval do
it "raises an error if duration is called on a non-started interval" do
i = Hitimes::Interval.new
- lambda{ i.duration }.should raise_error( Hitimes::Error, /\AAttempt to report a duration on an interval that has not started\Z/ )
+ lambda{ i.duration }.must_raise( Hitimes::Error, /\AAttempt to report a duration on an interval that has not started\Z/ )
end
it "raises an error if stop is called on a non-started interval" do
i = Hitimes::Interval.new
- lambda { i.stop }.should raise_error( Hitimes::Error, /\AAttempt to stop an interval that has not started\Z/ )
+ lambda { i.stop }.must_raise( Hitimes::Error, /\AAttempt to stop an interval that has not started\Z/ )
end
it "knows if it has been started" do
i = Hitimes::Interval.new
- i.should_not be_started
+ i.started?.must_equal false
i.start
- i.should be_started
+ i.started?.must_equal true
end
it "knows if it has been stopped" do
i = Hitimes::Interval.new
i.start
- i.should_not be_stopped
+ i.stopped?.must_equal false
i.stop
- i.should be_stopped
+ i.stopped?.must_equal true
end
it "knows if it is currently running" do
i = Hitimes::Interval.new
- i.should_not be_running
+ i.running?.must_equal false
i.start
- i.should be_running
+ i.running?.must_equal true
i.stop
- i.should_not be_running
+ i.running?.must_equal false
end
it "can time a block of code" do
d = Hitimes::Interval.measure do
sleep 0.2
end
- d.should be_within(0.02).of(0.2)
+ d.must_be_close_to(0.2, 0.002)
end
it "raises an error if measure is called with no block" do
- lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
+ lambda{ Hitimes::Interval.measure }.must_raise( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
end
it "creates an interval via #now" do
i = Hitimes::Interval.now
- i.should be_started
- i.should_not be_stopped
+ i.started?.must_equal true
+ i.stopped?.must_equal false
end
it "calling duration multiple times returns successivly grater durations" do
@@ -58,33 +58,33 @@
i.start
y = i.duration
z = i.duration
- z.should > y
+ z.must_be :>, y
end
it "calling start multiple times on has no effect after the first call" do
i = Hitimes::Interval.new
- i.start.should be == true
+ i.start.must_equal true
x = i.start_instant
- i.start_instant.should be > 0
- i.start.should be == false
- x.should == i.start_instant
+ i.start_instant.must_be :>, 0
+ i.start.must_equal false
+ x.must_equal i.start_instant
end
it "returns the duration on the first call to stop" do
i = Hitimes::Interval.now
d = i.stop
- d.should be_instance_of( Float )
+ d.must_be_instance_of( Float )
end
it "calling stop multiple times on has no effect after the first call" do
i = Hitimes::Interval.new
- i.start.should be == true
+ i.start.must_equal true
i.stop
x = i.stop_instant
- i.stop_instant.should be > 0
- i.stop.should be == false
- x.should == i.stop_instant
+ i.stop_instant.must_be :>, 0
+ i.stop.must_equal false
+ x.must_equal i.stop_instant
end
@@ -93,26 +93,26 @@
i.start
x = i.stop
y = i.duration
- i.stop.should be == false
+ i.stop.must_equal false
z = i.duration
- x.should be == y
- x.should be == z
+ x.must_equal y
+ x.must_equal z
- y.should be == z
+ y.must_equal z
end
it "can return how much time has elapsed from the start without stopping the interval" do
i = Hitimes::Interval.new
i.start
x = i.duration_so_far
- i.should be_running
+ i.running?.must_equal true
y = i.duration_so_far
i.stop
- x.should be < y
- x.should be < i.duration
- y.should be < i.duration
+ x.must_be :<, y
+ x.must_be :<, i.duration
+ y.must_be :<, i.duration
end
describe "#split" do
@@ -121,14 +121,14 @@
i = Hitimes::Interval.new
i.start
i2 = i.split
- i.object_id.should_not == i2.object_id
+ i.object_id.wont_equal i2.object_id
end
it "with the stop instant equivialent to the previous Interval's start instant" do
i = Hitimes::Interval.new
i.start
i2 = i.split
- i.stop_instant.should == i2.start_instant
+ i.stop_instant.must_equal i2.start_instant
end
end
View
14 spec/metric_spec.rb
@@ -6,22 +6,22 @@
end
it 'has a name' do
- @metric.name.should be == "testing"
+ @metric.name.must_equal "testing"
end
it "has associated data from initialization" do
m = Hitimes::Metric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
- m.additional_data['foo'].should be == 'bar'
- m.additional_data['this'].should be == 'that'
+ m.additional_data['foo'].must_equal 'bar'
+ m.additional_data['this'].must_equal 'that'
m = Hitimes::Metric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
- m.additional_data['foo'].should be == 'bar'
- m.additional_data['this'].should be == 'that'
+ m.additional_data['foo'].must_equal 'bar'
+ m.additional_data['this'].must_equal 'that'
end
it "initially has no sampling times" do
- @metric.sampling_start_time.should be == nil
- @metric.sampling_stop_time.should be == nil
+ @metric.sampling_start_time.must_be_nil
+ @metric.sampling_stop_time.must_be_nil
end
end
View
6 spec/mutex_stats_spec.rb
@@ -19,18 +19,18 @@ def run_with_scissors( stats, threads, iters )
if (not defined? RUBY_ENGINE) or (RUBY_ENGINE == "ruby") then
it "Hitimes::Stats is threadsafe" do
stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
- stats.count.should== @final_value
+ stats.count.must_equal @final_value
end
else
it "Hitimes::Stats is not threadsafe" do
stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
- stats.count.should_not == @final_value
+ stats.count.wont_equal @final_value
end
end
it "has a threadsafe update" do
stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
- stats.count.should == @final_value
+ stats.count.must_equal @final_value
end
end
View
4 spec/paths_spec.rb
@@ -2,10 +2,10 @@
describe Hitimes::Paths do
it "can access the root dir of the project" do
- Hitimes::Paths.root_dir.should == File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
+ Hitimes::Paths.root_dir.must_equal File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
end
it "can access the lib path of the project" do
- Hitimes::Paths.lib_path.should == File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
+ Hitimes::Paths.lib_path.must_equal File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
end
end
View
4 spec/spec_helper.rb
@@ -4,6 +4,8 @@
SimpleCov.start if ENV['COVERAGE']
end
-require 'rspec/autorun'
+gem 'minitest'
require 'hitimes'
+require 'minitest/autorun'
+require 'minitest/pride'
View
54 spec/stats_spec.rb
@@ -10,64 +10,64 @@
end
it "is initialized with 0 values" do
- @stats.count.should be == 0
- @stats.min.should be == 0.0
- @stats.max.should be == 0.0
- @stats.sum.should be == 0.0
- @stats.rate.should be == 0.0
+ @stats.count.must_equal 0
+ @stats.min.must_equal 0.0
+ @stats.max.must_equal 0.0
+ @stats.sum.must_equal 0.0
+ @stats.rate.must_equal 0.0
end
it "calculates the mean correctly" do
- @full_stats.mean.should be == 2.0
+ @full_stats.mean.must_equal 2.0
end
it "calculates the rate correctly" do
- @full_stats.rate.should be == 0.5
+ @full_stats.rate.must_equal 0.5
end
it "tracks the maximum value" do
- @full_stats.max.should be == 3.0
+ @full_stats.max.must_equal 3.0
end
it "tracks the minimum value" do
- @full_stats.min.should be == 1.0
+ @full_stats.min.must_equal 1.0
end
it "tracks the count" do
- @full_stats.count.should be == 3
+ @full_stats.count.must_equal 3
end
it "tracks the sum" do
- @full_stats.sum.should be == 6.0
+ @full_stats.sum.must_equal 6.0
end
it "calculates the standard deviation" do
- @full_stats.stddev.should be == 1.0
+ @full_stats.stddev.must_equal 1.0
end
it "calculates the sum of squares " do
- @full_stats.sumsq.should be == 14.0
+ @full_stats.sumsq.must_equal 14.0
end
describe "#to_hash " do
it "converts to a Hash" do
h = @full_stats.to_hash
- h.size.should be == ::Hitimes::Stats::STATS.size
- h.keys.sort.should be == ::Hitimes::Stats::STATS
+ h.size.must_equal ::Hitimes::Stats::STATS.size
+ h.keys.sort.must_equal ::Hitimes::Stats::STATS
end
it "converts to a limited Hash if given arguments" do
h = @full_stats.to_hash( "min", "max", "mean" )
- h.size.should be == 3
- h.keys.sort.should be == %w[ max mean min ]
+ h.size.must_equal 3
+ h.keys.sort.must_equal %w[ max mean min ]
h = @full_stats.to_hash( %w[ count rate ] )
- h.size.should be == 2
- h.keys.sort.should be == %w[ count rate ]
+ h.size.must_equal 2
+ h.keys.sort.must_equal %w[ count rate ]
end
it "raises NoMethodError if an invalid stat is used" do
- lambda { @full_stats.to_hash( "wibble" ) }.should raise_error( NoMethodError )
+ lambda { @full_stats.to_hash( "wibble" ) }.must_raise( NoMethodError )
end
end
@@ -75,24 +75,24 @@
it "converts to a json string" do
j = @full_stats.to_json
h = JSON.parse( j )
- h.size.should be == ::Hitimes::Stats::STATS.size
- h.keys.sort.should be == ::Hitimes::Stats::STATS
+ h.size.must_equal ::Hitimes::Stats::STATS.size
+ h.keys.sort.must_equal ::Hitimes::Stats::STATS
end
it "converts to a limited Hash if given arguments" do
j = @full_stats.to_json( "min", "max", "mean" )
h = JSON.parse( j )
- h.size.should be == 3
- h.keys.sort.should be == %w[ max mean min ]
+ h.size.must_equal 3
+ h.keys.sort.must_equal %w[ max mean min ]
j = @full_stats.to_json( %w[ count rate ] )
h = JSON.parse( j )
- h.size.should be == 2
- h.keys.sort.should be == %w[ count rate ]
+ h.size.must_equal 2
+ h.keys.sort.must_equal %w[ count rate ]
end
it "raises NoMethodError if an invalid stat is used" do
- lambda { @full_stats.to_json( "wibble" ) }.should raise_error( NoMethodError )
+ lambda { @full_stats.to_json( "wibble" ) }.must_raise( NoMethodError )
end
end
end
View
74 spec/timed_metric_spec.rb
@@ -6,90 +6,90 @@
end
it "knows if it is running or not" do
- @tm.should_not be_running
+ @tm.running?.must_equal false
@tm.start
- @tm.should be_running
+ @tm.running?.must_equal true
@tm.stop
- @tm.should_not be_running
+ @tm.running?.must_equal false
end
it "#split returns the last duration and the timer is still running" do
@tm.start
d = @tm.split
- @tm.should be_running
- d.should be > 0
- @tm.count.should be == 1
- @tm.duration.should be == d
+ @tm.running?.must_equal true
+ d.must_be :>, 0
+ @tm.count.must_equal 1
+ @tm.duration.must_equal d
end
it "#stop returns false if called more than once in a row" do
@tm.start
- @tm.stop.should be > 0
- @tm.stop.should be == false
+ @tm.stop.must_be :>, 0
+ @tm.stop.must_equal false
end
it "does not count a currently running interval as an interval in calculations" do
@tm.start
- @tm.count.should be == 0
+ @tm.count.must_equal 0
@tm.split
- @tm.count.should be == 1
+ @tm.count.must_equal 1
end
it "#split called on a stopped timer does nothing" do
@tm.start
@tm.stop
- @tm.split.should be == false
+ @tm.split.must_equal false
end
it "calculates the mean of the durations" do
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.mean.should be_within(0.01).of(0.05)
+ @tm.mean.must_be_close_to(0.05, 0.002)
end
it "calculates the rate of the counts " do
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.rate.should be_within(1.0).of(20.00)
+ @tm.rate.must_be_close_to(20.00, 0.5)
end
it "calculates the stddev of the durations" do
3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop }
- @tm.stddev.should be_within(0.002).of( 0.05)
+ @tm.stddev.must_be_close_to(0.05)
end
it "returns 0.0 for stddev if there is no data" do
- @tm.stddev.should be == 0.0
+ @tm.stddev.must_equal 0.0
end
it "keeps track of the min value" do
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.min.should be_within( 0.002 ).of(0.05)
+ @tm.min.must_be_close_to(0.05, 0.01)
end
it "keeps track of the max value" do
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.max.should be_within( 0.002 ).of(0.05)
+ @tm.max.must_be_close_to(0.05, 0.01)
end
it "keeps track of the sum value" do
2.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.sum.should be_within( 0.005 ).of(0.10)
+ @tm.sum.must_be_close_to(0.10, 0.01)
end
it "keeps track of the sum of squars value" do
3.times { @tm.start ; sleep 0.05 ; @tm.stop }
- @tm.sumsq.should be_within(0.001).of(0.0075)
+ @tm.sumsq.must_be_close_to(0.0075)
end
it "keeps track of the minimum start time of all the intervals" do
f1 = Time.now.gmtime.to_f * 1_000_000
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
f2 = Time.now.gmtime.to_f * 1_000_000
- @tm.sampling_start_time.should be >= f1
- @tm.sampling_start_time.should be < f2
+ @tm.sampling_start_time.must_be :>=, f1
+ @tm.sampling_start_time.must_be :<, f2
# distance from now to start time should be greater than the distance from
# the start to the min start_time
- (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
+ (f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
end
it "keeps track of the last stop time of all the intervals" do
@@ -98,57 +98,57 @@
5.times { @tm.start ; sleep 0.05 ; @tm.stop }
sleep 0.01
f2 = Time.now.gmtime.to_f * 1_000_000
- @tm.sampling_stop_time.should be > f1
- @tm.sampling_stop_time.should be <= f2
+ @tm.sampling_stop_time.must_be :>, f1
+ @tm.sampling_stop_time.must_be :<=, f2
# distance from now to max stop time time should be less than the distance
# from the start to the max stop time
- (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
+ (f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
end
it "can create an already running timer" do
t = Hitimes::TimedMetric.now( 'already-running' )
- t.should be_running
+ t.running?.must_equal true
end
it "can measure a block of code from an instance" do
t = Hitimes::TimedMetric.new( 'measure a block' )
3.times { t.measure { sleep 0.05 } }
- t.duration.should be_within(0.01).of(0.15)
- t.count.should be == 3
+ t.duration.must_be_close_to(0.15, 0.01)
+ t.count.must_equal 3
end
it "returns the value of the block when measuring" do
t = Hitimes::TimedMetric.new( 'measure a block' )
x = t.measure { sleep 0.05; 42 }
- t.duration.should be_within(0.002).of(0.05)
- x.should be == 42
+ t.duration.must_be_close_to(0.05, 0.002)
+ x.must_equal 42
end
describe "#to_hash" do
it "has name value" do
h = @tm.to_hash
- h['name'].should be == "test-timed-metric"
+ h['name'].must_equal "test-timed-metric"
end
it "has an empty hash for additional_data" do
h = @tm.to_hash
- h['additional_data'].should be == Hash.new
- h['additional_data'].size.should be == 0
+ h['additional_data'].must_equal Hash.new
+ h['additional_data'].size.must_equal 0
end
it "has the right sum" do
10.times { |x| @tm.measure { sleep 0.01*x } }
h = @tm.to_hash
- h['sum'].should be_within( 0.01).of(0.45)
+ h['sum'].must_be_close_to(0.45, 0.01)
end
fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
fields.each do |f|
- it "should have a value for #{f}" do
+ it "has a value for #{f}" do
@tm.measure { sleep 0.001 }
h = @tm.to_hash
- h[f].should_not be_nil
+ h[f].wont_be_nil
end
end
end
View
98 spec/timed_value_metric_spec.rb
@@ -6,100 +6,100 @@
end
it "knows if it is running or not" do
- @tm.should_not be_running
+ @tm.running?.must_equal false
@tm.start
- @tm.should be_running
+ @tm.running?.must_equal true
@tm.stop( 1 )
- @tm.should_not be_running
+ @tm.running?.must_equal false
end
it "#split returns the last duration and the timer is still running" do
@tm.start
d = @tm.split( 1 )
- @tm.should be_running
- d.should be > 0
- @tm.value_stats.count.should be == 1
- @tm.timed_stats.count.should be == 1
- @tm.duration.should be == d
+ @tm.running?.must_equal true
+ d.must_be :>, 0
+ @tm.value_stats.count.must_equal 1
+ @tm.timed_stats.count.must_equal 1
+ @tm.duration.must_equal d
end
it "#stop returns false if called more than once in a row" do
@tm.start
- @tm.stop( 1 ).should be > 0
- @tm.stop( 1 ).should be == false
+ @tm.stop( 1 ).must_be :>, 0
+ @tm.stop( 1 ).must_equal false
end
it "does not count a currently running interval as an interval in calculations" do
@tm.start
- @tm.value_stats.count.should be == 0
- @tm.timed_stats.count.should be == 0
+ @tm.value_stats.count.must_equal 0
+ @tm.timed_stats.count.must_equal 0
@tm.split( 1 )
- @tm.value_stats.count.should be == 1
- @tm.timed_stats.count.should be == 1
+ @tm.value_stats.count.must_equal 1
+ @tm.timed_stats.count.must_equal 1
end
it "#split called on a stopped timer does nothing" do
@tm.start
@tm.stop( 1 )
- @tm.split( 1 ).should be == false
+ @tm.split( 1 ).must_equal false
end
it "calculates the mean of the durations" do
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop(x) }
- @tm.timed_stats.mean.should be_within(0.01).of(0.05)
- @tm.value_stats.mean.should be == 1.00
+ @tm.timed_stats.mean.must_be_close_to(0.05, 0.01)
+ @tm.value_stats.mean.must_equal 1.00
end
it "calculates the rate of the counts " do
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
- @tm.rate.should be_within(1.0).of(40.0)
+ @tm.rate.must_be_close_to(40.0, 1.0)
end
it "calculates the stddev of the durations" do
3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop(x) }
- @tm.timed_stats.stddev.should be_within(0.001).of(0.05)
- @tm.value_stats.stddev.should be == 1.0
+ @tm.timed_stats.stddev.must_be_close_to(0.05, 0.001)
+ @tm.value_stats.stddev.must_equal 1.0
end
it "returns 0.0 for stddev if there is no data" do
- @tm.timed_stats.stddev.should be == 0.0
- @tm.value_stats.stddev.should be == 0.0
+ @tm.timed_stats.stddev.must_equal 0.0
+ @tm.value_stats.stddev.must_equal 0.0
end
it "keeps track of the min value" do
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
- @tm.timed_stats.min.should be_within( 0.003 ).of(0.05)
- @tm.value_stats.min.should be == 0
+ @tm.timed_stats.min.must_be_close_to( 0.05, 0.003 )
+ @tm.value_stats.min.must_equal 0
end
it "keeps track of the max value" do
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
- @tm.timed_stats.max.should be_within(0.003).of( 0.05 )
- @tm.value_stats.max.should be == 2
+ @tm.timed_stats.max.must_be_close_to( 0.05, 0.003 )
+ @tm.value_stats.max.must_equal 2
end
it "keeps track of the sum value" do
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
- @tm.timed_stats.sum.should be_within(0.01).of(0.15)
- @tm.value_stats.sum.should be == 3
+ @tm.timed_stats.sum.must_be_close_to( 0.15, 0.01 )
+ @tm.value_stats.sum.must_equal 3
end
it "keeps track of the sum of squares value" do
3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
- @tm.timed_stats.sumsq.should be_within(0.0005).of(0.0075)
- @tm.value_stats.sumsq.should be == 5
+ @tm.timed_stats.sumsq.must_be_close_to(0.0075, 0.0005)
+ @tm.value_stats.sumsq.must_equal 5
end
it "keeps track of the minimum start time of all the intervals" do
f1 = Time.now.gmtime.to_f * 1000000
5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
f2 = Time.now.gmtime.to_f * 1000000
- @tm.sampling_start_time.should be >= f1
- @tm.sampling_start_time.should be < f2
+ @tm.sampling_start_time.must_be :>=, f1
+ @tm.sampling_start_time.must_be :<, f2
# distance from now to start time should be greater than the distance from
# the start to the min start_time
- (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
+ (f2 - @tm.sampling_start_time).must_be :>, ( @tm.sampling_start_time - f1 )
end
it "keeps track of the last stop time of all the intervals" do
@@ -107,64 +107,64 @@
5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
sleep 0.05
f2 = Time.now.gmtime.to_f * 1_000_000
- @tm.sampling_stop_time.should be > f1
- @tm.sampling_stop_time.should be <= f2
+ @tm.sampling_stop_time.must_be :>, f1
+ @tm.sampling_stop_time.must_be :<=, f2
# distance from now to max stop time time should be less than the distance
# from the start to the max stop time
- (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
+ (f2 - @tm.sampling_stop_time).must_be :<, ( @tm.sampling_stop_time - f1 )
end
it "can create an already running timer" do
t = Hitimes::TimedValueMetric.now( 'already-running' )
- t.should be_running
+ t.running?.must_equal true
end
it "can measure a block of code from an instance" do
t = Hitimes::TimedValueMetric.new( 'measure a block' )
3.times { t.measure( 1 ) { sleep 0.05 } }
- t.duration.should be_within(0.004).of(0.15)
- t.timed_stats.count.should be == 3
- t.value_stats.count.should be == 3
+ t.duration.must_be_close_to(0.15, 0.004)
+ t.timed_stats.count.must_equal 3
+ t.value_stats.count.must_equal 3
end
it "returns the value of the block when measuring" do
t = Hitimes::TimedValueMetric.new( 'measure a block' )
x = t.measure( 42 ) { sleep 0.05; 42 }
- t.duration.should be_within(0.002).of(0.05)
- x.should be == 42
+ t.duration.must_be_close_to(0.05, 0.002)
+ x.must_equal 42
end
describe "#to_hash" do
it "has name value" do
h = @tm.to_hash
- h['name'].should be == "test-timed-value-metric"
+ h['name'].must_equal "test-timed-value-metric"
end
it "has an empty has for additional_data" do
h = @tm.to_hash
- h['additional_data'].should be == Hash.new
- h['additional_data'].size.should be == 0
+ h['additional_data'].must_equal Hash.new
+ h['additional_data'].size.must_equal 0
end
it "has a rate" do
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
h = @tm.to_hash
- h['rate'].should be_within(1.0 ).of(40.0)
+ h['rate'].must_be_close_to(40.0, 1.0)
end
it "has a unit_count" do
5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
h = @tm.to_hash
- h['unit_count'].should be == 10
+ h['unit_count'].must_equal 10
end
fields = %w[ name additional_data sampling_start_time sampling_stop_time value_stats timed_stats rate unit_count ]
fields.each do |f|
- it "should have a value for #{f}" do
+ it "has a value for #{f}" do
3.times { |x| @tm.measure(x) { sleep 0.001 } }
h = @tm.to_hash
- h[f].should_not be_nil
+ h[f].wont_be_nil
end
end
end
View
50 spec/value_metric_spec.rb
@@ -7,50 +7,50 @@
end
it 'has a name' do
- @metric.name.should be == "testing"
+ @metric.name.must_equal "testing"
end
it "has associated data from initialization" do
m = Hitimes::ValueMetric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
- m.additional_data['foo'].should be == 'bar'
- m.additional_data['this'].should be == 'that'
+ m.additional_data['foo'].must_equal 'bar'
+ m.additional_data['this'].must_equal 'that'
m = Hitimes::ValueMetric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
- m.additional_data['foo'].should be == 'bar'
- m.additional_data['this'].should be == 'that'
+ m.additional_data['foo'].must_equal 'bar'
+ m.additional_data['this'].must_equal 'that'
end
it "calculates the mean of the measurements" do
- @metric.mean.should be == 4.5
+ @metric.mean.must_equal 4.5
end
it "calculates the stddev of the measurements" do
- @metric.stddev.should > 0.0
+ @metric.stddev.must_be :>, 0.0
end
it "returns 0.0 for stddev if there is no data" do
m = Hitimes::ValueMetric.new('0-data')
- m.stddev.should be == 0.0
+ m.stddev.must_equal 0.0
end
it "keeps track of the sum of data" do
- @metric.sum.should be == 45.0
+ @metric.sum.must_equal 45.0
end
it "keeps track of the sum of squars of data" do
- @metric.sumsq.should be == 285.0
+ @metric.sumsq.must_equal 285.0
end
it "retuns 0.0 for mean if there is no data" do
- Hitimes::ValueMetric.new('0-data').mean.should be == 0.0
+ Hitimes::ValueMetric.new('0-data').mean.must_equal 0.0
end
it "keeps track of the min value" do
- @metric.min.should be == 0
+ @metric.min.must_equal 0
end
it "keeps track of the max value" do
- @metric.max.should be == 9
+ @metric.max.must_equal 9
end
it "keeps track of the first start time of all the measurements" do
@@ -58,11 +58,11 @@
f1 = Time.now.gmtime.to_f * 1_000_000
10.times{ |x| m.measure( x ); sleep 0.1 }
f2 = Time.now.gmtime.to_f * 1_000_000
- m.sampling_start_time.should be >= f1
- m.sampling_start_time.should be < f2
+ m.sampling_start_time.must_be :>=, f1
+ m.sampling_start_time.must_be :<, f2
# distance from now to start time should be greater than the distance from
# the start to the min start_time
- (f2 - m.sampling_start_time).should > ( m.sampling_start_time - f1 )
+ (f2 - m.sampling_start_time).must_be :>, ( m.sampling_start_time - f1 )
end
it "keeps track of the last stop time of all the intervals" do
@@ -70,37 +70,37 @@
f1 = Time.now.gmtime.to_f * 1_000_000
10.times {|x| m.measure( x ); sleep 0.1 }
f2 = Time.now.gmtime.to_f * 1_000_000
- m.sampling_stop_time.should be > f1
- m.sampling_stop_time.should be <= f2
+ m.sampling_stop_time.must_be :>, f1
+ m.sampling_stop_time.must_be :<=, f2
# distance from now to max stop time time should be less than the distance
# from the start to the max stop time
- (f2 - m.sampling_stop_time).should < ( m.sampling_stop_time - f1 )
+ (f2 - m.sampling_stop_time).must_be :<, ( m.sampling_stop_time - f1 )
end
describe "#to_hash" do
it "has name value" do
h = @metric.to_hash
- h['name'].should be == "testing"
+ h['name'].must_equal "testing"
end
it "has an empty has for additional_data" do
h = @metric.to_hash
- h['additional_data'].should be == Hash.new
- h['additional_data'].size.should be == 0
+ h['additional_data'].must_equal Hash.new
+ h['additional_data'].size.must_equal 0
end
it "has the right sum" do
h = @metric.to_hash
- h['sum'].should be == 45
+ h['sum'].must_equal 45
end
fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
fields = fields - [ 'rate' ]
fields.each do |f|
- it "should have a value for #{f}" do
+ it "has a value for #{f}" do
h = @metric.to_hash
- h[f].should_not be_nil
+ h[f].wont_be_nil
end
end
end
View
2  spec/version_spec.rb
@@ -2,6 +2,6 @@
describe "Hitimes::Version" do
it "should be accessable as a constant" do
- Hitimes::VERSION.should match(/\d+\.\d+\.\d+/)
+ Hitimes::VERSION.must_match(/\d+\.\d+\.\d+/)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.