From ccbb158046c2aeee0b6605f53de64314a3bc9a99 Mon Sep 17 00:00:00 2001 From: freak4pc Date: Tue, 9 Mar 2021 01:05:31 +0200 Subject: [PATCH] Add tests for location scenario reference --- CHANGELOG.md | 4 ++ .../scheme/location_scenario_reference.rb | 2 +- .../location_scenario_reference_spec.rb | 72 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 spec/scheme/location_scenario_reference_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index cc29b37c1..4ad2af45e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ##### Enhancements +* Allow accessing a Launch Action's Simulated Location (`LocationScenarioReference`) + [freak4pc](https://github.com/freak4pc) + [#813](https://github.com/CocoaPods/Xcodeproj/pull/813) + * Add support for group options when using the sort command [zanchee](https://github.com/Zanchee) [imachumphries](https://github.com/imachumphries) diff --git a/lib/xcodeproj/scheme/location_scenario_reference.rb b/lib/xcodeproj/scheme/location_scenario_reference.rb index 50884f1d2..e58f2412a 100644 --- a/lib/xcodeproj/scheme/location_scenario_reference.rb +++ b/lib/xcodeproj/scheme/location_scenario_reference.rb @@ -2,7 +2,7 @@ module Xcodeproj class XCScheme # This class wraps the LocationScenarioReference node of a .xcscheme XML file # - # A LocationScenarioReference is a reference to a simulated GPS locatio associated + # A LocationScenarioReference is a reference to a simulated GPS location associated # with a scheme's launch action # class LocationScenarioReference < XMLElementWrapper diff --git a/spec/scheme/location_scenario_reference_spec.rb b/spec/scheme/location_scenario_reference_spec.rb new file mode 100644 index 000000000..3975aa34b --- /dev/null +++ b/spec/scheme/location_scenario_reference_spec.rb @@ -0,0 +1,72 @@ +require File.expand_path('../../spec_helper', __FILE__) + +module Xcodeproj + describe XCScheme::LocationScenarioReference do + describe 'Created from scratch' do + before do + @ref = Xcodeproj::XCScheme::LocationScenarioReference.new(nil) + end + + it 'Creates an initial, quite empty XML node' do + @ref.xml_element.name.should == 'LocationScenarioReference' + @ref.xml_element.attributes.count.should == 2 + @ref.xml_element.attributes['identifier'].should == '' + @ref.xml_element.attributes['referenceType'].should == '0' + end + end + + describe 'Built-in Created from a XML node' do + before do + node = REXML::Element.new('LocationScenarioReference') + attributes = { + 'identifier' => 'London, England', + 'referenceType' => '1', + } + node.add_attributes(attributes) + @ref = Xcodeproj::XCScheme::LocationScenarioReference.new(node) + end + + it 'raise if invalid XML node' do + node = REXML::Element.new('Foo') + should.raise(Informative) do + Xcodeproj::XCScheme::LocationScenarioReference.new(node) + end.message.should.match /Wrong XML tag name/ + end + + it '#identifier' do + @ref.identifier.should == @ref.xml_element.attributes['identifier'] + end + + it '#reference_type' do + @ref.reference_type.should == @ref.xml_element.attributes['referenceType'] + end + end + + describe 'Custom GPX Created from a XML node' do + before do + node = REXML::Element.new('LocationScenarioReference') + attributes = { + 'identifier' => 'path/to/AmazingLocation.gpx', + 'referenceType' => '0', + } + node.add_attributes(attributes) + @ref = Xcodeproj::XCScheme::LocationScenarioReference.new(node) + end + + it 'raise if invalid XML node' do + node = REXML::Element.new('Foo') + should.raise(Informative) do + Xcodeproj::XCScheme::LocationScenarioReference.new(node) + end.message.should.match /Wrong XML tag name/ + end + + it '#identifier' do + @ref.identifier.should == @ref.xml_element.attributes['identifier'] + end + + it '#reference_type' do + @ref.reference_type.should == @ref.xml_element.attributes['referenceType'] + end + end + end +end