summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2016-01-03 21:24:36 +0100
committerChris Schlaeger <chris@linux.com>2016-01-03 21:24:36 +0100
commit998bc46bdf995963a237fccf51e75317d08cd608 (patch)
treefe57a6ab39f0a2dbad209ceb5e6ec95324a9a720 /spec/spec_helper.rb
parent54719ca934e1b01dca10344bd3b392c686528a89 (diff)
downloadpostrunner-998bc46bdf995963a237fccf51e75317d08cd608.zip
Big refactoring to switch to PEROBS database.
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dbb1e0e..dba6be6 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -19,6 +19,16 @@ require 'fileutils'
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', lib_dir, 'lib'))
end
+require 'fit4ruby'
+require 'perobs'
+require 'postrunner/FitFileStore'
+require 'postrunner/PersonalRecords'
+
+def capture_stdio
+ @log = StringIO.new
+ Fit4Ruby::Log.open(@log)
+end
+
def tmp_dir_name(caller_file)
begin
dir_name = File.join(Dir.tmpdir,
@@ -28,6 +38,29 @@ def tmp_dir_name(caller_file)
dir_name
end
+def create_working_dirs
+ @work_dir = tmp_dir_name(__FILE__)
+ Dir.mkdir(@work_dir)
+ @fit_dir = File.join(@work_dir, 'fit')
+ Dir.mkdir(@fit_dir)
+ @html_dir = File.join(@work_dir, 'html')
+ Dir.mkdir(@html_dir)
+end
+
+def cleanup
+ FileUtils.rm_rf(@work_dir)
+end
+
+def create_fit_file_store
+ store = PEROBS::Store.new(File.join(@work_dir, 'db'))
+ store['config'] = store.new(PEROBS::Hash)
+ store['config']['data_dir'] = @work_dir
+ store['config']['html_dir'] = @html_dir
+ store['config']['unit_system'] = :metric
+ @ffs = store['file_store'] = store.new(PostRunner::FitFileStore)
+ @records = store['records'] = store.new(PostRunner::PersonalRecords)
+end
+
def create_fit_file(name, date, duration_minutes = 30)
Fit4Ruby.write(name, create_fit_activity(
{ :t => date, :duration => duration_minutes }))
@@ -112,4 +145,42 @@ def create_fit_activity(config)
a
end
+def tables_to_arrays(str)
+ mode = :searching_table
+ arrays = []
+ array = []
+ str.each_line do |line|
+ case mode
+ when :searching_table
+ if line[0] == '+'
+ mode = :header
+ end
+ when :header
+ if line[0] == '|'
+ mode = :separation_line
+ else
+ mode = :searching_table
+ end
+ when :separation_line
+ if line[0] == '+'
+ mode = :body
+ else
+ mode = :searching_table
+ end
+ when :body
+ if line[0] == '|'
+ array << line[1..-3].split('|').map(&:strip)
+ elsif line[0] == '+'
+ arrays << array
+ array = []
+ mode = :searching_table
+ else
+ array = []
+ mode = :searching_table
+ end
+ end
+ end
+
+ arrays
+end