Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added rcov and added specs

  • Loading branch information...
commit 01d465243c6dd7a23e21555de3982d59ec2e7d85 1 parent 05b7d70
Bart ten Brinke barttenbrinke authored
1  .gitignore
@@ -7,3 +7,4 @@ requests.db
7 7 /tmp
8 8 /classes
9 9 /files
  10 +/coverage
3  Rakefile
... ... @@ -1,4 +1,3 @@
1 1 Dir[File.dirname(__FILE__) + "/tasks/*.rake"].each { |file| load(file) }
2 2
3   -task :default => :spec
4   -
  3 +task :default => :spec
75 spec/unit/tracker/hourly_spread_spec.rb
... ... @@ -0,0 +1,75 @@
  1 +require File.dirname(__FILE__) + '/../../spec_helper'
  2 +
  3 +describe RequestLogAnalyzer::Tracker::HourlySpread do
  4 +
  5 + include RequestLogAnalyzer::Spec::Helper
  6 +
  7 + before(:each) do
  8 + @tracker = RequestLogAnalyzer::Tracker::HourlySpread.new
  9 + @tracker.prepare
  10 + end
  11 +
  12 + it "should store timestamps correctly" do
  13 + @tracker.update(request(:timestamp => 20090102000000))
  14 + @tracker.update(request(:timestamp => 20090101000000))
  15 + @tracker.update(request(:timestamp => 20090103000000))
  16 +
  17 + @tracker.request_time_graph[0].should eql(3)
  18 + end
  19 +
  20 + it "should count the number of timestamps correctly" do
  21 + @tracker.update(request(:timestamp => 20090102000000))
  22 + @tracker.update(request(:timestamp => 20090101000000))
  23 + @tracker.update(request(:timestamp => 20090103000000))
  24 + @tracker.update(request(:timestamp => 20090103010000))
  25 +
  26 + @tracker.total_requests.should eql(4)
  27 + end
  28 +
  29 + it "should set the first request timestamp correctly" do
  30 + @tracker.update(request(:timestamp => 20090102000000))
  31 + @tracker.update(request(:timestamp => 20090101000000))
  32 + @tracker.update(request(:timestamp => 20090103000000))
  33 +
  34 + @tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
  35 + end
  36 +
  37 + it "should set the last request timestamp correctly" do
  38 + @tracker.update(request(:timestamp => 20090102000000))
  39 + @tracker.update(request(:timestamp => 20090101000000))
  40 + @tracker.update(request(:timestamp => 20090103000000))
  41 +
  42 + @tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
  43 + end
  44 +
  45 + it "should return the correct timespan in days when multiple requests are given" do
  46 + @tracker.update(request(:timestamp => 20090102000000))
  47 + @tracker.update(request(:timestamp => 20090101000000))
  48 + @tracker.update(request(:timestamp => 20090103000000))
  49 +
  50 + @tracker.timespan.should == 2
  51 + end
  52 +
  53 +end
  54 +
  55 +describe RequestLogAnalyzer::Tracker::HourlySpread, 'reporting' do
  56 +
  57 + include RequestLogAnalyzer::Spec::Helper
  58 +
  59 + before(:each) do
  60 + @tracker = RequestLogAnalyzer::Tracker::HourlySpread.new
  61 + @tracker.prepare
  62 + end
  63 +
  64 + it "should generate a report without errors when no request was tracked" do
  65 + lambda { @tracker.report(mock_output) }.should_not raise_error
  66 + end
  67 +
  68 + it "should generate a report without errors when multiple requests were tracked" do
  69 + @tracker.update(request(:timestamp => 20090102000000))
  70 + @tracker.update(request(:timestamp => 20090101000000))
  71 + @tracker.update(request(:timestamp => 20090103000000))
  72 + @tracker.update(request(:timestamp => 20090103010000))
  73 + lambda { @tracker.report(mock_output) }.should_not raise_error
  74 + end
  75 +end
1  spec/unit/tracker/timespan_tracker_spec.rb
@@ -59,6 +59,7 @@
59 59 it "should generate a report without errors when multiple requests were tracked" do
60 60 @tracker.update(request(:category => 'a', :timestamp => 20090102000000))
61 61 @tracker.update(request(:category => 'a', :timestamp => 20090101000000))
  62 + @tracker.update(request(:category => 'a', :timestamp => 20090103000000))
62 63 lambda { @tracker.report(mock_output) }.should_not raise_error
63 64 end
64 65 end
12 tasks/rspec.rake
... ... @@ -0,0 +1,12 @@
  1 +require 'rake'
  2 +require 'spec/rake/spectask'
  3 +
  4 +namespace :spec do
  5 + desc "Run all rspec with RCov"
  6 + Spec::Rake::SpecTask.new(:rcov) do |t|
  7 +
  8 + t.spec_files = FileList['spec/**/*_spec.rb']
  9 + t.rcov = true
  10 + t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
  11 + end
  12 +end

0 comments on commit 01d4652

Please sign in to comment.
Something went wrong with that request. Please try again.