Skip to content

Commit

Permalink
Validate that a spec has the minimum required attributes. Testing if …
Browse files Browse the repository at this point in the history
…it compiles is for later.
  • Loading branch information
alloy committed Sep 19, 2011
1 parent 9ba5654 commit 1bb68e0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .kick
Expand Up @@ -5,7 +5,7 @@ Ruby.runner_bin = 'macbacon'
process do |files|
specs = files.take_and_map do |file|
case file
when %r{lib/cocoa_pods/(.+?)\.rb$}
when %r{lib/cocoapods/(.+?)\.rb$}
s = Dir.glob("spec/**/#{$1}_spec.rb")
s unless s.empty?
end
Expand Down
12 changes: 7 additions & 5 deletions lib/cocoapods/command/spec.rb
Expand Up @@ -56,16 +56,18 @@ def create
source_files 'Classes', 'Classes/**/*.{h,m}'
xcconfig 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework'
dependency 'SomeLibraryThat#{@name}DependsOn', '>= 1.0.0'
end
SPEC
(Pathname.pwd + "#{@name}.podspec").open('w') { |f| f << spec }
end

#def lint
#file = @name ? Pathname.new(@name) : config.project_podfile
#spec = Specification.from_podspec(file)
#spec.validate!
#end
def lint
file = @name ? Pathname.new(@name) : config.project_podfile
spec = Specification.from_podspec(file)
spec.validate!
end

#def push

Expand Down
16 changes: 16 additions & 0 deletions lib/cocoapods/specification.rb
Expand Up @@ -144,6 +144,22 @@ def inspect
"#<#{self.class.name} for #{to_s}>"
end

def validate!
attrs = []
attrs << "`name'" unless @name
attrs << "`version'" unless @version
attrs << "`summary'" unless @summary
attrs << "`homepage'" unless @homepage
attrs << "`author(s)'" unless @authors
attrs << "either `source' or `part_of'" unless @source || @part_of
attrs << "`source_files'" unless @source_files
unless attrs.empty?
raise Informative, "The following required " \
"#{attrs.size == 1 ? 'attribute is' : 'attributes are'} " \
"missing: #{attrs.join(", ")}"
end
end

# Install and download hooks

# Places the activated specification in the project's pods directory.
Expand Down
1 change: 1 addition & 0 deletions spec/functional/command_spec.rb
Expand Up @@ -53,6 +53,7 @@ def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
spec.read(:description).should == 'An optional longer description of Bananas.'
spec.read(:source_files).should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')]
spec.read(:xcconfig).should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
spec.read(:dependencies).should == [Pod::Dependency.new('SomeLibraryThatBananasDependsOn', '>= 1.0.0')]
end

before do
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/specification_spec.rb
Expand Up @@ -138,3 +138,12 @@
# @spec.pod_destroot
#end
end

describe "A Pod::Specification, in general," do
it "raises if the specification does not contain the minimum required attributes" do
exception = lambda {
Pod::Spec.new.validate!
}.should.raise Pod::Informative
exception.message =~ /name.+?version.+?summary.+?homepage.+?authors.+?(source|part_of).+?source_files/
end
end

0 comments on commit 1bb68e0

Please sign in to comment.