This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write unit test for dependencies class
[#83883822]
- Loading branch information
Rasheed Abdul-Aziz and Sai To Yeung
committed
Dec 9, 2014
1 parent
b7cf21f
commit 08154be
Showing
6 changed files
with
97 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$LOAD_PATH << File.expand_path('../../lib', __FILE__) | ||
require 'dependencies' | ||
require 'compile_extensions' | ||
require 'yaml' | ||
|
||
uri = ARGV[0] | ||
cache_path = File.join(`pwd`.chomp, 'dependencies') | ||
|
||
dependencies = Dependencies.new | ||
manifest = YAML.load_file('manifest.yml') | ||
dependencies = CompileExtensions::Dependencies.new(manifest) | ||
|
||
translated_uri = dependencies.find_translated_dependency(uri) | ||
|
||
if translated_uri.nil? | ||
puts "DEPENDENCY_MISSING_IN_MANIFEST: #{uri}" | ||
exit 1 | ||
end | ||
|
||
if File.exist? cache_path | ||
file_path = File.join(cache_path, dependencies.find_translated_dependency(uri).gsub(/[\/:]/, '_')) | ||
file_path = File.join(cache_path, translated_uri.gsub(/[\/:]/, '_')) | ||
|
||
puts "file://#{file_path}" | ||
else | ||
puts dependencies.find_translated_dependency(uri) | ||
puts translated_uri | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'dependencies' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
require 'yaml' | ||
module CompileExtensions | ||
class Dependencies | ||
def initialize(manifest) | ||
@manifest = manifest | ||
end | ||
|
||
class Dependencies | ||
def find_matching_dependency(uri) | ||
manifest = YAML.load_file('manifest.yml') | ||
manifest['dependencies'].find do |dependency| | ||
dependency['original'] == uri | ||
def find_matching_dependency(uri) | ||
@manifest['dependencies'].find do |dependency| | ||
dependency['original'] == uri | ||
end | ||
end | ||
end | ||
|
||
def find_translated_dependency(uri) | ||
matching_dependency = find_matching_dependency(uri) | ||
def find_translated_dependency(uri) | ||
dependency = find_matching_dependency(uri) | ||
|
||
if matching_dependency.nil? | ||
puts "DEPENDENCY_MISSING_IN_MANIFEST: #{uri}" | ||
exit 1 | ||
end | ||
return nil if dependency.nil? | ||
|
||
matching_dependency['xlated'] | ||
dependency['xlated'] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require 'rspec' | ||
require 'tmpdir' | ||
require 'compile_extensions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
module CompileExtensions | ||
describe Dependencies do | ||
|
||
let(:manifest) { | ||
{ | ||
'dependencies' => [ | ||
{ | ||
'original' => 'https://google.com/backdoor', | ||
'xlated' => 'my_dog_has_fleas' | ||
}, | ||
{ | ||
'original' => 'https://google.com/frontdoor', | ||
'xlated' => 'i_do_not_like_green_eggs_and_ham' | ||
} | ||
] | ||
} | ||
} | ||
|
||
subject(:dependencies) { CompileExtensions::Dependencies.new(manifest) } | ||
|
||
describe 'find matching dependency hash' do | ||
let(:matching_dependency) { dependencies.find_matching_dependency(original_url) } | ||
|
||
context 'a key that should match the first item' do | ||
let(:original_url) { 'https://google.com/backdoor' } | ||
|
||
specify do | ||
expect(matching_dependency['original']).to eql('https://google.com/backdoor') | ||
expect(matching_dependency['xlated']).to eql('my_dog_has_fleas') | ||
end | ||
end | ||
|
||
context 'a key that should match another item' do | ||
let(:original_url) { 'https://google.com/frontdoor' } | ||
|
||
specify do | ||
expect(matching_dependency['original']).to eql('https://google.com/frontdoor') | ||
expect(matching_dependency['xlated']).to eql('i_do_not_like_green_eggs_and_ham') | ||
end | ||
end | ||
|
||
end | ||
|
||
describe 'find matching dependency translated url' do | ||
let(:translated_url) { dependencies.find_translated_dependency(original_url) } | ||
|
||
context 'a matching dependency' do | ||
let(:original_url) { 'https://google.com/backdoor' } | ||
|
||
specify do | ||
expect(translated_url).to eql('my_dog_has_fleas') | ||
end | ||
end | ||
|
||
context 'no matching dependency' do | ||
let(:original_url) { 'https://notthere.com' } | ||
|
||
specify do | ||
expect(translated_url).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |