ultra_marathon 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  describe UltraMarathon::Instrumentation::Profile do
3
- let(:start_time) { Time.local(1991, 1, 31, 15, 15, 00) }
4
- let(:end_time) { Time.local(1991, 1, 31, 16, 00, 20) }
3
+ let(:start_time) { Time.local(1991, 1, 31, 15, 15, 00, 0) }
4
+ let(:end_time) { Time.local(1991, 1, 31, 16, 00, 20, 0) }
5
5
  let(:run_block) do
6
6
  # This is going to be evaluated in context of the instance
7
7
  # so we need to wrap in an IIF to access `end_time`
@@ -44,7 +44,8 @@ describe UltraMarathon::Instrumentation::Profile do
44
44
  before(:each) { run }
45
45
 
46
46
  it 'should return the total seconds elapsed' do
47
- profile.total_time.should eq 2720
47
+ #Rounding because floats are a pain in the ass
48
+ profile.total_time.round(3).should eq (end_time - start_time).round(3)
48
49
  end
49
50
  end
50
51
 
@@ -52,7 +53,7 @@ describe UltraMarathon::Instrumentation::Profile do
52
53
  before(:each) { run }
53
54
 
54
55
  it 'should return the total time, formatted' do
55
- profile.formatted_total_time.should eq '00:45:20'
56
+ profile.formatted_total_time.should eq '00:45:20:000'
56
57
  end
57
58
  end
58
59
  end
@@ -0,0 +1,73 @@
1
+ require 'ostruct'
2
+ require 'spec_helper'
3
+
4
+ describe UltraMarathon::Instrumentation::Store do
5
+
6
+ let(:profiles) { [] }
7
+ let(:test_instance) { described_class.new(profiles) }
8
+ let(:profile_double_class) do
9
+ anonymous_test_class(OpenStruct) do
10
+ def initialize(name, attributes={})
11
+ @name = name
12
+ super(attributes)
13
+ end
14
+
15
+ def <=>(other_profile_double)
16
+ total_time <=> other_profile_double.total_time
17
+ end
18
+ end
19
+ end
20
+
21
+ def profile_double(*args)
22
+ profile_double_class.new(*args)
23
+ end
24
+
25
+
26
+ describe 'calculation methods' do
27
+ let(:min_profile) { profile_double(:min_profile, total_time: 1) }
28
+ let(:max_profile) { profile_double(:max_profile, total_time: 247) }
29
+ let(:mediocre_profile) { profile_double(:mediocre_profile, total_time: 13.5) }
30
+ let(:profiles) { [min_profile, max_profile, mediocre_profile] }
31
+
32
+ before(:each) do
33
+ test_instance.stub(:instrumentations) do
34
+ {
35
+ min_profile: min_profile,
36
+ max_profile: max_profile,
37
+ mediocre_profile: mediocre_profile
38
+ }
39
+ end
40
+ end
41
+
42
+ describe '#min' do
43
+ it 'should return the name and profile of the min' do
44
+ test_instance.min.should eq min_profile
45
+ end
46
+ end
47
+
48
+ describe '#max' do
49
+ it 'should return the name and profile of the max' do
50
+ test_instance.max.should eq max_profile
51
+ end
52
+ end
53
+
54
+ describe '#median' do
55
+ it 'should return the name and profile of the median' do
56
+ test_instance.median.should eq mediocre_profile
57
+ end
58
+ end
59
+
60
+ describe '#mean_runtime' do
61
+ it 'should return the mean time for all profiles' do
62
+ total_time = profiles.reduce(0) { |sum, profile| sum + profile.total_time }
63
+ test_instance.mean_runtime.should eq (total_time/profiles.size)
64
+ end
65
+ end
66
+
67
+ describe '#standard_deviation' do
68
+ it 'should return the standard deviation of the total times' do
69
+ test_instance.standard_deviation.round(2).should eq 113.13
70
+ end
71
+ end
72
+ end
73
+ end
@@ -22,7 +22,7 @@ describe UltraMarathon::Instrumentation do
22
22
  run.should eq 'Bubbles!'
