hitimes 1.1.1 → 1.2.0
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.
- data/CONTRIBUTING.md +45 -0
 - data/{HISTORY → HISTORY.rdoc} +14 -1
 - data/LICENSE +11 -8
 - data/Manifest.txt +44 -0
 - data/{README → README.rdoc} +20 -6
 - data/Rakefile +20 -62
 - data/ext/hitimes/{extconf.rb → c/extconf.rb} +3 -3
 - data/ext/hitimes/{hitimes_ext.c → c/hitimes.c} +1 -1
 - data/ext/hitimes/{hitimes_instant_clock_gettime.c → c/hitimes_instant_clock_gettime.c} +0 -0
 - data/ext/hitimes/c/hitimes_instant_osx.c +45 -0
 - data/ext/hitimes/{hitimes_instant_windows.c → c/hitimes_instant_windows.c} +0 -0
 - data/ext/hitimes/{hitimes_interval.c → c/hitimes_interval.c} +15 -7
 - data/ext/hitimes/{hitimes_interval.h → c/hitimes_interval.h} +5 -5
 - data/ext/hitimes/{hitimes_stats.c → c/hitimes_stats.c} +0 -0
 - data/ext/hitimes/{hitimes_stats.h → c/hitimes_stats.h} +0 -0
 - data/ext/hitimes/java/src/hitimes/Hitimes.java +54 -0
 - data/ext/hitimes/java/src/hitimes/HitimesInterval.java +181 -0
 - data/ext/hitimes/java/src/hitimes/HitimesService.java +16 -0
 - data/ext/hitimes/java/src/hitimes/HitimesStats.java +112 -0
 - data/lib/hitimes.rb +15 -5
 - data/lib/hitimes/version.rb +1 -50
 - data/spec/hitimes_spec.rb +14 -0
 - data/spec/interval_spec.rb +24 -21
 - data/spec/metric_spec.rb +8 -10
 - data/spec/mutex_stats_spec.rb +8 -6
 - data/spec/paths_spec.rb +1 -3
 - data/spec/spec_helper.rb +7 -3
 - data/spec/stats_spec.rb +26 -28
 - data/spec/timed_metric_spec.rb +33 -33
 - data/spec/timed_value_metric_spec.rb +45 -46
 - data/spec/value_metric_spec.rb +21 -23
 - data/spec/version_spec.rb +4 -30
 - data/tasks/default.rake +267 -0
 - data/tasks/extension.rake +31 -101
 - data/tasks/this.rb +209 -0
 - metadata +139 -143
 - data/ext/hitimes/hitimes_instant_osx.c +0 -16
 - data/gemspec.rb +0 -64
 - data/tasks/announce.rake +0 -42
 - data/tasks/config.rb +0 -109
 - data/tasks/distribution.rake +0 -93
 - data/tasks/documentation.rake +0 -32
 - data/tasks/rspec.rake +0 -33
 - data/tasks/rubyforge.rake +0 -55
 - data/tasks/utils.rb +0 -80
 
| 
         @@ -1,6 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'hitimes/timed_value_metric'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
3 
     | 
    
         
             
            describe Hitimes::TimedValueMetric do
         
     | 
| 
       6 
4 
     | 
    
         
             
              before( :each ) do
         
     | 
| 
         @@ -19,97 +17,98 @@ describe Hitimes::TimedValueMetric do 
     | 
|
| 
       19 
17 
     | 
    
         
             
                @tm.start
         
     | 
| 
       20 
18 
     | 
    
         
             
                d = @tm.split( 1 )
         
     | 
| 
       21 
19 
     | 
    
         
             
                @tm.should be_running
         
     | 
| 
       22 
     | 
    
         
            -
                d.should > 0
         
     | 
| 
       23 
     | 
    
         
            -
                @tm.value_stats.count.should == 1
         
     | 
| 
       24 
     | 
    
         
            -
                @tm.timed_stats.count.should == 1
         
     | 
| 
       25 
     | 
    
         
            -
                @tm.duration.should == d
         
     | 
| 
      
 20 
     | 
    
         
            +
                d.should be > 0
         
     | 
| 
      
 21 
     | 
    
         
            +
                @tm.value_stats.count.should be == 1
         
     | 
| 
      
 22 
     | 
    
         
            +
                @tm.timed_stats.count.should be == 1
         
     | 
| 
      
 23 
     | 
    
         
            +
                @tm.duration.should be == d
         
     | 
| 
       26 
24 
     | 
    
         
             
              end
         
     | 
| 
       27 
25 
     | 
    
         | 
| 
       28 
26 
     | 
    
         
             
              it "#stop returns false if called more than once in a row" do
         
     | 
| 
       29 
27 
     | 
    
         
             
                @tm.start
         
     | 
| 
       30 
     | 
    
         
            -
                @tm.stop( 1 ).should > 0
         
     | 
| 
       31 
     | 
    
         
            -
                @tm.stop( 1 ).should == false
         
     | 
| 
      
 28 
     | 
    
         
            +
                @tm.stop( 1 ).should be > 0
         
     | 
| 
      
 29 
     | 
    
         
            +
                @tm.stop( 1 ).should be == false
         
     | 
| 
       32 
30 
     | 
    
         
             
              end
         
     | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
32 
     | 
    
         
             
              it "does not count a currently running interval as an interval in calculations" do
         
     | 
| 
       35 
33 
     | 
    
         
             
                @tm.start
         
     | 
| 
       36 
     | 
    
         
            -
                @tm.value_stats.count.should == 0
         
     | 
| 
       37 
     | 
    
         
            -
                @tm.timed_stats.count.should == 0
         
     | 
| 
      
 34 
     | 
    
         
            +
                @tm.value_stats.count.should be == 0
         
     | 
| 
      
 35 
     | 
    
         
            +
                @tm.timed_stats.count.should be == 0
         
     | 
| 
       38 
36 
     | 
    
         
             
                @tm.split( 1 )
         
     | 
| 
       39 
     | 
    
         
            -
                @tm.value_stats.count.should == 1
         
     | 
| 
       40 
     | 
    
         
            -
                @tm.timed_stats.count.should == 1
         
     | 
| 
      
 37 
     | 
    
         
            +
                @tm.value_stats.count.should be == 1
         
     | 
| 
      
 38 
     | 
    
         
            +
                @tm.timed_stats.count.should be == 1
         
     | 
| 
       41 
39 
     | 
    
         
             
              end
         
     | 
| 
       42 
40 
     | 
    
         | 
| 
       43 
