Skip to content

Commit

Permalink
Fix an issue that sometimes caused Pod::Version instances to be seria…
Browse files Browse the repository at this point in the history
…lized as a hash inside the :source hash
  • Loading branch information
amorde committed Oct 27, 2023
1 parent 1294797 commit 5a231f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cocoapods-core/specification/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module JSONSupport
#
def to_json(*a)
require 'json'
to_hash.to_json(*a) << "\n"
JSON.dump(to_hash, *a) << "\n"
end

# @return [String] the pretty json representation of the specification.
Expand Down
27 changes: 27 additions & 0 deletions spec/specification/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ module Pod
JSON.parse(spec.to_json).should == expected
end

it 'serializes tags with Pod::Version correctly' do
spec = Specification.new(nil, 'BananaLib') do |spec|
spec.version = '1.0'
spec.version.class.should == Pod::Version
spec.source = {
:git => 'https://github.com/CocoaPods/CocoaPodsExampleLibrary.git',
:tag => spec.version
}
end
expected = {
'name' => 'BananaLib',
'version' => '1.0',
'source' => {
'git' => 'https://github.com/CocoaPods/CocoaPodsExampleLibrary.git',
'tag' => '1.0'
},
'platforms' => {
'osx' => nil,
'ios' => nil,
'tvos' => nil,
'visionos'=> nil,
'watchos' => nil,
},
}
JSON.parse(spec.to_json).should == expected
end

it 'terminates the json representation with a new line' do
spec = Specification.new(nil, 'BananaLib')
spec.to_json.should.end_with "\n"
Expand Down

0 comments on commit 5a231f8

Please sign in to comment.