23
23
  end
24
24
 
25
- it 'should add the instrumentation information to the #instrumentations hash' do
25
+ it 'should add the instrumentation information to the #instrumentations store' do
26
26
  run
27
27
  profile = test_instance.instrumentations[:run]
28
28
  profile.should be_an UltraMarathon::Instrumentation::Profile
@@ -28,7 +28,7 @@ describe UltraMarathon::SubRunner do
28
28
  let(:name) { :frank }
29
29
  let(:context) { test_class.new }
30
30
 
31
- context '#run' do
31
+ context '#run!' do
32
32
  let(:run_block) { ->{ increment_bubbles } }
33
33
  subject { test_instance.run! }
34
34
 
@@ -37,6 +37,10 @@ describe UltraMarathon::SubRunner do
37
37
  context.bubble_count.should be 1
38
38
  end
39
39
 
40
+ it 'returns itself' do
41
+ subject.should be test_instance
42
+ end
43
+
40
44
  it 'starts the logs with its name' do
41
45
  subject
42
46
  test_instance.logger.contents.should be_start_with "Running '#{name}' SubRunner"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_marathon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Maddox
@@ -18,15 +18,24 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - LICENSE.md
20
20
  - README.md
21
+ - lib/core_ext/class.rb
22
+ - lib/core_ext/extensions.rb
23
+ - lib/core_ext/object.rb
21
24
  - lib/core_ext/proc.rb
25
+ - lib/core_ext/string.rb
22
26
  - lib/ultra_marathon.rb
23
27
  - lib/ultra_marathon/abstract_runner.rb
28
+ - lib/ultra_marathon/base_runner.rb
24
29
  - lib/ultra_marathon/callbacks.rb
30
+ - lib/ultra_marathon/collection_runner.rb
31
+ - lib/ultra_marathon/contexticution.rb
25
32
  - lib/ultra_marathon/instrumentation.rb
26
33
  - lib/ultra_marathon/instrumentation/profile.rb
34
+ - lib/ultra_marathon/instrumentation/store.rb
27
35
  - lib/ultra_marathon/logger.rb
28
36
  - lib/ultra_marathon/logging.rb
29
37
  - lib/ultra_marathon/store.rb
38
+ - lib/ultra_marathon/sub_context.rb
30
39
  - lib/ultra_marathon/sub_runner.rb
31
40
  - lib/ultra_marathon/version.rb
32
41
  - spec/spec_helper.rb
@@ -34,7 +43,9 @@ files:
34
43
  - spec/support/test_helpers.rb
35
44
  - spec/ultra_marathon/abstract_runner_spec.rb
36
45
  - spec/ultra_marathon/callbacks_spec.rb
46
+ - spec/ultra_marathon/collection_runner_spec.rb
37
47
  - spec/ultra_marathon/instrumentation/profile_spec.rb
48
+ - spec/ultra_marathon/instrumentation/store_spec.rb
38
49
  - spec/ultra_marathon/instrumentation_spec.rb
39
50
  - spec/ultra_marathon/logging_spec.rb
40
51
  - spec/ultra_marathon/store_spec.rb
@@ -70,8 +81,11 @@ test_files:
70
81
  - spec/support/test_helpers.rb
71
82
  - spec/ultra_marathon/abstract_runner_spec.rb
72
83
  - spec/ultra_marathon/callbacks_spec.rb
84
+ - spec/ultra_marathon/collection_runner_spec.rb
73
85
  - spec/ultra_marathon/instrumentation/profile_spec.rb
86
+ - spec/ultra_marathon/instrumentation/store_spec.rb
74
87
  - spec/ultra_marathon/instrumentation_spec.rb
75
88
  - spec/ultra_marathon/logging_spec.rb
76
89
  - spec/ultra_marathon/store_spec.rb
77
90
  - spec/ultra_marathon/sub_runner_spec.rb
91
+ has_rdoc: