Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
added helper spec file.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Apr 11, 2016
1 parent b47668e commit 10f4b7d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/capsulecd/ruby/ruby_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def build_step
super
gemspec_path = CapsuleCD::Ruby::RubyHelper.get_gemspec_path(@source_git_local_path)

# check for/create required VERSION file
gemspec_data = CapsuleCD::Ruby::RubyHelper.load_gemspec_data(gemspec_path)
# check for required VERSION file
gemspec_data = CapsuleCD::Ruby::RubyHelper.get_gemspec_data(@source_git_local_path)

if !gemspec_data || !File.exist?(CapsuleCD::Ruby::RubyHelper.version_filepath(@source_git_local_path, gemspec_data.name))
if !File.exist?(CapsuleCD::Ruby::RubyHelper.version_filepath(@source_git_local_path, gemspec_data.name))
fail CapsuleCD::Error::BuildPackageInvalid, 'version.rb file is required to process Ruby gem'
end

Expand Down
9 changes: 8 additions & 1 deletion lib/capsulecd/ruby/ruby_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def self.get_gemspec_data(repo_path)
self.load_gemspec_data(self.get_gemspec_path(repo_path))
end

##################################################################################################################
# protected/private methods.

# since the Gem::Specification class is basically eval'ing the gemspec file, and the gemspec file is doing a require
# to load the version.rb file, the version.rb file is cached in memory. We're going to try to get around that issue
# by parsing the gemspec file in a forked process.
Expand All @@ -49,9 +52,13 @@ def self.execute_in_child
end

def self.load_gemspec_data(gemspec_path)
return self.execute_in_child do
gemspec_data = self.execute_in_child do
Gem::Specification::load(gemspec_path)
end
if !gemspec_data
fail CapsuleCD::Error::BuildPackageInvalid, '*.gemspec could not be parsed.'
end
return gemspec_data
end


Expand Down
51 changes: 51 additions & 0 deletions spec/lib/capsulecd/ruby/ruby_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'CapsuleCD::Ruby::RubyHelper', :ruby do
subject{
CapsuleCD::Ruby::RubyHelper
}
describe '#version_filepath' do
it 'default should generate the correct path to version.rb' do
expect(subject.version_filepath('/tmp','capsulecd')).to eql('/tmp/lib/capsulecd/version.rb')
end
it 'with custom version filename should generate the correct path' do
expect(subject.version_filepath('/tmp','capsulecd', 'VERSION.rb')).to eql('/tmp/lib/capsulecd/VERSION.rb')
end
end

describe '#get_gemspec_path' do
describe 'without a gemspec file' do
it 'should raise an error' do
expect{subject.get_gemspec_path(test_directory)}.to raise_error(CapsuleCD::Error::BuildPackageInvalid)
end
end

describe 'with a valid gemspec file' do
it 'should generate correct gemspec path' do
FileUtils.copy_entry('spec/fixtures/ruby/gem_analogj_test', test_directory)

expect(subject.get_gemspec_path(test_directory)).to eql(test_directory + '/gem_analogj_test.gemspec')
end
end
end

describe '#get_gemspec_data' do
it 'should parse gemspec data' do
FileUtils.copy_entry('spec/fixtures/ruby/gem_analogj_test', test_directory)
gemspec_data = subject.get_gemspec_data(test_directory)
expect(gemspec_data.name).to eql('gem_analogj_test')
expect(gemspec_data.version.to_s).to eql('0.1.3')
end

describe 'with an invalid gemspec file' do
it 'should raise an error' do
FileUtils.copy_entry('spec/fixtures/ruby/gem_analogj_test', test_directory)
FileUtils.rm(test_directory + '/lib/gem_analogj_test/version.rb')

expect{subject.get_gemspec_data(test_directory)}.to raise_error(CapsuleCD::Error::BuildPackageInvalid)
end
end

end

end

0 comments on commit 10f4b7d

Please sign in to comment.