diff --git a/CHANGELOG.md b/CHANGELOG.md index e145074f7..376ec9b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ ##### Enhancements -* None. +* Add accessors for working with skipped tests inside TestAction in `.xcscheme` files. + [Eduard Panasiuk](https://github.com/somedev) + [#380](https://github.com/CocoaPods/Xcodeproj/pull/380) ##### Bug Fixes diff --git a/lib/xcodeproj/scheme/test_action.rb b/lib/xcodeproj/scheme/test_action.rb index 6f33f93e3..ff4eb0a45 100644 --- a/lib/xcodeproj/scheme/test_action.rb +++ b/lib/xcodeproj/scheme/test_action.rb @@ -148,6 +148,49 @@ def add_buildable_reference(ref) @xml_element.add_element(ref.xml_element) end + # @return [Array] + # The list of SkippedTest this action will skip. + # + def skipped_tests + @xml_element.elements['SkippedTests'].get_elements('Test').map do |node| + TestableReference::SkippedTest.new(node) + end + end + + # @param [SkippedTest] skipped_test + # The SkippedTest to add to the list of tests this action will skip + # + def add_skipped_test(skipped_test) + entries = @xml_element.elements['SkippedTests'] || @xml_element.add_element('SkippedTests') + entries.add_element(skipped_test.xml_element) + end + + class SkippedTest < XMLElementWrapper + # @param [REXML::Element] node + # The 'Test' XML node that this object will wrap. + # If nil, will create a default XML node to use. + # + def initialize(node = nil) + create_xml_element_with_fallback(node, 'Test') do + self.identifier = node.attributes['Identifier'] unless node.nil? + end + end + + # @return [String] + # Skipped test class name + # + def identifier + @xml_element.attributes['Identifier'] + end + + # @param [String] value + # Set the name of the skipped test class name + # + def identifier=(value) + @xml_element.attributes['Identifier'] = value + end + end + # @todo handle 'AdditionalOptions' tag end end diff --git a/spec/scheme/test_action_spec.rb b/spec/scheme/test_action_spec.rb index f78805806..601089a1e 100644 --- a/spec/scheme/test_action_spec.rb +++ b/spec/scheme/test_action_spec.rb @@ -193,6 +193,33 @@ module Xcodeproj specs_for_bool_attr(attributes) end + it '#add_skipped_test' do + test_ref = XCScheme::TestAction::TestableReference.new + skipped_test = XCScheme::TestAction::TestableReference::SkippedTest.new + skipped_test.identifier = 'MyClassTests' + test_ref.add_skipped_test(skipped_test) + test_ref.xml_element.elements['SkippedTests'].should.not.nil? + test_ref.xml_element.elements['SkippedTests'].count.should == 1 + test_ref.xml_element.elements['SkippedTests'].elements['Test'].should == skipped_test.xml_element + end + + it '#skipped_tests' do + test_ref = XCScheme::TestAction::TestableReference.new + + test1 = XCScheme::TestAction::TestableReference::SkippedTest.new + test1.identifier = 'MyClassTests1' + test_ref.add_skipped_test(test1) + + test2 = XCScheme::TestAction::TestableReference::SkippedTest.new + test2.identifier = 'MyClassTests2' + test_ref.add_skipped_test(test2) + + test_ref.skipped_tests.count.should == 2 + test_ref.skipped_tests.all? { |e| e.class.should == XCScheme::TestAction::TestableReference::SkippedTest } + test_ref.skipped_tests[0].xml_element.should == test1.xml_element + test_ref.skipped_tests[1].xml_element.should == test2.xml_element + end + it '#add_buildable_reference' do project = Xcodeproj::Project.new('/foo/bar/baz.xcodeproj') test_ref = XCScheme::TestAction::TestableReference.new