Skip to content

Commit

Permalink
[Specification::Linter] Forbid whitespaces, dots and slashes
Browse files Browse the repository at this point in the history
The spec is based off of the changes by @segiddins in #178 and @kaplin in #202. So this supersedes and closes #178, #202. This fixes #177.
  • Loading branch information
mrackwitz committed Apr 9, 2015
1 parent b830026 commit 0f80dba
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
27 changes: 12 additions & 15 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def lint
if spec
validate_root_name
check_required_attributes
validate_name
run_root_validation_hooks
perform_all_specs_analysis
else
Expand Down Expand Up @@ -185,22 +184,20 @@ def run_validation_hooks(attributes, target)

# Performs validations related to the `name` attribute.
#
def validate_name
if spec.name && file
if spec.name =~ /\//
results.add_error('name', 'The name of a spec should not contain ' \
'a slash.')
end
def _validate_name(name)
if name =~ /\//
results.add_error('name', 'The name of a spec should not contain ' \
'a slash.')
end

if spec.root.name =~ /\s/
results.add_error('name', 'The name of a spec should not contain ' \
'whitespace.')
end
if name =~ /\s/
results.add_error('name', 'The name of a spec should not contain ' \
'whitespace.')
end

if spec.root.name[0, 1] == '.'
results.add_error('name', 'The name of a spec should not begin' \
' with a period.')
end
if name[0, 1] == '.'
results.add_error('name', 'The name of a spec should not begin' \
' with a period.')
end
end

Expand Down
46 changes: 39 additions & 7 deletions spec/specification/linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,9 @@ module Pod
end
end

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

describe 'Root spec' do
shared 'Linter' do
before do
fixture_path = 'spec-repos/test_repo/Specs/BananaLib/1.0/BananaLib.podspec'
@podspec_path = fixture(fixture_path)
@podspec_path = fixture(@fixture_path)
@linter = Specification::Linter.new(@podspec_path)
@spec = @linter.spec
end
Expand All @@ -110,6 +107,16 @@ def result_should_include(*values)

matched.size.should == 1
end
end

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

describe 'Root spec' do
before do
@fixture_path = 'spec-repos/test_repo/Specs/BananaLib/1.0/BananaLib.podspec'
end

behaves_like 'Linter'

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

Expand Down Expand Up @@ -146,12 +153,12 @@ def result_should_include(*values)
end

it 'fails a specification whose name contains whitespace' do
@spec.stubs(:name).returns('bad name')
@spec.name = 'bad name'
result_should_include('name', 'whitespace')
end

it 'fails a specification whose name contains a slash' do
@spec.stubs(:name).returns('BananaKit/BananaFruit')
@spec.name = 'BananaKit/BananaFruit'
result_should_include('name', 'slash')
end

Expand Down Expand Up @@ -453,5 +460,30 @@ def result_should_include(*values)
result_should_include('warnings', 'disabled', 'compiler_flags')
end
end

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

describe 'Subspec' do
before do
@fixture_path = 'spec-repos/master/RestKit/0.20.1/RestKit.podspec'
end

behaves_like 'Linter'

it 'fails a subspec whose name contains whitespace' do
@spec.subspecs.each { |ss| ss.name = 'bad name' }
result_should_include('name', 'whitespace')
end

it 'fails a subspec whose name begins with a `.`' do
@spec.subspecs.each { |ss| ss.name = '.badname' }
result_should_include('name', 'period')
end

it 'fails a specification whose name contains a slash' do
@spec.name = 'BananaKit/BananaFruit'
result_should_include('name', 'slash')
end
end
end
end

0 comments on commit 0f80dba

Please sign in to comment.