summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/PostRunner_spec.rb59
-rw-r--r--spec/spec_helper.rb7
2 files changed, 47 insertions, 19 deletions
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb
index 24ae0fa..437438e 100644
--- a/spec/PostRunner_spec.rb
+++ b/spec/PostRunner_spec.rb
@@ -21,6 +21,8 @@ describe PostRunner::Main do
args = [ '--dbdir', @db_dir ] + args
old_stdout = $stdout
$stdout = (stdout = StringIO.new)
+ @postrunner = nil
+ GC.start
@postrunner = PostRunner::Main.new(args)
$stdout = old_stdout
stdout.string
@@ -31,10 +33,13 @@ describe PostRunner::Main do
create_working_dirs
@db_dir = File.join(@work_dir, '.postrunner')
- @file1 = File.join(@work_dir, 'FILE1.FIT')
- @file2 = File.join(@work_dir, 'FILE2.FIT')
- create_fit_file(@file1, '2014-07-01-8:00')
- create_fit_file(@file2, '2014-07-02-8:00')
+ @opts = { :t => '2014-07-01-8:00', :speed => 11.0 }
+ @file1 = create_fit_activity_file(@work_dir, @opts)
+ @opts[:t] = '2014-07-02-8:00'
+ @file2 = create_fit_activity_file(@work_dir, @opts)
+ @opts[:t] = '2014-07-03-8:00'
+ @opts[:speed] = 12.5
+ @file3 = create_fit_activity_file(@work_dir, @opts)
end
after(:all) do
@@ -74,34 +79,34 @@ describe PostRunner::Main do
end
it 'should list the imported file' do
- expect(postrunner(%w( list )).index('FILE1')).to be_a(Fixnum)
+ expect(postrunner(%w( list )).index(File.basename(@file1))).to be_a(Fixnum)
end
- it 'should import the other FIT file' do
- postrunner([ 'import', @work_dir ])
+ it 'should import the 2nd FIT file' do
+ postrunner([ 'import', @file2 ])
list = postrunner(%w( list ))
- expect(list.index('FILE1.FIT')).to be_a(Fixnum)
- expect(list.index('FILE2.FIT')).to be_a(Fixnum)
+ expect(list.index(File.basename(@file1))).to be_a(Fixnum)
+ expect(list.index(File.basename(@file2))).to be_a(Fixnum)
end
it 'should delete the first file' do
postrunner(%w( delete :2 ))
list = postrunner(%w( list ))
- expect(list.index('FILE1.FIT')).to be_nil
- expect(list.index('FILE2.FIT')).to be_a(Fixnum)
+ expect(list.index(File.basename(@file1))).to be_nil
+ expect(list.index(File.basename(@file2))).to be_a(Fixnum)
end
it 'should not import the deleted file again' do
- postrunner(%w( import . ))
+ postrunner([ 'import', @file1 ])
list = postrunner(%w( list ))
- expect(list.index('FILE1.FIT')).to be_nil
- expect(list.index('FILE2.FIT')).to be_a(Fixnum)
+ expect(list.index(File.basename(@file1))).to be_nil
+ expect(list.index(File.basename(@file2))).to be_a(Fixnum)
end
it 'should rename FILE2.FIT activity' do
postrunner(%w( rename foobar :1 ))
list = postrunner(%w( list ))
- expect(list.index('FILE2.FIT')).to be_nil
+ expect(list.index(File.basename(@file2))).to be_nil
expect(list.index('foobar')).to be_a(Fixnum)
end
@@ -109,14 +114,14 @@ describe PostRunner::Main do
expect { postrunner(%w( set foo bar :1)) }.to raise_error(Fit4Ruby::Error)
end
- it 'should set name for FILE2.FIT activity' do
+ it 'should set name for 2nd activity' do
postrunner(%w( set name foobar :1 ))
list = postrunner(%w( list ))
expect(list.index(@file2)).to be_nil
expect(list.index('foobar')).to be_a(Fixnum)
end
- it 'should set activity type for FILE2.FIT activity' do
+ it 'should set activity type for 2nd activity' do
postrunner(%w( set type Cycling :1 ))
list = postrunner(%w( summary :1 ))
expect(list.index('Running')).to be_nil
@@ -162,5 +167,25 @@ describe PostRunner::Main do
postrunner(%w( units metric ))
end
+ it 'should list records' do
+ # Add slow running activity
+ postrunner([ 'import', '--force', @file1 ])
+ list = postrunner([ 'records' ])
+ expect(list.index(File.basename(@file1))).to be_a(Fixnum)
+
+ # Add fast running activity
+ postrunner([ 'import', @file3 ])
+ list = postrunner([ 'records' ])
+ expect(list.index(File.basename(@file3))).to be_a(Fixnum)
+ expect(list.index(File.basename(@file1))).to be_nil
+ end
+
+ it 'should ignore records of an activity' do
+ postrunner(%w( set norecord true :1 ))
+ list = postrunner([ 'records' ])
+ expect(list.index(File.basename(@file1))).to be_a(Fixnum)
+ expect(list.index(File.basename(@file3))).to be_nil
+ end
+
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dba6be6..2d93e12 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -96,14 +96,17 @@ def create_fit_activity(config)
:garmin_product => 'sdm4',
:device_index => 1, :battery_status => 'ok' })
laps = 0
+ curr_speed = (config[:speed] ? config[:speed] : 10.0) / 3.6 # as m/s
+ curr_distance = 0.0 # as m
0.upto((a.total_timer_time / 60) - 1) do |mins|
+ curr_speed -= 0.05 if curr_speed > 2.5
a.new_record({
:timestamp => ts,
:position_lat => 51.5512 - mins * 0.0008,
:position_long => 11.647 + mins * 0.002,
- :distance => 200.0 * mins,
+ :distance => curr_distance += curr_speed * 60,
:altitude => 100 + mins * 3,
- :speed => 3.1,
+ :speed => curr_speed,
:vertical_oscillation => 90 + mins * 0.2,
:stance_time => 235.0 * mins * 0.01,
:stance_time_percent => 32.0,