41 
     | 
    
         
             
              it "#split called on a stopped timer does nothing" do
         
     | 
| 
       44 
42 
     | 
    
         
             
                @tm.start
         
     | 
| 
       45 
43 
     | 
    
         
             
                @tm.stop( 1 )
         
     | 
| 
       46 
     | 
    
         
            -
                @tm.split( 1 ).should == false
         
     | 
| 
      
 44 
     | 
    
         
            +
                @tm.split( 1 ).should be == false
         
     | 
| 
       47 
45 
     | 
    
         
             
              end
         
     | 
| 
       48 
46 
     | 
    
         | 
| 
       49 
47 
     | 
    
         
             
              it "calculates the mean of the durations" do
         
     | 
| 
       50 
48 
     | 
    
         
             
                3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop(x) }
         
     | 
| 
       51 
     | 
    
         
            -
                @tm.timed_stats.mean.should  
     | 
| 
       52 
     | 
    
         
            -
                @tm.value_stats.mean.should == 1.00
         
     | 
| 
      
 49 
     | 
    
         
            +
                @tm.timed_stats.mean.should be_within(0.01).of(0.05)
         
     | 
| 
      
 50 
     | 
    
         
            +
                @tm.value_stats.mean.should be == 1.00
         
     | 
| 
       53 
51 
     | 
    
         
             
              end
         
     | 
| 
       54 
52 
     | 
    
         | 
| 
       55 
53 
     | 
    
         
             
              it "calculates the rate of the counts " do
         
     | 
| 
       56 
54 
     | 
    
         
             
                5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       57 
     | 
    
         
            -
                @tm.rate.should  
     | 
| 
      
 55 
     | 
    
         
            +
                @tm.rate.should be_within(1.0).of(40.0)
         
     | 
| 
       58 
56 
     | 
    
         
             
              end
         
     | 
| 
       59 
57 
     | 
    
         | 
| 
       60 
58 
     | 
    
         | 
| 
       61 
59 
     | 
    
         
             
              it "calculates the stddev of the durations" do
         
     | 
| 
       62 
     | 
    
         
            -
                3.times { |x| @tm.start ; sleep 
     | 
| 
       63 
     | 
    
         
            -
                @tm.timed_stats.stddev.should  
     | 
| 
       64 
     | 
    
         
            -
                @tm.value_stats.stddev.should == 1.0
         
     | 
| 
      
 60 
     | 
    
         
            +
                3.times { |x| @tm.start ; sleep(0.05 * x) ; @tm.stop(x) }
         
     | 
| 
      
 61 
     | 
    
         
            +
                @tm.timed_stats.stddev.should be_within(0.001).of(0.05)
         
     | 
| 
      
 62 
     | 
    
         
            +
                @tm.value_stats.stddev.should be == 1.0
         
     | 
| 
       65 
63 
     | 
    
         
             
              end
         
     | 
| 
       66 
64 
     | 
    
         | 
| 
       67 
65 
     | 
    
         
             
              it "returns 0.0 for stddev if there is no data" do
         
     | 
| 
       68 
     | 
    
         
            -
                @tm.timed_stats.stddev.should == 0.0
         
     | 
| 
       69 
     | 
    
         
            -
                @tm.value_stats.stddev.should == 0.0
         
     | 
| 
      
 66 
     | 
    
         
            +
                @tm.timed_stats.stddev.should be == 0.0
         
     | 
| 
      
 67 
     | 
    
         
            +
                @tm.value_stats.stddev.should be == 0.0
         
     | 
| 
       70 
68 
     | 
    
         
             
              end
         
     | 
| 
       71 
69 
     | 
    
         | 
| 
       72 
70 
     | 
    
         
             
              it "keeps track of the min value" do
         
     | 
| 
       73 
71 
     | 
    
         
             
                3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       74 
     | 
    
         
            -
                @tm.timed_stats.min.should  
     | 
| 
       75 
     | 
    
         
            -
                @tm.value_stats.min.should == 0
         
     | 
| 
      
 72 
     | 
    
         
            +
                @tm.timed_stats.min.should be_within( 0.003 ).of(0.05)
         
     | 
| 
      
 73 
     | 
    
         
            +
                @tm.value_stats.min.should be == 0
         
     | 
| 
       76 
74 
     | 
    
         
             
              end
         
     | 
| 
       77 
75 
     | 
    
         | 
| 
       78 
76 
     | 
    
         
             
              it "keeps track of the max value" do
         
     | 
| 
       79 
77 
     | 
    
         
             
                3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       80 
     | 
    
         
            -
                @tm.timed_stats.max.should  
     | 
| 
       81 
     | 
    
         
            -
                @tm.value_stats.max.should == 2
         
     | 
| 
      
 78 
     | 
    
         
            +
                @tm.timed_stats.max.should be_within(0.003).of( 0.05 )
         
     | 
| 
      
 79 
     | 
    
         
            +
                @tm.value_stats.max.should be == 2
         
     | 
| 
       82 
80 
     | 
    
         
             
              end
         
     | 
| 
       83 
81 
     | 
    
         | 
| 
       84 
82 
     | 
    
         
             
              it "keeps track of the sum value" do
         
     | 
| 
       85 
83 
     | 
    
         
             
                3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       86 
     | 
    
         
            -
                @tm.timed_stats.sum.should  
     | 
| 
       87 
     | 
    
         
            -
                @tm.value_stats.sum.should == 3
         
     | 
| 
      
 84 
     | 
    
         
            +
                @tm.timed_stats.sum.should be_within(0.01).of(0.15)
         
     | 
| 
      
 85 
     | 
    
         
            +
                @tm.value_stats.sum.should be == 3
         
     | 
| 
       88 
86 
     | 
    
         
             
              end
         
     | 
| 
       89 
87 
     | 
    
         | 
| 
       90 
88 
     | 
    
         
             
              it "keeps track of the sum of squares value" do
         
     | 
| 
       91 
89 
     | 
    
         
             
                3.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       92 
     | 
    
         
            -
                @tm.timed_stats.sumsq.should  
     | 
| 
       93 
     | 
    
         
            -
                @tm.value_stats.sumsq.should == 5
         
     | 
| 
      
 90 
     | 
    
         
            +
                @tm.timed_stats.sumsq.should be_within(0.0005).of(0.0075)
         
     | 
| 
      
 91 
     | 
    
         
            +
                @tm.value_stats.sumsq.should be == 5
         
     | 
| 
       94 
92 
     | 
    
         
             
              end
         
     | 
| 
       95 
93 
     | 
    
         | 
| 
       96 
94 
     | 
    
         
             
              it "keeps track of the minimum start time of all the intervals" do
         
     | 
| 
       97 
95 
     | 
    
         
             
                f1 = Time.now.gmtime.to_f * 1000000
         
     | 
| 
       98 
96 
     | 
    
         
             
                5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
         
     | 
| 
       99 
97 
     | 
    
         
             
                f2 = Time.now.gmtime.to_f * 1000000
         
     | 
| 
       100 
     | 
    
         
            -
                @tm.sampling_start_time.should >= f1
         
     | 
| 
       101 
     | 
    
         
            -
                @tm.sampling_start_time.should < f2
         
     | 
| 
      
 98 
     | 
    
         
            +
                @tm.sampling_start_time.should be >= f1
         
     | 
| 
      
 99 
     | 
    
         
            +
                @tm.sampling_start_time.should be < f2
         
     | 
| 
       102 
100 
     | 
    
         
             
                # distance from now to start time should be greater than the distance from
         
     | 
| 
       103 
101 
     | 
    
         
             
                # the start to the min start_time
         
     | 
| 
       104 
102 
     | 
    
         
             
                (f2 - @tm.sampling_start_time).should > ( @tm.sampling_start_time - f1 )
         
     | 
| 
       105 
103 
     | 
    
         
             
              end
         
     | 
| 
       106 
104 
     | 
    
         | 
| 
       107 
105 
     | 
    
         
             
              it "keeps track of the last stop time of all the intervals" do
         
     | 
| 
       108 
     | 
    
         
            -
                f1 = Time.now.gmtime.to_f *  
     | 
| 
      
 106 
     | 
    
         
            +
                f1 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
       109 
107 
     | 
    
         
             
                5.times { @tm.start ; sleep 0.05 ; @tm.stop( 1 ) }
         
     | 
| 
       110 
     | 
    
         
            -
                 
     | 
| 
       111 
     | 
    
         
            -
                 
     | 
| 
       112 
     | 
    
         
            -
                @tm.sampling_stop_time.should  
     | 
| 
      
 108 
     | 
    
         
            +
                sleep 0.05
         
     | 
| 
      
 109 
     | 
    
         
            +
                f2 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
      
 110 
     | 
    
         
            +
                @tm.sampling_stop_time.should be > f1
         
     | 
| 
      
 111 
     | 
    
         
            +
                @tm.sampling_stop_time.should be <= f2
         
     | 
| 
       113 
112 
     | 
    
         
             
                # distance from now to max stop time time should be less than the distance
         
     | 
| 
       114 
113 
     | 
    
         
             
                # from the start to the max stop time
         
     | 
| 
       115 
114 
     | 
    
         
             
                (f2 - @tm.sampling_stop_time).should < ( @tm.sampling_stop_time - f1 )
         
     | 
| 
         @@ -123,41 +122,41 @@ describe Hitimes::TimedValueMetric do 
     | 
|
| 
       123 
122 
     | 
    
         
             
              it "can measure a block of code from an instance" do
         
     | 
| 
       124 
123 
     | 
    
         
             
                t = Hitimes::TimedValueMetric.new( 'measure a block' )
         
     | 
| 
       125 
124 
     | 
    
         
             
                3.times { t.measure( 1 ) { sleep 0.05 } }
         
     | 
| 
       126 
     | 
    
         
            -
                t.duration.should  
     | 
| 
       127 
     | 
    
         
            -
                t.timed_stats.count.should == 3
         
     | 
| 
       128 
     | 
    
         
            -
                t.value_stats.count.should == 3
         
     | 
| 
      
 125 
     | 
    
         
            +
                t.duration.should be_within(0.004).of(0.15)
         
     | 
| 
      
 126 
     | 
    
         
            +
                t.timed_stats.count.should be == 3
         
     | 
| 
      
 127 
     | 
    
         
            +
                t.value_stats.count.should be == 3
         
     | 
| 
       129 
128 
     | 
    
         
             
              end
         
     | 
| 
       130 
129 
     | 
    
         | 
| 
       131 
130 
     | 
    
         
             
              it "returns the value of the block when measuring" do
         
     | 
| 
       132 
131 
     | 
    
         
             
                t = Hitimes::TimedValueMetric.new( 'measure a block' )
         
     | 
| 
       133 
132 
     | 
    
         
             
                x = t.measure( 42 ) { sleep 0.05; 42 }
         
     | 
| 
       134 
     | 
    
         
            -
                t.duration.should  
     | 
| 
       135 
     | 
    
         
            -
                x.should == 42
         
     | 
| 
      
 133 
     | 
    
         
            +
                t.duration.should be_within(0.002).of(0.05)
         
     | 
| 
      
 134 
     | 
    
         
            +
                x.should be == 42
         
     | 
| 
       136 
135 
     | 
    
         
             
              end
         
     | 
| 
       137 
136 
     | 
    
         | 
| 
       138 
137 
     | 
    
         
             
              describe "#to_hash" do
         
     | 
| 
       139 
138 
     | 
    
         | 
| 
       140 
139 
     | 
    
         
             
                it "has name value" do
         
     | 
| 
       141 
140 
     | 
    
         
             
                  h = @tm.to_hash
         
     | 
| 
       142 
     | 
    
         
            -
                  h['name'].should == "test-timed-value-metric"
         
     | 
| 
      
 141 
     | 
    
         
            +
                  h['name'].should be == "test-timed-value-metric"
         
     | 
| 
       143 
142 
     | 
    
         
             
                end
         
     | 
| 
       144 
143 
     | 
    
         | 
| 
       145 
144 
     | 
    
         
             
                it "has an empty has for additional_data" do
         
     | 
| 
       146 
145 
     | 
    
         
             
                  h = @tm.to_hash
         
     | 
| 
       147 
     | 
    
         
            -
                  h['additional_data'].should == Hash.new
         
     | 
| 
       148 
     | 
    
         
            -
                  h['additional_data'].size.should == 0
         
     | 
| 
      
 146 
     | 
    
         
            +
                  h['additional_data'].should be == Hash.new
         
     | 
| 
      
 147 
     | 
    
         
            +
                  h['additional_data'].size.should be == 0
         
     | 
| 
       149 
148 
     | 
    
         
             
                end
         
     | 
| 
       150 
149 
     | 
    
         | 
| 
       151 
150 
     | 
    
         
             
                it "has a rate" do
         
     | 
| 
       152 
151 
     | 
    
         
             
                  5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       153 
152 
     | 
    
         
             
                  h = @tm.to_hash
         
     | 
| 
       154 
     | 
    
         
            -
                  h['rate'].should  
     | 
| 
      
 153 
     | 
    
         
            +
                  h['rate'].should be_within(1.0  ).of(40.0)
         
     | 
| 
       155 
154 
     | 
    
         
             
                end
         
     | 
| 
       156 
155 
     | 
    
         | 
| 
       157 
156 
     | 
    
         
             
                it "has a unit_count" do
         
     | 
| 
       158 
157 
     | 
    
         
             
                  5.times { |x| @tm.start ; sleep 0.05 ; @tm.stop( x ) }
         
     | 
| 
       159 
158 
     | 
    
         
             
                  h = @tm.to_hash
         
     | 
| 
       160 
     | 
    
         
            -
                  h['unit_count'].should ==  10
         
     | 
| 
      
 159 
     | 
    
         
            +
                  h['unit_count'].should be ==  10
         
     | 
| 
       161 
160 
     | 
    
         
             
                end
         
     | 
| 
       162 
161 
     | 
    
         | 
| 
       163 
162 
     | 
    
         
             
                fields = %w[ name additional_data sampling_start_time sampling_stop_time value_stats timed_stats rate unit_count ]
         
     | 
    
        data/spec/value_metric_spec.rb
    CHANGED
    
    | 
         @@ -1,6 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'hitimes/value_metric'
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       4 
2 
     | 
    
         | 
| 
       5 
3 
     | 
    
         
             
            describe Hitimes::ValueMetric do
         
     | 
| 
       6 
4 
     | 
    
         
             
              before( :each ) do
         
     | 
| 
         @@ -9,21 +7,21 @@ describe Hitimes::ValueMetric do 
     | 
|
| 
       9 
7 
     | 
    
         
             
              end
         
     | 
| 
       10 
8 
     | 
    
         | 
| 
       11 
9 
     | 
    
         
             
              it 'has a name' do
         
     | 
| 
       12 
     | 
    
         
            -
                @metric.name.should == "testing"
         
     | 
| 
      
 10 
     | 
    
         
            +
                @metric.name.should be == "testing"
         
     | 
| 
       13 
11 
     | 
    
         
             
              end
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
       15 
13 
     | 
    
         
             
              it "has associated data from initialization" do
         
     | 
| 
       16 
14 
     | 
    
         
             
                m = Hitimes::ValueMetric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
         
     | 
| 
       17 
     | 
    
         
            -
                m.additional_data['foo'].should == 'bar'
         
     | 
| 
       18 
     | 
    
         
            -
                m.additional_data['this'].should == 'that'
         
     | 
| 
      
 15 
     | 
    
         
            +
                m.additional_data['foo'].should be == 'bar'
         
     | 
| 
      
 16 
     | 
    
         
            +
                m.additional_data['this'].should be == 'that'
         
     | 
| 
       19 
17 
     | 
    
         | 
| 
       20 
18 
     | 
    
         
             
                m = Hitimes::ValueMetric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
         
     | 
| 
       21 
     | 
    
         
            -
                m.additional_data['foo'].should == 'bar'
         
     | 
| 
       22 
     | 
    
         
            -
                m.additional_data['this'].should == 'that'
         
     | 
| 
      
 19 
     | 
    
         
            +
                m.additional_data['foo'].should be == 'bar'
         
     | 
| 
      
 20 
     | 
    
         
            +
                m.additional_data['this'].should be == 'that'
         
     | 
| 
       23 
21 
     | 
    
         
             
              end
         
     | 
| 
       24 
22 
     | 
    
         | 
| 
       25 
23 
     | 
    
         
             
              it "calculates the mean of the measurements" do
         
     | 
| 
       26 
     | 
    
         
            -
                @metric.mean.should == 4.5
         
     | 
| 
      
 24 
     | 
    
         
            +
                @metric.mean.should be == 4.5
         
     | 
| 
       27 
25 
     | 
    
         
             
              end
         
     | 
| 
       28 
26 
     | 
    
         | 
| 
       29 
27 
     | 
    
         
             
              it "calculates the stddev of the measurements" do
         
     | 
| 
         @@ -32,27 +30,27 @@ describe Hitimes::ValueMetric do 
     | 
|
| 
       32 
30 
     | 
    
         | 
| 
       33 
31 
     | 
    
         
             
              it "returns 0.0 for stddev if there is no data" do
         
     | 
| 
       34 
32 
     | 
    
         
             
                m = Hitimes::ValueMetric.new('0-data')
         
     | 
| 
       35 
     | 
    
         
            -
                m.stddev.should == 0.0
         
     | 
| 
      
 33 
     | 
    
         
            +
                m.stddev.should be == 0.0
         
     | 
| 
       36 
34 
     | 
    
         
             
              end
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
36 
     | 
    
         
             
              it "keeps track of the sum of data" do
         
     | 
| 
       39 
     | 
    
         
            -
                @metric.sum.should == 45.0
         
     | 
| 
      
 37 
     | 
    
         
            +
                @metric.sum.should be == 45.0
         
     | 
| 
       40 
38 
     | 
    
         
             
              end
         
     | 
| 
       41 
39 
     | 
    
         | 
| 
       42 
40 
     | 
    
         
             
              it "keeps track of the sum of squars of data" do
         
     | 
| 
       43 
     | 
    
         
            -
                @metric.sumsq.should == 285.0
         
     | 
| 
      
 41 
     | 
    
         
            +
                @metric.sumsq.should be == 285.0
         
     | 
| 
       44 
42 
     | 
    
         
             
              end
         
     | 
| 
       45 
43 
     | 
    
         | 
| 
       46 
44 
     | 
    
         
             
              it "retuns 0.0 for mean if there is no data" do
         
     | 
| 
       47 
     | 
    
         
            -
                Hitimes::ValueMetric.new('0-data').mean.should == 0.0
         
     | 
| 
      
 45 
     | 
    
         
            +
                Hitimes::ValueMetric.new('0-data').mean.should be == 0.0
         
     | 
| 
       48 
46 
     | 
    
         
             
              end
         
     | 
| 
       49 
47 
     | 
    
         | 
| 
       50 
48 
     | 
    
         
             
              it "keeps track of the min value" do
         
     | 
| 
       51 
     | 
    
         
            -
                @metric.min.should == 0
         
     | 
| 
      
 49 
     | 
    
         
            +
                @metric.min.should be == 0
         
     | 
| 
       52 
50 
     | 
    
         
             
              end
         
     | 
| 
       53 
51 
     | 
    
         | 
| 
       54 
52 
     | 
    
         
             
              it "keeps track of the max value" do
         
     | 
| 
       55 
     | 
    
         
            -
                @metric.max.should == 9
         
     | 
| 
      
 53 
     | 
    
         
            +
                @metric.max.should be == 9
         
     | 
| 
       56 
54 
     | 
    
         
             
              end
         
     | 
| 
       57 
55 
     | 
    
         | 
| 
       58 
56 
     | 
    
         
             
              it "keeps track of the first start time of all the measurements" do
         
     | 
| 
         @@ -60,8 +58,8 @@ describe Hitimes::ValueMetric do 
     | 
|
| 
       60 
58 
     | 
    
         
             
                f1 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
       61 
59 
     | 
    
         
             
                10.times{ |x| m.measure( x ); sleep 0.1 }
         
     | 
| 
       62 
60 
     | 
    
         
             
                f2 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
       63 
     | 
    
         
            -
                m.sampling_start_time.should >= f1
         
     | 
| 
       64 
     | 
    
         
            -
                m.sampling_start_time.should < f2
         
     | 
| 
      
 61 
     | 
    
         
            +
                m.sampling_start_time.should be >= f1
         
     | 
| 
      
 62 
     | 
    
         
            +
                m.sampling_start_time.should be < f2
         
     | 
| 
       65 
63 
     | 
    
         
             
                # distance from now to start time should be greater than the distance from
         
     | 
| 
       66 
64 
     | 
    
         
             
                # the start to the min start_time
         
     | 
| 
       67 
65 
     | 
    
         
             
                (f2 - m.sampling_start_time).should > ( m.sampling_start_time - f1 )
         
     | 
| 
         @@ -72,8 +70,8 @@ describe Hitimes::ValueMetric do 
     | 
|
| 
       72 
70 
     | 
    
         
             
                f1 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
       73 
71 
     | 
    
         
             
                10.times {|x| m.measure( x ); sleep 0.1  }
         
     | 
| 
       74 
72 
     | 
    
         
             
                f2 = Time.now.gmtime.to_f * 1_000_000
         
     | 
| 
       75 
     | 
    
         
            -
                m.sampling_stop_time.should > f1
         
     | 
| 
       76 
     | 
    
         
            -
                m.sampling_stop_time.should <= f2
         
     | 
| 
      
 73 
     | 
    
         
            +
                m.sampling_stop_time.should be > f1
         
     | 
| 
      
 74 
     | 
    
         
            +
                m.sampling_stop_time.should be <= f2
         
     | 
| 
       77 
75 
     | 
    
         
             
                # distance from now to max stop time time should be less than the distance
         
     | 
| 
       78 
76 
     | 
    
         
             
                # from the start to the max stop time
         
     | 
| 
       79 
77 
     | 
    
         
             
                (f2 - m.sampling_stop_time).should < ( m.sampling_stop_time - f1 )
         
     | 
| 
         @@ -83,18 +81,18 @@ describe Hitimes::ValueMetric do 
     | 
|
| 
       83 
81 
     | 
    
         | 
| 
       84 
82 
     | 
    
         
             
                it "has name value" do
         
     | 
| 
       85 
83 
     | 
    
         
             
                  h = @metric.to_hash
         
     | 
| 
       86 
     | 
    
         
            -
                  h['name'].should == "testing"
         
     | 
| 
      
 84 
     | 
    
         
            +
                  h['name'].should be == "testing"
         
     | 
| 
       87 
85 
     | 
    
         
             
                end
         
     | 
| 
       88 
86 
     | 
    
         | 
| 
       89 
87 
     | 
    
         
             
                it "has an empty has for additional_data" do
         
     | 
| 
       90 
88 
     | 
    
         
             
                  h = @metric.to_hash
         
     | 
| 
       91 
     | 
    
         
            -
                  h['additional_data'].should == Hash.new
         
     | 
| 
       92 
     | 
    
         
            -
                  h['additional_data'].size.should == 0
         
     | 
| 
      
 89 
     | 
    
         
            +
                  h['additional_data'].should be == Hash.new
         
     | 
| 
      
 90 
     | 
    
         
            +
                  h['additional_data'].size.should be == 0
         
     | 
| 
       93 
91 
     | 
    
         
             
                end
         
     | 
| 
       94 
92 
     | 
    
         | 
| 
       95 
93 
     | 
    
         
             
                it "has the right sum" do
         
     | 
| 
       96 
94 
     | 
    
         
             
                  h = @metric.to_hash
         
     | 
| 
       97 
     | 
    
         
            -
                  h['sum'].should == 45
         
     | 
| 
      
 95 
     | 
    
         
            +
                  h['sum'].should be == 45
         
     | 
| 
       98 
96 
     | 
    
         
             
                end
         
     | 
| 
       99 
97 
     | 
    
         | 
| 
       100 
98 
     | 
    
         
             
                fields = ::Hitimes::Stats::STATS.dup + %w[ name additional_data sampling_start_time sampling_stop_time ]
         
     | 
    
        data/spec/version_spec.rb
    CHANGED
    
    | 
         @@ -1,33 +1,7 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
      
 1 
     | 
    
         
            +
            require "spec_helper"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe "Hitimes::Version" do
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                it "should have a minor number that is >= 0" do
         
     | 
| 
       9 
     | 
    
         
            -
                    Hitimes::Version::MINOR.should >= 0
         
     | 
| 
       10 
     | 
    
         
            -
                end 
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                it "should have a tiny number that is >= 0" do
         
     | 
| 
       13 
     | 
    
         
            -
                    Hitimes::Version::BUILD.should >= 0
         
     | 
| 
       14 
     | 
    
         
            -
                end 
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                it "should have an array representation" do
         
     | 
| 
       17 
     | 
    
         
            -
                    Hitimes::Version.to_a.should have(3).items
         
     | 
| 
       18 
     | 
    
         
            -
                end 
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                it "should have a string representation" do
         
     | 
| 
       21 
     | 
    
         
            -
                    Hitimes::Version.to_s.should match(/\d+\.\d+\.\d+/)
         
     | 
| 
       22 
     | 
    
         
            -
                end 
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                it "should have a hash representation" do
         
     | 
| 
       25 
     | 
    
         
            -
                  [ :major, :minor, :build ].each do |k|
         
     | 
| 
       26 
     | 
    
         
            -
                    Hitimes::Version.to_hash[k].should_not be_nil
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                it "should be accessable as a constant" do
         
     | 
| 
       31 
     | 
    
         
            -
                    Hitimes::VERSION.should match(/\d+\.\d+\.\d+/)
         
     | 
| 
       32 
     | 
    
         
            -
                end 
         
     | 
| 
      
 4 
     | 
    
         
            +
              it "should be accessable as a constant" do
         
     | 
| 
      
 5 
     | 
    
         
            +
                Hitimes::VERSION.should match(/\d+\.\d+\.\d+/)
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
       33 
7 
     | 
    
         
             
            end
         
     | 
    
        data/tasks/default.rake
    ADDED
    
    | 
         @@ -0,0 +1,267 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # vim: syntax=ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rake/clean'
         
     | 
| 
      
 3 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 4 
     | 
    
         
            +
            # If you want to Develop on this project just run 'rake develop' and you'll
         
     | 
| 
      
 5 
     | 
    
         
            +
            # have all you need to get going. If you want to use bundler for development,
         
     | 
| 
      
 6 
     | 
    
         
            +
            # then run 'rake develop:using_bundler'
         
     | 
| 
      
 7 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 8 
     | 
    
         
            +
            namespace :develop do
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              # Install all the development and runtime dependencies of this gem using the
         
     | 
| 
      
 11 
     | 
    
         
            +
              # gemspec.
         
     | 
| 
      
 12 
     | 
    
         
            +
              task :default do
         
     | 
| 
      
 13 
     | 
    
         
            +
                require 'rubygems/dependency_installer'
         
     | 
| 
      
 14 
     | 
    
         
            +
                installer = Gem::DependencyInstaller.new
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                This.set_coverage_gem
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                puts "Installing gem depedencies needed for development"
         
     | 
| 
      
 19 
     | 
    
         
            +
                This.platform_gemspec.dependencies.each do |dep|
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if dep.matching_specs.empty? then
         
     | 
| 
      
 21 
     | 
    
         
            +
                    puts "Installing : #{dep}"
         
     | 
| 
      
 22 
     | 
    
         
            +
                    installer.install dep
         
     | 
| 
      
 23 
     | 
    
         
            +
                  else
         
     | 
| 
      
 24 
     | 
    
         
            +
                    puts "Skipping   : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
                puts "\n\nNow run 'rake test'"
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              # Create a Gemfile that just references the gemspec
         
     | 
| 
      
 31 
     | 
    
         
            +
              file 'Gemfile' => :gemspec do
         
     | 
| 
      
 32 
     | 
    
         
            +
                File.open( "Gemfile", "w+" ) do |f|
         
     | 
| 
      
 33 
     | 
    
         
            +
                  f.puts 'source :rubygems'
         
     | 
| 
      
 34 
     | 
    
         
            +
                  f.puts 'gemspec'
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              desc "Create a bundler Gemfile"
         
     | 
| 
      
 39 
     | 
    
         
            +
              task :using_bundler => 'Gemfile' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                puts "Now you can 'bundle'"
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              # Gemfiles are build artifacts
         
     | 
| 
      
 44 
     | 
    
         
            +
              CLOBBER << FileList['Gemfile*']
         
     | 
| 
      
 45 
     | 
    
         
            +
            end
         
     | 
| 
      
 46 
     | 
    
         
            +
            desc "Boostrap development"
         
     | 
| 
      
 47 
     | 
    
         
            +
            task :develop => "develop:default"
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 50 
     | 
    
         
            +
            # Minitest - standard TestTask
         
     | 
| 
      
 51 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 52 
     | 
    
         
            +
            begin
         
     | 
| 
      
 53 
     | 
    
         
            +
              require 'rake/testtask'
         
     | 
| 
      
 54 
     | 
    
         
            +
              Rake::TestTask.new( :test ) do |t|
         
     | 
| 
      
 55 
     | 
    
         
            +
                t.ruby_opts    = %w[ -w -rubygems ]
         
     | 
| 
      
 56 
     | 
    
         
            +
                t.libs         = %w[ lib spec ]
         
     | 
| 
      
 57 
     | 
    
         
            +
                t.pattern      = "spec/**/*_spec.rb"
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              task :test_requirements
         
     | 
| 
      
 61 
     | 
    
         
            +
              task :test => :test_requirements
         
     | 
| 
      
 62 
     | 
    
         
            +
              task :default => :test
         
     | 
| 
      
 63 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 64 
     | 
    
         
            +
              This.task_warning( 'test' )
         
     | 
| 
      
 65 
     | 
    
         
            +
            end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 68 
     | 
    
         
            +
            # RDoc - standard rdoc rake task, although we must make sure to use a more
         
     | 
| 
      
 69 
     | 
    
         
            +
            #        recent version of rdoc since it is the one that has 'tomdoc' markup
         
     | 
| 
      
 70 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 71 
     | 
    
         
            +
            begin
         
     | 
| 
      
 72 
     | 
    
         
            +
              gem 'rdoc' # otherwise we get the wrong task from stdlib
         
     | 
| 
      
 73 
     | 
    
         
            +
              require 'rdoc/task'
         
     | 
| 
      
 74 
     | 
    
         
            +
              RDoc::Task.new do |t|
         
     | 
| 
      
 75 
     | 
    
         
            +
                t.markup   = 'tomdoc'
         
     | 
| 
      
 76 
     | 
    
         
            +
                t.rdoc_dir = 'doc'
         
     | 
| 
      
 77 
     | 
    
         
            +
                t.main     = 'README.rdoc'
         
     | 
| 
      
 78 
     | 
    
         
            +
                t.title    = "#{This.name} #{This.version}"
         
     | 
| 
      
 79 
     | 
    
         
            +
                t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
            rescue LoadError => le
         
     | 
| 
      
 82 
     | 
    
         
            +
              This.task_warning( 'rdoc' )
         
     | 
| 
      
 83 
     | 
    
         
            +
            end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 86 
     | 
    
         
            +
            # Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
         
     | 
| 
      
 87 
     | 
    
         
            +
            #            for the moment only rcov is listed.
         
     | 
| 
      
 88 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 89 
     | 
    
         
            +
            if RUBY_VERSION < "1.9.0"
         
     | 
| 
      
 90 
     | 
    
         
            +
              begin
         
     | 
| 
      
 91 
     | 
    
         
            +
               require 'rcov/rcovtask'
         
     | 
| 
      
 92 
     | 
    
         
            +
               Rcov::RcovTask.new( 'coverage' ) do |t|
         
     | 
| 
      
 93 
     | 
    
         
            +
                 t.libs      << 'spec'
         
     | 
| 
      
 94 
     | 
    
         
            +
                 t.pattern   = 'spec/**/*_spec.rb'
         
     | 
| 
      
 95 
     | 
    
         
            +
                 t.verbose   = true
         
     | 
| 
      
 96 
     | 
    
         
            +
                 t.rcov_opts << "-x ^/"           # remove all the global files
         
     | 
| 
      
 97 
     | 
    
         
            +
                 t.rcov_opts << "--sort coverage" # so we see the worst files at the top
         
     | 
| 
      
 98 
     | 
    
         
            +
               end
         
     | 
| 
      
 99 
     | 
    
         
            +
              rescue LoadError
         
     | 
| 
      
 100 
     | 
    
         
            +
               This.task_warning( 'rcov' )
         
     | 
| 
      
 101 
     | 
    
         
            +
              end
         
     | 
| 
      
 102 
     | 
    
         
            +
            else
         
     | 
| 
      
 103 
     | 
    
         
            +
              begin
         
     | 
| 
      
 104 
     | 
    
         
            +
                require 'simplecov'
         
     | 
| 
      
 105 
     | 
    
         
            +
                desc 'Run tests with code coverage'
         
     | 
| 
      
 106 
     | 
    
         
            +
                task :coverage do
         
     | 
| 
      
 107 
     | 
    
         
            +
                  ENV['COVERAGE'] = 'true'
         
     | 
| 
      
 108 
     | 
    
         
            +
                  Rake::Task[:test].execute
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
                CLOBBER << FileList["coverage"]
         
     | 
| 
      
 111 
     | 
    
         
            +
              rescue LoadError
         
     | 
| 
      
 112 
     | 
    
         
            +
                This.task_warning( 'simplecov' )
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
            end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 117 
     | 
    
         
            +
            # Manifest - We want an explicit list of thos files that are to be packaged in
         
     | 
| 
      
 118 
     | 
    
         
            +
            #            the gem. Most of this is from Hoe.
         
     | 
| 
      
 119 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 120 
     | 
    
         
            +
            namespace 'manifest' do
         
     | 
| 
      
 121 
     | 
    
         
            +
              desc "Check the manifest"
         
     | 
| 
      
 122 
     | 
    
         
            +
              task :check => :clean do
         
     | 
| 
      
 123 
     | 
    
         
            +
                files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
         
     | 
| 
      
 124 
     | 
    
         
            +
                files = files.select{ |f| File.file?( f ) }
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                tmp = "Manifest.tmp"
         
     | 
| 
      
 127 
     | 
    
         
            +
                File.open( tmp, 'w' ) do |f|
         
     | 
| 
      
 128 
     | 
    
         
            +
                  f.puts files.join("\n")
         
     | 
| 
      
 129 
     | 
    
         
            +
                end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                begin
         
     | 
| 
      
 132 
     | 
    
         
            +
                  sh "diff -du Manifest.txt #{tmp}"
         
     | 
| 
      
 133 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 134 
     | 
    
         
            +
                  rm tmp
         
     | 
| 
      
 135 
     | 
    
         
            +
                end
         
     | 
| 
      
 136 
     | 
    
         
            +
                puts "Manifest looks good"
         
     | 
| 
      
 137 
     | 
    
         
            +
              end
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
              desc "Generate the manifest"
         
     | 
| 
      
 140 
     | 
    
         
            +
              task :generate => :clean do
         
     | 
| 
      
 141 
     | 
    
         
            +
                files = %x[ git ls-files ].split("\n").sort
         
     | 
| 
      
 142 
     | 
    
         
            +
                files.reject! { |f| f =~ This.exclude_from_manifest }
         
     | 
| 
      
 143 
     | 
    
         
            +
                File.open( "Manifest.txt", "w" ) do |f|
         
     | 
| 
      
 144 
     | 
    
         
            +
                  f.puts files.join("\n")
         
     | 
| 
      
 145 
     | 
    
         
            +
                end
         
     | 
| 
      
 146 
     | 
    
         
            +
              end
         
     | 
| 
      
 147 
     | 
    
         
            +
            end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 150 
     | 
    
         
            +
            # Fixme - look for fixmes and report them
         
     | 
| 
      
 151 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 152 
     | 
    
         
            +
            namespace :fixme do
         
     | 
| 
      
 153 
     | 
    
         
            +
              task :default => 'manifest:check' do
         
     | 
| 
      
 154 
     | 
    
         
            +
                This.manifest.each do |file|
         
     | 
| 
      
 155 
     | 
    
         
            +
                  next if file == __FILE__
         
     | 
| 
      
 156 
     | 
    
         
            +
                  next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
         
     | 
| 
      
 157 
     | 
    
         
            +
                  puts "FIXME: Rename #{file}" if file =~ /fixme/i
         
     | 
| 
      
 158 
     | 
    
         
            +
                  IO.readlines( file ).each_with_index do |line, idx|
         
     | 
| 
      
 159 
     | 
    
         
            +
                    prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
         
     | 
| 
      
 160 
     | 
    
         
            +
                    puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
         
     | 
| 
      
 161 
     | 
    
         
            +
                  end
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
              end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
              def fixme_project_root
         
     | 
| 
      
 166 
     | 
    
         
            +
                This.project_path( '../fixme' )
         
     | 
| 
      
 167 
     | 
    
         
            +
              end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
              def fixme_project_path( subtree )
         
     | 
| 
      
 170 
     | 
    
         
            +
                fixme_project_root.join( subtree )
         
     | 
| 
      
 171 
     | 
    
         
            +
              end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
              def local_fixme_files
         
     | 
| 
      
 174 
     | 
    
         
            +
                This.manifest.select { |p| p =~ %r|^tasks/| }
         
     | 
| 
      
 175 
     | 
    
         
            +
              end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
              def outdated_fixme_files
         
     | 
| 
      
 178 
     | 
    
         
            +
                local_fixme_files.reject do |local|
         
     | 
| 
      
 179 
     | 
    
         
            +
                  upstream     = fixme_project_path( local )
         
     | 
| 
      
 180 
     | 
    
         
            +
                  Digest::SHA256.file( local ) == Digest::SHA256.file( upstream )
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
              end
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
              def fixme_up_to_date?
         
     | 
| 
      
 185 
     | 
    
         
            +
                outdated_fixme_files.empty?
         
     | 
| 
      
 186 
     | 
    
         
            +
              end
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
              desc "See if the fixme tools are outdated"
         
     | 
| 
      
 189 
     | 
    
         
            +
              task :outdated => :release_check do
         
     | 
| 
      
 190 
     | 
    
         
            +
                if fixme_up_to_date? then
         
     | 
| 
      
 191 
     | 
    
         
            +
                  puts "Fixme files are up to date."
         
     | 
| 
      
 192 
     | 
    
         
            +
                else
         
     | 
| 
      
 193 
     | 
    
         
            +
                  outdated_fixme_files.each do |f|
         
     | 
| 
      
 194 
     | 
    
         
            +
                    puts "#{f} is outdated"
         
     | 
| 
      
 195 
     | 
    
         
            +
                  end
         
     | 
| 
      
 196 
     | 
    
         
            +
                end
         
     | 
| 
      
 197 
     | 
    
         
            +
              end
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
              desc "Update outdated fixme files"
         
     | 
| 
      
 200 
     | 
    
         
            +
              task :update => :release_check do
         
     | 
| 
      
 201 
     | 
    
         
            +
                if fixme_up_to_date? then
         
     | 
| 
      
 202 
     | 
    
         
            +
                  puts "Fixme files are already up to date."
         
     | 
| 
      
 203 
     | 
    
         
            +
                else
         
     | 
| 
      
 204 
     | 
    
         
            +
                  puts "Updating fixme files:"
         
     | 
| 
      
 205 
     | 
    
         
            +
                  outdated_fixme_files.each do |local|
         
     | 
| 
      
 206 
     | 
    
         
            +
                    upstream = fixme_project_path( local )
         
     | 
| 
      
 207 
     | 
    
         
            +
                    puts "  * #{local}"
         
     | 
| 
      
 208 
     | 
    
         
            +
                    FileUtils.cp( upstream, local )
         
     | 
| 
      
 209 
     | 
    
         
            +
                  end
         
     | 
| 
      
 210 
     | 
    
         
            +
                  puts "Use your git commands as appropriate."
         
     | 
| 
      
 211 
     | 
    
         
            +
                end
         
     | 
| 
      
 212 
     | 
    
         
            +
              end
         
     | 
| 
      
 213 
     | 
    
         
            +
            end
         
     | 
| 
      
 214 
     | 
    
         
            +
            desc "Look for fixmes and report them"
         
     | 
| 
      
 215 
     | 
    
         
            +
            task :fixme => "fixme:default"
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 218 
     | 
    
         
            +
            # Gem Specification
         
     | 
| 
      
 219 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 220 
     | 
    
         
            +
            # Really this is only here to support those who use bundler
         
     | 
| 
      
 221 
     | 
    
         
            +
            desc "Build the #{This.name}.gemspec file"
         
     | 
| 
      
 222 
     | 
    
         
            +
            task :gemspec do
         
     | 
| 
      
 223 
     | 
    
         
            +
              File.open( This.gemspec_file, "wb+" ) do |f|
         
     | 
| 
      
 224 
     | 
    
         
            +
                f.write This.platform_gemspec.to_ruby
         
     | 
| 
      
 225 
     | 
    
         
            +
              end
         
     | 
| 
      
 226 
     | 
    
         
            +
            end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
            # the gemspec is also a dev artifact and should not be kept around.
         
     | 
| 
      
 229 
     | 
    
         
            +
            CLOBBER << This.gemspec_file.to_s
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
            # The standard gem packaging task, everyone has it.
         
     | 
| 
      
 232 
     | 
    
         
            +
            require 'rubygems/package_task'
         
     | 
| 
      
 233 
     | 
    
         
            +
            Gem::PackageTask.new( This.platform_gemspec ) do
         
     | 
| 
      
 234 
     | 
    
         
            +
              # nothing
         
     | 
| 
      
 235 
     | 
    
         
            +
            end
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 238 
     | 
    
         
            +
            # Release - the steps we go through to do a final release, this is pulled from
         
     | 
| 
      
 239 
     | 
    
         
            +
            #           a compbination of mojombo's rakegem, hoe and hoe-git
         
     | 
| 
      
 240 
     | 
    
         
            +
            #
         
     | 
| 
      
 241 
     | 
    
         
            +
            # 1) make sure we are on the master branch
         
     | 
| 
      
 242 
     | 
    
         
            +
            # 2) make sure there are no uncommitted items
         
     | 
| 
      
 243 
     | 
    
         
            +
            # 3) check the manifest and make sure all looks good
         
     | 
| 
      
 244 
     | 
    
         
            +
            # 4) build the gem
         
     | 
| 
      
 245 
     | 
    
         
            +
            # 5) do an empty commit to have the commit message of the version
         
     | 
| 
      
 246 
     | 
    
         
            +
            # 6) tag that commit as the version
         
     | 
| 
      
 247 
     | 
    
         
            +
            # 7) push master
         
     | 
| 
      
 248 
     | 
    
         
            +
            # 8) push the tag
         
     | 
| 
      
 249 
     | 
    
         
            +
            # 7) pus the gem
         
     | 
| 
      
 250 
     | 
    
         
            +
            #------------------------------------------------------------------------------
         
     | 
| 
      
 251 
     | 
    
         
            +
            task :release_check do
         
     | 
| 
      
 252 
     | 
    
         
            +
              unless `git branch` =~ /^\* master$/
         
     | 
| 
      
 253 
     | 
    
         
            +
                abort "You must be on the master branch to release!"
         
     | 
| 
      
 254 
     | 
    
         
            +
              end
         
     | 
| 
      
 255 
     | 
    
         
            +
              unless `git status` =~ /^nothing to commit/m
         
     | 
| 
      
 256 
     | 
    
         
            +
                abort "Nope, sorry, you have unfinished business"
         
     | 
| 
      
 257 
     | 
    
         
            +
              end
         
     | 
| 
      
 258 
     | 
    
         
            +
            end
         
     | 
| 
      
 259 
     | 
    
         
            +
             
     | 
| 
      
 260 
     | 
    
         
            +
            desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
         
     | 
| 
      
 261 
     | 
    
         
            +
            task :release => [ :release_check, 'manifest:check', :gem ] do
         
     | 
| 
      
 262 
     | 
    
         
            +
              sh "git commit --allow-empty -a -m 'Release #{This.version}'"
         
     | 
| 
      
 263 
     | 
    
         
            +
              sh "git tag -a -m 'v#{This.version}' v#{This.version}"
         
     | 
| 
      
 264 
     | 
    
         
            +
              sh "git push origin master"
         
     | 
| 
      
 265 
     | 
    
         
            +
              sh "git push origin v#{This.version}"
         
     | 
| 
      
 266 
     | 
    
         
            +
              sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
         
     | 
| 
      
 267 
     | 
    
         
            +
            end
         
     |