<commit_before>require 'spec_helper'
require 'read_pwx'

RSpec.describe ReadPWX::Serializers::GPXSerializer do
  before do
    file = IO.read(File.join('spec', 'fixtures', 'mod_ride.pwx'))
    @pwx = ReadPWX::Parser.new(file).pwx
  end

  it "dumps using a PWX class" do
    expect {
      ReadPWX::Serializers::GPXSerializer.dump(@pwx)
    }.to_not raise_error
  end

  describe "the dumped GPX document" do
    before do
      @gpx = ReadPWX::Serializers::GPXSerializer.dump(@pwx)
    end

    it "validates against GPX schema" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpx.xsd')))
      expect(schema.valid?(@gpx)).to be true
    end

    it "has no GPX schema errors" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpx.xsd')))
      expect(schema.validate(@gpx)).to be_empty
    end

    it "validates against GPXData schema" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpxdata10.xsd')))
      expect(schema.valid?(@gpx)).to be true
    end

    it "has no GPXData schema errors" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpxdata10.xsd')))
      expect(schema.validate(@gpx)).to be_empty
    end

    it "sets the metadata author name" do
      name = @gpx.at_xpath('//xmlns:metadata/xmlns:author/xmlns:name').text.strip
      expect(name).to eq "ReadPWX"
    end

    it "sets the metadata author link text" do
      link = @gpx.at_xpath('//xmlns:metadata/xmlns:author/xmlns:link/xmlns:text').text.strip
      expect(link).to eq "Github: openfirmware/read_pwx"
    end

    it "sets the metadata author link href" do
      link = @gpx.at_xpath('//xmlns:metadata/xmlns:author/xmlns:link')
      expect(link.attributes['href'].value).to eq "https://github.com/openfirmware/read_pwx"
    end

    it "sets the metadata author link mimetype" do
      link = @gpx.at_xpath('//xmlns:metadata/xmlns:author/xmlns:link/xmlns:type').text.strip
      expect(link).to eq "text/html"
    end

    it "has the cadence data as a trkpt extension" do
      cadence = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:cadence').text.strip
      expect(cadence).to eq @pwx.workouts.first.samples.first.cad
    end

    it "ignores the cadence element when it is not present" do
      cadence = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:cadence')
      expect(cadence).to eq nil
    end

    it "has the distance data as a trkpt extension" do
      distance = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:distance').text.strip
      expect(distance).to eq @pwx.workouts.first.samples.first.dist
    end

    it "ignores the distance element when it is not present" do
      distance = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:distance')
      expect(distance).to eq nil
    end

    it "has the heart rate data as a trkpt extension" do
      hr = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:hr').text.strip
      expect(hr).to eq @pwx.workouts.first.samples.first.hr
    end

    it "ignores the heart rate element when it is not present" do
      hr = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:hr')
      expect(hr).to eq nil
    end

    it "has the temperature data as a trkpt extension" do
      temp = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:temp').text.strip
      expect(temp).to eq @pwx.workouts.first.samples.first.temp
    end

    it "ignores the temperature element when it is not present" do
      temp = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:temp')
      expect(temp).to eq nil
    end

    it "has the power data as a trkpt extension" do
      power = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:power').text.strip
      expect(power).to eq @pwx.workouts.first.samples.first.pwr
    end

    it "ignores the power element when it is not present" do
      power = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:power')
      expect(power).to eq nil
    end

    it "has the ISO8601 date/time as a trkpt element" do
      datetime = @gpx.at_xpath('//xmlns:trkpt/xmlns:time').text.strip
      expect(datetime).to eq @pwx.workouts.first.samples.first.time
    end

    it "has the run info as a trk extension" do
      run = @gpx.at_xpath('//xmlns:trk/xmlns:extensions/gpxdata:run')
      expect(run).to_not eq nil
    end
  end
end
<commit_msg>Use more specific xpath in specs<commit_after>require 'spec_helper'
require 'read_pwx'

