summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-08-02 22:32:04 +0200
committerChris Schlaeger <chris@linux.com>2014-08-02 22:32:04 +0200
commitb9eaf5d4bc366e2f13921bac49017801ce4d6449 (patch)
tree3d16b29f63c14d8def9f0da9706081a9eeda9eee /spec
parent70f54be360a7d0f55ceec1636e0fea9447c2b83c (diff)
downloadpostrunner-b9eaf5d4bc366e2f13921bac49017801ce4d6449.zip
Adding personal record management
Diffstat (limited to 'spec')
-rw-r--r--spec/FlexiTable_spec.rb14
-rw-r--r--spec/PostRunner_spec.rb122
2 files changed, 136 insertions, 0 deletions
diff --git a/spec/FlexiTable_spec.rb b/spec/FlexiTable_spec.rb
new file mode 100644
index 0000000..dedc9cb
--- /dev/null
+++ b/spec/FlexiTable_spec.rb
@@ -0,0 +1,14 @@
+require 'postrunner/FlexiTable'
+
+describe PostRunner::FlexiTable do
+
+ it 'should create a simple ASCII table' do
+ t = PostRunner::FlexiTable.new do
+ row(%w( a bb ))
+ row(%w( ccc ddddd ))
+ end
+ puts t.to_s
+ end
+
+end
+
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb
new file mode 100644
index 0000000..cd21f7c
--- /dev/null
+++ b/spec/PostRunner_spec.rb
@@ -0,0 +1,122 @@
+require 'fileutils'
+
+require 'postrunner/Main'
+
+describe PostRunner::Main do
+
+ def postrunner(args)
+ args = [ '--dbdir', @db_dir ] + args
+ old_stdout = $stdout
+ $stdout = (stdout = StringIO.new)
+ PostRunner::Main.new(args)
+ $stdout = old_stdout
+ stdout.string
+ end
+
+ def create_fit_file(name, date)
+ a = Fit4Ruby::Activity.new
+ a.timestamp = Time.parse(date)
+ a.total_timer_time = 30 * 60
+ 0.upto(30) do |mins|
+ r = a.new_record
+ r.timestamp = a.timestamp + mins * 60
+ r.distance = 200.0 * mins
+ r.cadence = 75
+
+ if mins > 0 && mins % 5 == 0
+ s = a.new_lap
+ end
+ end
+ a.new_session
+ a.aggregate
+ Fit4Ruby.write(name, a)
+ end
+
+ before(:all) do
+ @db_dir = File.join(File.dirname(__FILE__), '.postrunner')
+ FileUtils.rm_rf(@db_dir)
+ FileUtils.rm_rf('FILE1.FIT')
+ create_fit_file('FILE1.FIT', '2014-07-01-8:00')
+ create_fit_file('FILE2.FIT', '2014-07-02-8:00')
+ end
+
+ after(:all) do
+ FileUtils.rm_rf(@db_dir)
+ FileUtils.rm_rf('FILE1.FIT')
+ FileUtils.rm_rf('FILE2.FIT')
+ end
+
+ it 'should abort without arguments' do
+ lambda { postrunner([]) }.should raise_error SystemExit
+ end
+
+ it 'should abort with bad command' do
+ lambda { postrunner(%w( foobar)) }.should raise_error SystemExit
+ end
+
+ it 'should support the -v option' do
+ postrunner(%w( --version ))
+ end
+
+ it 'should check a FIT file' do
+ postrunner(%w( check FILE1.FIT ))
+ end
+
+ it 'should list and empty archive' do
+ postrunner(%w( list ))
+ end
+
+ it 'should import a FIT file' do
+ postrunner(%w( import FILE1.FIT ))
+ end
+
+ it 'should check the imported file' do
+ postrunner(%w( check :1 ))
+ end
+
+ it 'should check a FIT file' do
+ postrunner(%w( check FILE2.FIT ))
+ end
+
+ it 'should list the imported file' do
+ postrunner(%w( list )).index('FILE1.FIT').should be_a(Fixnum)
+ end
+
+ it 'should import another FIT file' do
+ postrunner(%w( import FILE2.FIT ))
+ list = postrunner(%w( list ))
+ list.index('FILE1.FIT').should be_a(Fixnum)
+ list.index('FILE2.FIT').should be_a(Fixnum)
+ end
+
+ it 'should delete the first file' do
+ postrunner(%w( delete :2 ))
+ list = postrunner(%w( list ))
+ list.index('FILE1.FIT').should be_nil
+ list.index('FILE2.FIT').should be_a(Fixnum)
+ end
+
+ it 'should not import the deleted file again' do
+ postrunner(%w( import . ))
+ list = postrunner(%w( list ))
+ list.index('FILE1.FIT').should be_nil
+ list.index('FILE2.FIT').should be_a(Fixnum)
+ end
+
+ it 'should rename FILE2.FIT activity' do
+ postrunner(%w( rename :1 --name foobar ))
+ list = postrunner(%w( list ))
+ list.index('FILE2.FIT').should be_nil
+ list.index('foobar').should be_a(Fixnum)
+ end
+
+ it 'should dump an activity from the archive' do
+ postrunner(%w( dump :1 ))
+ end
+
+ it 'should dump a FIT file' do
+ postrunner(%w( dump FILE1.FIT ))
+ end
+
+end
+