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

Add test_spec. app_host_name to DSL #520

Merged
merged 12 commits into from
Apr 23, 2019
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

##### Enhancements

* None.
* Allow test specs to specify an `app_host_name` to point to an app spec whose
application is used as the test's app host.
[jkap](https://github.com/jkap)
[Samuel Giddins](https://github.com/segiddins)
[#520](https://github.com/CocoaPods/Core/pull/520)

##### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions lib/cocoapods-core/specification/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def user_target_xcconfig
spec_attr_accessor :requires_app_host
alias_method :requires_app_host?, :requires_app_host

# @return [String] Name of the app host this spec requires
#
spec_attr_accessor :app_host_name

# @return [Symbol] the test type supported by this specification.
#
spec_attr_accessor :test_type
Expand Down
33 changes: 33 additions & 0 deletions lib/cocoapods-core/specification/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,39 @@ def subspec(name, &block)
:default_value => false,
:spec_types => [:test]

# @!method app_host_name=(name)
segiddins marked this conversation as resolved.
Show resolved Hide resolved
#
# The app specification to use as an app host, if necessary.
#
# @note
#
# You must depend on that app spec using `test_spec.dependency 'PodName'`.
#
# @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.requires_app_host = true
# test_spec.app_host_name = 'NSAttributedString+CCLFormat/App'
segiddins marked this conversation as resolved.
Show resolved Hide resolved
# test_spec.dependency 'NSAttributedString+CCLFormat/App'
# end
#
# spec.app_spec 'App' do |app_spec|
# app_spec.source_files = 'NSAttributedString+CCLFormat.m'
# app_spec.dependency 'AFNetworking'
# end
# end
#
# @param [String] name
# The app specification to use as an app host, if necessary.
#
attribute :app_host_name,
:types => [String],
:spec_types => [:test]

SCHEME_KEYS = [:launch_arguments, :environment_variables].freeze

# @!method scheme=(flag)
Expand Down
12 changes: 12 additions & 0 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ def _validate_test_type(t)
end
end

def _validate_app_host_name(n)
unless consumer.requires_app_host?
results.add_error('app_host_name', '`requires_app_host` must be set to ' \
'`true` when `app_host_name` is specified.')
end

unless consumer.dependencies.map(&:name).include?(n)
results.add_error('app_host_name', "The app host name (#{n}) specified by `#{consumer.spec.name}` could " \
'not be found. You must explicitly declare a dependency on that app spec.')
end
end

# Performs validations related to the `script_phases` attribute.
#
def _validate_script_phases(s)
Expand Down
8 changes: 8 additions & 0 deletions spec/specification/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ module Pod
test_consumer.requires_app_host?.should.be.true
end

it 'allows to specify a specific app host to use' do
segiddins marked this conversation as resolved.
Show resolved Hide resolved
@spec.test_spec {}
test_spec = @spec.test_specs.first
test_spec.app_host_name = 'Foo/App'
test_consumer = Specification::Consumer.new(test_spec, :ios)
test_consumer.app_host_name.should == 'Foo/App'
end

it 'returns the scheme configuration of a test spec' do
@spec.test_spec {}
test_spec = @spec.test_specs.first
Expand Down
35 changes: 35 additions & 0 deletions spec/specification/linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,41 @@ def result_should_include(*values)

#------------------#

it 'fails a test spec with `requires_app_host = false` and `app_host_name` set' do
@spec.test_specification = true
@spec.requires_app_host = false
@spec.app_host_name = 'BananaLib/App'
result_ignore('must explicitly declare a dependency')
result_should_include('app_host_name', 'requires_app_host')
end

it 'passes a test spec with `requires_app_host = true` and `app_host_name` set' do
@spec.test_specification = true
@spec.requires_app_host = true
@spec.app_host_name = 'BananaLib/App'
@spec.dependency 'BananaLib/App'
@linter.lint
@linter.results.should.be.empty?
end

it 'fails a test spec requiring an app host from a pod that isn\'t required' do
@spec.test_specification = true
@spec.requires_app_host = true
@spec.app_host_name = 'Foo/App'
result_should_include('app_host_name', 'Foo')
end

it 'passes a test spec requiring an app host from a pod that is listed as a dependency' do
dnkoutso marked this conversation as resolved.
Show resolved Hide resolved
@spec.dependency 'Foo/App'
@spec.test_specification = true
@spec.requires_app_host = true
@spec.app_host_name = 'Foo/App'
@linter.lint
@linter.results.should.be.empty?
end

#------------------#

it 'checks if the description is not an empty string' do
@spec.stubs(:description).returns('')
result_should_include('description', 'empty')
Expand Down