-
Notifications
You must be signed in to change notification settings - Fork 352
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
Introduce test_specification
DSL
#369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,16 @@ class Specification | |
# @param [String] name | ||
# the name of the specification. | ||
# | ||
def initialize(parent = nil, name = nil) | ||
# @param [Bool] test_specification | ||
# Whether the specification is a test specification | ||
# | ||
def initialize(parent = nil, name = nil, test_specification = false) | ||
@attributes_hash = {} | ||
@subspecs = [] | ||
@consumers = {} | ||
@parent = parent | ||
@hash_value = nil | ||
@test_specification = test_specification | ||
attributes_hash['name'] = name | ||
|
||
yield self if block_given? | ||
|
@@ -203,7 +207,26 @@ def subspec? | |
|
||
# @!group Dependencies & Subspecs | ||
|
||
# @return [Array<Specifications>] the recursive list of all the subspecs of | ||
# @return [Bool] if the specification is a test specification | ||
# | ||
def test_specification? | ||
@test_specification | ||
end | ||
|
||
# @return [Symbol] the test type supported if this is a test specification | ||
# | ||
def test_type | ||
attributes_hash['test_type'] | ||
end | ||
|
||
# @return [Array<Specification>] the list of all the test subspecs of | ||
# a specification. | ||
# | ||
def test_specs | ||
subspecs.select(&:test_specification?) | ||
end | ||
|
||
# @return [Array<Specification>] the recursive list of all the subspecs of | ||
# a specification. | ||
# | ||
def recursive_subspecs | ||
|
@@ -241,7 +264,7 @@ def subspec_by_name(relative_name, raise_if_missing = true) | |
else | ||
remainder = relative_name[base_name.size + 1..-1] | ||
subspec_name = remainder.split('/').shift | ||
subspec = subspecs.find { |s| s.base_name == subspec_name } | ||
subspec = subspecs.find { |s| s.base_name == subspec_name && !s.test_specification? } | ||
unless subspec | ||
if raise_if_missing | ||
raise Informative, 'Unable to find a specification named ' \ | ||
|
@@ -274,7 +297,7 @@ def default_subspecs | |
# | ||
def subspec_dependencies(platform = nil) | ||
specs = if default_subspecs.empty? | ||
subspecs.compact | ||
subspecs.compact.reject(&:test_specification?) | ||
else | ||
default_subspecs.map do |subspec_name| | ||
root.subspec_by_name("#{name}/#{subspec_name}") | ||
|
@@ -288,9 +311,8 @@ def subspec_dependencies(platform = nil) | |
|
||
# Returns the dependencies on other Pods or subspecs of other Pods. | ||
# | ||
# @param [Bool] all_platforms | ||
# whether the dependencies should be returned for all platforms | ||
# instead of the active one. | ||
# @param [Platform] platform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed documentation for this method. |
||
# return only dependencies supported on the given platform. | ||
# | ||
# @note External dependencies are inherited by subspecs | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1324,6 +1324,47 @@ def subspec(name, &block) | |
subspec | ||
end | ||
|
||
# The list of the test types currently supported. | ||
# | ||
SUPPORTED_TEST_TYPES = [:unit].freeze | ||
|
||
# The test type this specification supports. This only applies to test specifications. | ||
# | ||
# --- | ||
# | ||
# @example | ||
# | ||
# test_spec.test_type = :unit | ||
# | ||
# @param [Symbol] type | ||
# The test type to use. | ||
attribute :test_type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead the |
||
:default_value => :unit, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out this exists! |
||
:types => [Symbol], | ||
:multi_platform => false | ||
|
||
# Represents a test specification for the library. Here you can place all | ||
# your tests for your podspec along with the test dependencies. | ||
# | ||
# --- | ||
# | ||
# @example | ||
# | ||
# Pod::Spec.new do |spec| | ||
# spec.name = 'NSAttributedString+CCLFormat' | ||
# | ||
# spec.test_spec do |test_spec| | ||
# test_spec.source_files = 'NSAttributedString+CCLFormatTests.m' | ||
# test_spec.dependency 'Expecta' | ||
# end | ||
# end | ||
# | ||
def test_spec(name = 'Tests', &block) | ||
subspec = Specification.new(self, name, true, &block) | ||
@subspecs << subspec | ||
subspec | ||
end | ||
|
||
#------------------# | ||
|
||
# @!method default_subspecs=(subspec_array) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,27 @@ module Pod | |
|
||
#-----------------------------------------------------------------------------# | ||
|
||
describe 'Test specs' do | ||
before do | ||
@spec = Spec.new do |spec| | ||
spec.name = 'Spec' | ||
spec.test_spec do |test_spec| | ||
test_spec.test_type = :unit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added it in the initializer of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed it now as the attribute now has a |
||
end | ||
end | ||
end | ||
|
||
it 'allows you to specify a test spec' do | ||
test_spec = @spec.subspecs.first | ||
test_spec.class.should == Specification | ||
test_spec.name.should == 'Spec/Tests' | ||
test_spec.test_specification?.should == true | ||
test_spec.test_type.should == :unit | ||
end | ||
end | ||
|
||
#-----------------------------------------------------------------------------# | ||
|
||
describe 'Multi-Platform' do | ||
before do | ||
@spec = Spec.new do |s| | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the work was done so I included the credit.