Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipped tests list support added for TestableReference #380

Merged
merged 3 commits into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

##### Enhancements

* None.
* Add accessors for working with skipped tests inside TestAction in `.xcscheme` files.
[Eduard Panasiuk](https://github.com/somedev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be pedantic, but could you also add the link to this PR too here? Thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem


##### Bug Fixes

Expand Down
43 changes: 43 additions & 0 deletions lib/xcodeproj/scheme/test_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,49 @@ def add_buildable_reference(ref)
@xml_element.add_element(ref.xml_element)
end

# @return [Array<SkippedTest>]
# 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
Expand Down
27 changes: 27 additions & 0 deletions spec/scheme/test_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down