Skip to content

Commit 85b501d

Browse files
committed
Parse route with tcxread.
1 parent 8f468e0 commit 85b501d

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

.rubocop_todo.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-10-20 02:25:48 UTC using RuboCop version 1.68.0.
3+
# on 2025-10-22 15:51:23 UTC using RuboCop version 1.68.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -16,6 +16,13 @@ RSpec/AnyInstance:
1616
Exclude:
1717
- 'spec/strava/api/client_spec.rb'
1818

19+
# Offense count: 3
20+
# Configuration parameters: Prefixes, AllowedPatterns.
21+
# Prefixes: when, with, without
22+
RSpec/ContextWording:
23+
Exclude:
24+
- 'spec/strava/api/client/endpoints/routes/export_route_tcx_spec.rb'
25+
1926
# Offense count: 5
2027
# Configuration parameters: AllowedGroups.
2128
RSpec/NestedGroups:

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ group :development, :test do
1717
gem 'rubocop', '1.68.0'
1818
gem 'rubocop-rake'
1919
gem 'rubocop-rspec'
20+
gem 'tcxread'
2021
gem 'vcr'
2122
gem 'webmock'
2223
gem 'webrick', '~> 1.7'

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
require 'rspec'
77
require 'strava-ruby-client'
88

9+
require 'tempfile'
910
require 'multi_xml'
1011
require 'gpx'
12+
require 'tcxread'
1113
require 'polylines'
1214

1315
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|

spec/strava/api/client/endpoints/routes/export_route_tcx_spec.rb

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,38 @@
44

55
RSpec.describe 'Strava::Api::Client#export_route_tcx', vcr: { cassette_name: 'client/export_route_tcx' } do
66
include_context 'with API client'
7-
it 'exports a route file' do
8-
route = client.export_route_tcx(id: 16_341_573)
9-
expect(route).to start_with "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase"
107

11-
xml = MultiXml.parse(route)
12-
expect(xml).to be_a Hash
8+
context 'an exported route' do
9+
let(:route) { client.export_route_tcx(id: 16_341_573) }
10+
11+
it 'is a TrainingCenterDatabase' do
12+
expect(route).to start_with "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase"
13+
end
14+
15+
context 'as xml' do
16+
let(:xml) { MultiXml.parse(route) }
17+
18+
it 'is valid XML' do
19+
expect(xml).to be_a Hash
20+
end
21+
end
22+
23+
context 'as parsed tcx' do
24+
let(:tcx) do
25+
Tempfile.open(['route', '.tcx']) do |temp_file|
26+
temp_file.write(route)
27+
temp_file.close
28+
29+
TCXRead.new(temp_file.path)
30+
end
31+
end
32+
33+
it 'is valid' do
34+
expect(tcx).to be_a(TCXRead)
35+
expect(tcx.total_distance_meters).to eq 0
36+
expect(tcx.total_time_seconds).to eq 0
37+
end
38+
end
1339
end
1440

1541
it 'exports a route file by id' do

0 commit comments

Comments
 (0)