tests/gpx_file_test.rb in gpx-1.1.1 vs tests/gpx_file_test.rb in gpx-1.1.2

- old
+ new

@@ -1,51 +1,25 @@ # frozen_string_literal: true require 'minitest/autorun' require 'gpx' +require 'stringio' class GPXFileTest < Minitest::Test ONE_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx') WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), 'gpx_files/with_or_without_elev.gpx') WITH_EMPTY_TRACKS = File.join(File.dirname(__FILE__), 'gpx_files/with_empty_tracks.gpx') BIG_FILE = File.join(File.dirname(__FILE__), 'gpx_files/big.gpx') def test_load_data_from_string gpx_file = GPX::GPXFile.new(gpx_data: File.open(ONE_TRACK_FILE).read) - assert_equal(1, gpx_file.tracks.size) - assert_equal(8, gpx_file.tracks.first.segments.size) - assert_equal('ACTIVE LOG', gpx_file.tracks.first.name) - assert_equal('active_log.gpx', gpx_file.name) - assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema) - assert_equal(38.681488, gpx_file.bounds.min_lat) - assert_equal(-109.606948, gpx_file.bounds.min_lon) - assert_equal(38.791759, gpx_file.bounds.max_lat) - assert_equal(-109.447045, gpx_file.bounds.max_lon) - assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description) - assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description) - assert_equal(3.0724966849262554, gpx_file.distance) - assert_equal(15_237.0, gpx_file.duration) - assert_equal(3036.0, gpx_file.moving_duration) - assert_equal(3.6432767014935834, gpx_file.average_speed) + shared_assertions_for_one_track_file(gpx_file) end def test_load_data_from_file gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK_FILE) - assert_equal(1, gpx_file.tracks.size) - assert_equal(8, gpx_file.tracks.first.segments.size) - assert_equal('ACTIVE LOG', gpx_file.tracks.first.name) - assert_equal('active_log.gpx', gpx_file.name) - assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema) - assert_equal(38.681488, gpx_file.bounds.min_lat) - assert_equal(-109.606948, gpx_file.bounds.min_lon) - assert_equal(38.791759, gpx_file.bounds.max_lat) - assert_equal(-109.447045, gpx_file.bounds.max_lon) - assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description) - assert_equal(3.0724966849262554, gpx_file.distance) - assert_equal(15_237.0, gpx_file.duration) - assert_equal(3036.0, gpx_file.moving_duration) - assert_equal(3.6432767014935834, gpx_file.average_speed) + shared_assertions_for_one_track_file(gpx_file) end def test_big_file gpx_file = GPX::GPXFile.new(gpx_file: BIG_FILE) assert_equal(1, gpx_file.tracks.size) @@ -71,7 +45,38 @@ # and ignores empty segments assert_equal(1, gpx_file.tracks.first.segments.size) assert_equal(21.0, gpx_file.duration) assert_equal(21.0, gpx_file.moving_duration) assert_equal(6.674040636626879, gpx_file.average_speed) + end + + def test_load_data_from_stringio_assigned_gpx_file + str = File.open(ONE_TRACK_FILE).read + io = StringIO.new(str, 'r+') + gpx_file = GPX::GPXFile.new(gpx_file: io) + shared_assertions_for_one_track_file(gpx_file) + end + + def test_load_data_from_stringio_assigned_gpx_data + str = File.open(ONE_TRACK_FILE).read + io = StringIO.new(str, 'r+') + gpx_file = GPX::GPXFile.new(gpx_data: io) + shared_assertions_for_one_track_file(gpx_file) + end + + def shared_assertions_for_one_track_file(gpx_file) + assert_equal(1, gpx_file.tracks.size) + assert_equal(8, gpx_file.tracks.first.segments.size) + assert_equal('ACTIVE LOG', gpx_file.tracks.first.name) + assert_equal('active_log.gpx', gpx_file.name) + assert_equal('2006-04-08T16:44:28Z', gpx_file.time.xmlschema) + assert_equal(38.681488, gpx_file.bounds.min_lat) + assert_equal(-109.606948, gpx_file.bounds.min_lon) + assert_equal(38.791759, gpx_file.bounds.max_lat) + assert_equal(-109.447045, gpx_file.bounds.max_lon) + assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description) + assert_equal(3.0724966849262554, gpx_file.distance) + assert_equal(15_237.0, gpx_file.duration) + assert_equal(3036.0, gpx_file.moving_duration) + assert_equal(3.6432767014935834, gpx_file.average_speed) end end