summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/ActivitySummary_spec.rb28
-rw-r--r--spec/FlexiTable_spec.rb8
-rw-r--r--spec/PostRunner_spec.rb65
-rw-r--r--spec/spec_helper.rb62
4 files changed, 106 insertions, 57 deletions
diff --git a/spec/ActivitySummary_spec.rb b/spec/ActivitySummary_spec.rb
new file mode 100644
index 0000000..4e92017
--- /dev/null
+++ b/spec/ActivitySummary_spec.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby -w
+# encoding: UTF-8
+#
+# = PostRunner_spec.rb -- PostRunner - Manage the data from your Garmin sport devices.
+#
+# Copyright (c) 2014 by Chris Schlaeger <cs@taskjuggler.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+
+require 'postrunner/ActivitySummary'
+require 'spec_helper'
+
+describe PostRunner::ActivitySummary do
+
+ before(:each) do
+ @as = PostRunner::ActivitySummary.new(
+ create_fit_activity('2014-08-26-19:00', 30), 'test', :metric)
+ end
+
+ it 'should create a metric summary' do
+ @as.to_s #TODO: Fix aggregation first
+ end
+
+end
+
diff --git a/spec/FlexiTable_spec.rb b/spec/FlexiTable_spec.rb
index f08e59a..5a03c56 100644
--- a/spec/FlexiTable_spec.rb
+++ b/spec/FlexiTable_spec.rb
@@ -19,7 +19,13 @@ describe PostRunner::FlexiTable do
row(%w( a bb ))
row(%w( ccc ddddd ))
end
- puts t.to_s
+ ref = <<EOT
++---+-----+
+|a |bb |
+|ccc|ddddd|
++---+-----+
+EOT
+ t.to_s.should == ref
end
end
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb
index 1fbfd05..9755a7c 100644
--- a/spec/PostRunner_spec.rb
+++ b/spec/PostRunner_spec.rb
@@ -13,6 +13,7 @@
require 'fileutils'
require 'postrunner/Main'
+require 'spec_helper'
describe PostRunner::Main do
@@ -25,62 +26,6 @@ describe PostRunner::Main do
stdout.string
end
- def create_fit_file(name, date)
- ts = Time.parse(date)
- a = Fit4Ruby::Activity.new({ :timestamp => ts })
- a.total_timer_time = 30 * 60
- a.new_user_profile({ :timestamp => ts,
- :age => 33, :height => 1.78, :weight => 73.0,
- :gender => 'male', :activity_class => 4.0,
- :max_hr => 178 })
-
- a.new_event({ :timestamp => ts, :event => 'timer',
- :event_type => 'start_time' })
- a.new_device_info({ :timestamp => ts, :device_index => 0 })
- a.new_device_info({ :timestamp => ts, :device_index => 1,
- :battery_status => 'ok' })
- 0.upto(a.total_timer_time / 60) do |mins|
- ts += 60
- a.new_record({
- :timestamp => ts,
- :position_lat => 51.5512 - mins * 0.0008,
- :position_long => 11.647 + mins * 0.002,
- :distance => 200.0 * mins,
- :altitude => 100 + mins * 0.5,
- :speed => 3.1,
- :vertical_oscillation => 9 + mins * 0.02,
- :stance_time => 235.0 * mins * 0.01,
- :stance_time_percent => 32.0,
- :heart_rate => 140 + mins,
- :cadence => 75,
- :activity_type => 'running',
- :fractional_cadence => (mins % 2) / 2.0
- })
-
- if mins > 0 && mins % 5 == 0
- a.new_lap({ :timestamp => ts })
- end
- end
- a.new_session({ :timestamp => ts })
- a.new_event({ :timestamp => ts, :event => 'recovery_time',
- :event_type => 'marker',
- :data => 2160 })
- a.new_event({ :timestamp => ts, :event => 'vo2max',
- :event_type => 'marker', :data => 52 })
- a.new_event({ :timestamp => ts, :event => 'timer',
- :event_type => 'stop_all' })
- a.new_device_info({ :timestamp => ts, :device_index => 0 })
- ts += 1
- a.new_device_info({ :timestamp => ts, :device_index => 1,
- :battery_status => 'low' })
- ts += 120
- a.new_event({ :timestamp => ts, :event => 'recovery_hr',
- :event_type => 'marker', :data => 132 })
-
- a.aggregate
- Fit4Ruby.write(name, a)
- end
-
before(:all) do
@db_dir = File.join(File.dirname(__FILE__), '.postrunner')
FileUtils.rm_rf(@db_dir)
@@ -169,5 +114,13 @@ describe PostRunner::Main do
postrunner(%w( dump FILE1.FIT ))
end
+ it 'should switch to statute units' do
+ postrunner(%w( units statute ))
+ end
+
+ it 'should switch back to metric units' do
+ postrunner(%w( units metric ))
+ end
+
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..cd6fec4
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,62 @@
+def create_fit_file(name, date, duration_minutes = 30)
+ Fit4Ruby.write(name, create_fit_activity(date, duration_minutes))
+end
+
+def create_fit_activity(date, duration_minutes)
+ ts = Time.parse(date)
+ a = Fit4Ruby::Activity.new({ :timestamp => ts })
+ a.total_timer_time = duration_minutes * 60
+ a.new_user_profile({ :timestamp => ts,
+ :age => 33, :height => 1.78, :weight => 73.0,
+ :gender => 'male', :activity_class => 4.0,
+ :max_hr => 178 })
+
+ a.new_event({ :timestamp => ts, :event => 'timer',
+ :event_type => 'start_time' })
+ a.new_device_info({ :timestamp => ts, :device_index => 0 })
+ a.new_device_info({ :timestamp => ts, :device_index => 1,
+ :battery_status => 'ok' })
+ 0.upto((a.total_timer_time / 60) - 1) do |mins|
+ a.new_record({
+ :timestamp => ts,
+ :position_lat => 51.5512 - mins * 0.0008,
+ :position_long => 11.647 + mins * 0.002,
+ :distance => 200.0 * mins,
+ :altitude => 100 + mins * 0.5,
+ :speed => 3.1,
+ :vertical_oscillation => 9 + mins * 0.02,
+ :stance_time => 235.0 * mins * 0.01,
+ :stance_time_percent => 32.0,
+ :heart_rate => 140 + mins,
+ :cadence => 75,
+ :activity_type => 'running',
+ :fractional_cadence => (mins % 2) / 2.0
+ })
+
+ ts += 60
+ if (mins + 1) % 5 == 0
+ a.new_lap({ :timestamp => ts })
+ end
+ end
+ a.new_session({ :timestamp => ts })
+ a.new_event({ :timestamp => ts, :event => 'recovery_time',
+ :event_type => 'marker',
+ :data => 2160 })
+ a.new_event({ :timestamp => ts, :event => 'vo2max',
+ :event_type => 'marker', :data => 52 })
+ a.new_event({ :timestamp => ts, :event => 'timer',
+ :event_type => 'stop_all' })
+ a.new_device_info({ :timestamp => ts, :device_index => 0 })
+ ts += 1
+ a.new_device_info({ :timestamp => ts, :device_index => 1,
+ :battery_status => 'low' })
+ ts += 120
+ a.new_event({ :timestamp => ts, :event => 'recovery_hr',
+ :event_type => 'marker', :data => 132 })
+
+ a.aggregate
+
+ a
+end
+
+