RSpec.describe ReadPWX::Serializers::GPXSerializer do
  before do
    file = IO.read(File.join('spec', 'fixtures', 'mod_ride.pwx'))
    @pwx = ReadPWX::Parser.new(file).pwx
  end

  it "dumps using a PWX class" do
    expect {
      ReadPWX::Serializers::GPXSerializer.dump(@pwx)
    }.to_not raise_error
  end

  describe "the dumped GPX document" do
    before do
      @gpx = ReadPWX::Serializers::GPXSerializer.dump(@pwx)
    end

    it "validates against GPX schema" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpx.xsd')))
      expect(schema.valid?(@gpx)).to be true
    end

    it "has no GPX schema errors" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpx.xsd')))
      expect(schema.validate(@gpx)).to be_empty
    end

    it "validates against GPXData schema" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpxdata10.xsd')))
      expect(schema.valid?(@gpx)).to be true
    end

    it "has no GPXData schema errors" do
      schema = Nokogiri::XML::Schema(IO.read(File.join('spec', 'schemas', 'gpxdata10.xsd')))
      expect(schema.validate(@gpx)).to be_empty
    end

    it "sets the metadata author name" do
      name = @gpx.at_xpath('/xmlns:gpx/xmlns:metadata/xmlns:author/xmlns:name').text.strip
      expect(name).to eq "ReadPWX"
    end

    it "sets the metadata author link text" do
      link = @gpx.at_xpath('/xmlns:gpx/xmlns:metadata/xmlns:author/xmlns:link/xmlns:text').text.strip
      expect(link).to eq "Github: openfirmware/read_pwx"
    end

    it "sets the metadata author link href" do
      link = @gpx.at_xpath('/xmlns:gpx/xmlns:metadata/xmlns:author/xmlns:link')
      expect(link.attributes['href'].value).to eq "https://github.com/openfirmware/read_pwx"
    end

    it "sets the metadata author link mimetype" do
      link = @gpx.at_xpath('/xmlns:gpx/xmlns:metadata/xmlns:author/xmlns:link/xmlns:type').text.strip
      expect(link).to eq "text/html"
    end

    it "has the cadence data as a trkpt extension" do
      cadence = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:cadence').text.strip
      expect(cadence).to eq @pwx.workouts.first.samples.first.cad
    end

    it "ignores the cadence element when it is not present" do
      cadence = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:cadence')
      expect(cadence).to eq nil
    end

    it "has the distance data as a trkpt extension" do
      distance = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:distance').text.strip
      expect(distance).to eq @pwx.workouts.first.samples.first.dist
    end

    it "ignores the distance element when it is not present" do
      distance = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:distance')
      expect(distance).to eq nil
    end

    it "has the heart rate data as a trkpt extension" do
      hr = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:hr').text.strip
      expect(hr).to eq @pwx.workouts.first.samples.first.hr
    end

    it "ignores the heart rate element when it is not present" do
      hr = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:hr')
      expect(hr).to eq nil
    end

    it "has the temperature data as a trkpt extension" do
      temp = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:temp').text.strip
      expect(temp).to eq @pwx.workouts.first.samples.first.temp
    end

    it "ignores the temperature element when it is not present" do
      temp = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:temp')
      expect(temp).to eq nil
    end

    it "has the power data as a trkpt extension" do
      power = @gpx.at_xpath('//xmlns:trkpt/xmlns:extensions/gpxdata:power').text.strip
      expect(power).to eq @pwx.workouts.first.samples.first.pwr
    end

    it "ignores the power element when it is not present" do
      power = @gpx.xpath('//xmlns:trkpt').last.at_xpath('xmlns:extensions/gpxdata:power')
      expect(power).to eq nil
    end

    it "has the ISO8601 date/time as a trkpt element" do
      datetime = @gpx.at_xpath('//xmlns:trkpt/xmlns:time').text.strip
      expect(datetime).to eq @pwx.workouts.first.samples.first.time
    end

    it "has the run info as a trk extension" do
      run = @gpx.at_xpath('//xmlns:trk/xmlns:extensions/gpxdata:run')
      expect(run).to_not eq nil
    end
  end
end

{'fraction_non_alphanumeric': 0.13340769659788065, 'fraction_numerical': 0.0017847183491355272, 'mean_word_length': 3.314725697786333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 80}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7551069', 'n_tokens_mistral': 3256, 'n_tokens_neox': 3152, 'n_words': 709}