diff options
author | Chris Schlaeger <chris@linux.com> | 2015-10-26 19:15:47 +0100 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2015-10-26 19:15:47 +0100 |
commit | 5590faccc2c96f5038463685407ea4e468c056c8 (patch) | |
tree | 3b1a43c9d99300463aeaf13f5f4523a10a5b190a /spec | |
parent | 23f180afce6c6089b9c671974611130b999a817f (diff) | |
download | postrunner-5590faccc2c96f5038463685407ea4e468c056c8.zip |
Add data sources table to activity view.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/PostRunner_spec.rb | 45 | ||||
-rw-r--r-- | spec/spec_helper.rb | 38 |
2 files changed, 56 insertions, 27 deletions
diff --git a/spec/PostRunner_spec.rb b/spec/PostRunner_spec.rb index 4ca5a4a..59c5d0e 100644 --- a/spec/PostRunner_spec.rb +++ b/spec/PostRunner_spec.rb @@ -27,26 +27,25 @@ describe PostRunner::Main do 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') + @work_dir = tmp_dir_name(__FILE__) + Dir.mkdir(@work_dir) + @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') end after(:all) do - FileUtils.rm_rf(@db_dir) - FileUtils.rm_rf('FILE1.FIT') - FileUtils.rm_rf('FILE2.FIT') - FileUtils::rm_rf('icons') + FileUtils.rm_rf(@work_dir) end it 'should abort without arguments' do - lambda { postrunner([]) }.should raise_error SystemExit + lambda { postrunner([]) }.should raise_error Fit4Ruby::Error end it 'should abort with bad command' do - lambda { postrunner(%w( foobar)) }.should raise_error SystemExit + lambda { postrunner(%w( foobar)) }.should raise_error Fit4Ruby::Error end it 'should support the -v option' do @@ -54,7 +53,7 @@ describe PostRunner::Main do end it 'should check a FIT file' do - postrunner(%w( check FILE1.FIT )) + postrunner([ 'check', @file1 ]) end it 'should list and empty archive' do @@ -62,7 +61,7 @@ describe PostRunner::Main do end it 'should import a FIT file' do - postrunner(%w( import FILE1.FIT )) + postrunner([ 'import', @file1 ]) end it 'should check the imported file' do @@ -70,20 +69,20 @@ describe PostRunner::Main do end it 'should check a FIT file' do - postrunner(%w( check FILE2.FIT )) + postrunner([ 'check', @file2 ]) end it 'should list the imported file' do - postrunner(%w( list )).index('FILE1.FIT').should be_a(Fixnum) + postrunner(%w( list )).index('FILE1').should be_a(Fixnum) end it 'should import the other FIT file' do - postrunner([ 'import', '.' ]) + postrunner([ 'import', @work_dir ]) list = postrunner(%w( list )) list.index('FILE1.FIT').should be_a(Fixnum) list.index('FILE2.FIT').should be_a(Fixnum) rc = YAML::load_file(File.join(@db_dir, 'config.yml')) - rc[:import_dir].should == '.' + rc[:import_dir].should == @work_dir template = "<a href=\"%s.html\"><img src=\"icons/%s.png\" " + "class=\"active_button\">" @@ -110,18 +109,18 @@ describe PostRunner::Main do it 'should rename FILE2.FIT activity' do postrunner(%w( rename foobar :1 )) list = postrunner(%w( list )) - list.index('FILE2.FIT').should be_nil + list.index(@file2).should be_nil list.index('foobar').should be_a(Fixnum) end it 'should fail when setting bad attribute' do - lambda { postrunner(%w( set foo bar :1)) }.should raise_error SystemExit + lambda { postrunner(%w( set foo bar :1)) }.should raise_error Fit4Ruby::Error end it 'should set name for FILE2.FIT activity' do postrunner(%w( set name foobar :1 )) list = postrunner(%w( list )) - list.index('FILE2.FIT').should be_nil + list.index(@file2).should be_nil list.index('foobar').should be_a(Fixnum) end @@ -133,7 +132,7 @@ describe PostRunner::Main do end it 'should fail when setting bad activity type' do - lambda { postrunner(%w( set type foobar :1)) }.should raise_error SystemExit + lambda { postrunner(%w( set type foobar :1)) }.should raise_error Fit4Ruby::Error end it 'should set activity subtype for FILE2.FIT activity' do @@ -144,7 +143,7 @@ describe PostRunner::Main do end it 'should fail when setting bad activity subtype' do - lambda { postrunner(%w( set subtype foobar :1)) }.should raise_error SystemExit + lambda { postrunner(%w( set subtype foobar :1)) }.should raise_error Fit4Ruby::Error end it 'should dump an activity from the archive' do @@ -152,7 +151,7 @@ describe PostRunner::Main do end it 'should dump a FIT file' do - postrunner(%w( dump FILE1.FIT )) + postrunner([ 'dump', @file1 ]) end it 'should switch to statute units' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e91cffd..dbb1e0e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,20 +10,44 @@ # published by the Free Software Foundation. # +require 'tmpdir' +require 'fileutils' + # Some dependencies may not be installed as Ruby Gems but as local sources. # Add them and the postrunner dir to the LOAD_PATH. %w( postrunner fit4ruby perobs ).each do |lib_dir| $:.unshift(File.join(File.dirname(__FILE__), '..', '..', lib_dir, 'lib')) end +def tmp_dir_name(caller_file) + begin + dir_name = File.join(Dir.tmpdir, + "#{File.basename(caller_file)}.#{rand(2**32)}") + end while File.exists?(dir_name) + + dir_name +end + def create_fit_file(name, date, duration_minutes = 30) - Fit4Ruby.write(name, create_fit_activity(date, duration_minutes)) + Fit4Ruby.write(name, create_fit_activity( + { :t => date, :duration => duration_minutes })) +end + +def create_fit_activity_file(dir, config) + activity = create_fit_activity(config) + end_time = activity.sessions[-1].start_time + + activity.sessions[-1].total_elapsed_time + fit_file_name = File.join(dir, Fit4Ruby::FileNameCoder.encode(end_time)) + Fit4Ruby.write(fit_file_name, activity) + + fit_file_name end -def create_fit_activity(date, duration_minutes) - ts = Time.parse(date) +def create_fit_activity(config) + ts = Time.parse(config[:t]) + serial = config[:serial] || 12345890 a = Fit4Ruby::Activity.new({ :timestamp => ts }) - a.total_timer_time = duration_minutes * 60 + a.total_timer_time = (config[:duration] || 10) * 60 a.new_user_profile({ :timestamp => ts, :age => 33, :height => 1.78, :weight => 73.0, :gender => 'male', :activity_class => 7.0, @@ -32,8 +56,11 @@ def create_fit_activity(date, duration_minutes) a.new_event({ :timestamp => ts, :event => 'timer', :event_type => 'start_time' }) a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin', + :garmin_product => 'fenix3', + :serial_number => serial, :device_index => 0 }) a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin', + :garmin_product => 'sdm4', :device_index => 1, :battery_status => 'ok' }) laps = 0 0.upto((a.total_timer_time / 60) - 1) do |mins| @@ -69,9 +96,12 @@ def create_fit_activity(date, duration_minutes) a.new_event({ :timestamp => ts, :event => 'timer', :event_type => 'stop_all' }) a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin', + :garmin_product => 'fenix3', + :serial_number => serial, :device_index => 0 }) ts += 1 a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin', + :garmin_product => 'sdm4', :device_index => 1, :battery_status => 'low' }) ts += 120 a.new_event({ :timestamp => ts, :event => 'recovery_hr', |