[Validator] Add specs for .swift-version

parent f3c1318c
......@@ -237,6 +237,19 @@ module Pod
Pathname(Dir.tmpdir) + 'CocoaPods/Lint'
end
# @return [String] the SWIFT_VERSION to use for validation.
#
def swift_version
@swift_version ||= dot_swift_version || '2.3'
end
# @return [String] the SWIFT_VERSION in the .swift-version file or nil.
#
def dot_swift_version
swift_version_path = file.dirname + '.swift-version'
File.read(swift_version_path) if File.exist?(swift_version_path)
end
#-------------------------------------------------------------------------#
private
......@@ -656,19 +669,6 @@ module Pod
# !@group Helpers
# @return [String] the SWIFT_VERSION to use for validation.
#
def swift_version
dot_swift_version || '2.3'
end
# @return [String] the SWIFT_VERSION in the .swift-version file or nil.
#
def dot_swift_version
swift_version_path = file.dirname + '.swift-version'
File.read(swift_version_path) if File.exists?(swift_version_path)
end
# @return [Array<String>] an array of source URLs used to create the
# {Podfile} used in the linting process
#
......
......@@ -784,13 +784,12 @@ module Pod
validator = Validator.new(file, config.sources_manager.master.map(&:url))
validator.stubs(:build_pod)
validator.stubs(:validate_url)
validator.stubs(:swift_version).returns('2.3')
validator.validate
validator
end
it 'fails on deployment target < iOS 8 for Swift Pods' do
validator = test_swiftpod
validator.validate
validator.results.map(&:to_s).first.should.match /dynamic frameworks.*iOS > 8/
validator.result_type.should == :error
......@@ -800,6 +799,7 @@ module Pod
Specification::Consumer.any_instance.stubs(:frameworks).returns(%w(XCTest))
validator = test_swiftpod
validator.validate
validator.results.count.should == 0
end
......@@ -807,12 +807,48 @@ module Pod
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod
validator.validate
validator.results.count.should == 0
end
it 'defaults to Swift 2.3' do
validator = test_swiftpod
describe '#swift_version' do
it 'defaults to Swift 2.3' do
validator = test_swiftpod
validator.stubs(:dot_swift_version).returns(nil)
validator.swift_version.should == '2.3'
end
it 'checks for dot_swift_version' do
validator = test_swiftpod
validator.expects(:dot_swift_version)
validator.swift_version
end
it 'uses the result of dot_swift_version if not nil' do
validator = test_swiftpod
validator.stubs(:dot_swift_version).returns('1.0')
validator.swift_version.should == '1.0'
end
end
describe '#dot_swift_version' do
it 'looks for a .swift-version file' do
validator = test_swiftpod
File.expects(:exist?).with do |arg|
arg.basename.to_s == '.swift-version'
end
validator.dot_swift_version
end
it 'uses the .swift-version file if present' do
validator = test_swiftpod
File.stubs(:exist?).returns(true)
File.expects(:read).with do |arg|
arg.basename.to_s == '.swift-version'
end.returns('1.0')
validator.dot_swift_version.should == '1.0'
end
end
end
#-------------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment