Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added rcov and added specs

  • Loading branch information...
commit 01d465243c6dd7a23e21555de3982d59ec2e7d85 1 parent 05b7d70
@barttenbrinke barttenbrinke authored
View
1  .gitignore
@@ -7,3 +7,4 @@ requests.db
/tmp
/classes
/files
+/coverage
View
3  Rakefile
@@ -1,4 +1,3 @@
Dir[File.dirname(__FILE__) + "/tasks/*.rake"].each { |file| load(file) }
-task :default => :spec
-
+task :default => :spec
View
75 spec/unit/tracker/hourly_spread_spec.rb
@@ -0,0 +1,75 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe RequestLogAnalyzer::Tracker::HourlySpread do
+
+ include RequestLogAnalyzer::Spec::Helper
+
+ before(:each) do
+ @tracker = RequestLogAnalyzer::Tracker::HourlySpread.new
+ @tracker.prepare
+ end
+
+ it "should store timestamps correctly" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+
+ @tracker.request_time_graph[0].should eql(3)
+ end
+
+ it "should count the number of timestamps correctly" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+ @tracker.update(request(:timestamp => 20090103010000))
+
+ @tracker.total_requests.should eql(4)
+ end
+
+ it "should set the first request timestamp correctly" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+
+ @tracker.first_timestamp.should == DateTime.parse('Januari 1, 2009 00:00:00')
+ end
+
+ it "should set the last request timestamp correctly" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+
+ @tracker.last_timestamp.should == DateTime.parse('Januari 3, 2009 00:00:00')
+ end
+
+ it "should return the correct timespan in days when multiple requests are given" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+
+ @tracker.timespan.should == 2
+ end
+
+end
+
+describe RequestLogAnalyzer::Tracker::HourlySpread, 'reporting' do
+
+ include RequestLogAnalyzer::Spec::Helper
+
+ before(:each) do
+ @tracker = RequestLogAnalyzer::Tracker::HourlySpread.new
+ @tracker.prepare
+ end
+
+ it "should generate a report without errors when no request was tracked" do
+ lambda { @tracker.report(mock_output) }.should_not raise_error
+ end
+
+ it "should generate a report without errors when multiple requests were tracked" do
+ @tracker.update(request(:timestamp => 20090102000000))
+ @tracker.update(request(:timestamp => 20090101000000))
+ @tracker.update(request(:timestamp => 20090103000000))
+ @tracker.update(request(:timestamp => 20090103010000))
+ lambda { @tracker.report(mock_output) }.should_not raise_error
+ end
+end
View
1  spec/unit/tracker/timespan_tracker_spec.rb
@@ -59,6 +59,7 @@
it "should generate a report without errors when multiple requests were tracked" do
@tracker.update(request(:category => 'a', :timestamp => 20090102000000))
@tracker.update(request(:category => 'a', :timestamp => 20090101000000))
+ @tracker.update(request(:category => 'a', :timestamp => 20090103000000))
lambda { @tracker.report(mock_output) }.should_not raise_error
end
end
View
12 tasks/rspec.rake
@@ -0,0 +1,12 @@
+require 'rake'
+require 'spec/rake/spectask'
+
+namespace :spec do
+ desc "Run all rspec with RCov"
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.