Skip to content

Commit

Permalink
[Spec] Strip indentation to prefix_header and to prepare_command
Browse files Browse the repository at this point in the history
Closes #51
  • Loading branch information
fabiopelosin committed Apr 1, 2014
1 parent 96aff70 commit ff63023
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,15 @@
# CocoaPods Core Changelog

## Master

##### Enhancements

* The specification now strips the indentation of the `prefix_header` and
`prepare_command` to aide their declaration as a here document (similarly to
what it already does with the description).
[Fabio Pelosin][irrationalfab]
[#51](https://github.com/CocoaPods/Core/issues/51)

## 0.31.0

##### Enhancements
Expand All @@ -18,3 +28,6 @@
## 0.30.0

Introduction of the Changelog.

[irrationalfab]: https://github.com/irrationalfab

5 changes: 4 additions & 1 deletion lib/cocoapods-core/specification/consumer.rb
Expand Up @@ -347,7 +347,10 @@ def prepare_hook_name(attr)
# @return [String] the prefix header.
#
def _prepare_prefix_header_contents(value)
value.is_a?(Array) ? value * "\n" : value
if value
value = value.join("\n") if value.is_a?(Array)
value.strip_heredoc.chomp
end
end

# Ensures that the file patterns of the resource bundles are contained in
Expand Down
5 changes: 3 additions & 2 deletions lib/cocoapods-core/specification/root_attribute_accessors.rb
Expand Up @@ -121,7 +121,7 @@ def summary
#
def description
description = attributes_hash["description"]
description.strip_heredoc if description
description.strip_heredoc.chomp if description
end

# @return [Array<String>] The list of the URL for the screenshots of
Expand All @@ -143,7 +143,8 @@ def documentation_url
# @return [String, Nil] The prepare command of the Pod if specified.
#
def prepare_command
attributes_hash["prepare_command"]
command = attributes_hash["prepare_command"]
command.strip_heredoc.chomp if command
end

#---------------------------------------------------------------------#
Expand Down
11 changes: 10 additions & 1 deletion spec/specification/consumer_spec.rb
Expand Up @@ -179,7 +179,16 @@ module Pod
end

it "allows to specify the contents of the prefix header as an array" do
@spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
@spec.prefix_header_contents = ['#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>']
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
end

it "strips the indentation of the prefix headers" do
headers = <<-DESC
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
DESC
@spec.prefix_header_contents = headers
@consumer.prefix_header_contents.should == "#import <UIKit/UIKit.h>\n#import <Foundation/Foundation.h>"
end

Expand Down
9 changes: 6 additions & 3 deletions spec/specification/root_attribute_accessors_spec.rb
Expand Up @@ -114,7 +114,7 @@ module Pod
Line2
DESC
@spec.description = desc
@spec.description.should == "Line1\nLine2\n"
@spec.description.should == "Line1\nLine2"
end

it "returns the screenshots" do
Expand All @@ -127,8 +127,11 @@ module Pod
@spec.screenshots.should == ['www.example.com/img1.png']
end

it "returns the prepare_command" do
@spec.prepare_command = 'ruby prepare_script.rb'
it "returns the prepare command stripping the indentation" do
command = <<-DESC
ruby prepare_script.rb
DESC
@spec.prepare_command = command
@spec.prepare_command.should == 'ruby prepare_script.rb'
end

Expand Down

0 comments on commit ff63023

Please sign in to comment.