Navigation Menu

Skip to content

Commit

Permalink
Adding colorize
Browse files Browse the repository at this point in the history
Abort on compile for uninitialized projects
  • Loading branch information
robertodecurnex committed Mar 22, 2016
1 parent 08a8c7e commit 3641f43
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/spectro.rb
@@ -1,3 +1,4 @@
require 'colorize'
require 'digest'
require 'forwardable'
require 'singleton'
Expand Down
4 changes: 4 additions & 0 deletions lib/spectro/compiler.rb
Expand Up @@ -22,6 +22,10 @@ class << self
#
# @return [Spectro::Compiler] self
def compile
if !Dir.exist?('.spectro')
abort "\n" + "This folder has not been initialzed as an Spectro project. Please run ".on_red + " spectro init ".on_light_black + " before compiling.".on_red + "\n\n"
end

undefined_yaml = YAML::Store.new(".spectro/undefined.yml")
undefined_yaml.transaction do
targets().map do |path|
Expand Down
9 changes: 5 additions & 4 deletions spectro.gemspec
Expand Up @@ -2,7 +2,7 @@ require 'rake'

Gem::Specification.new do |s|
s.authors = ['Roberto Decurnex']
s.date = '2015-01-13'
s.date = '2015-01-13'
s.email = 'decurnex.roberto@gmail.com'
s.homepage = 'http://github.com/robertodecurnex/spectro'
s.license = 'MIT'
Expand All @@ -12,15 +12,16 @@ Gem::Specification.new do |s|

s.bindir = 'bin'
s.executables << 'spectro'

s.files = FileList['lib/**/*.rb'].to_a

s.extra_rdoc_files = [
'README.md',
]

s.required_ruby_version = '>= 2.0.0'


s.add_runtime_dependency 'colorize'
s.add_runtime_dependency 'thor'

s.add_development_dependency 'codeclimate-test-reporter'
Expand Down
20 changes: 14 additions & 6 deletions test/minitest/spectro/test_compiler.rb
@@ -1,28 +1,28 @@
class TestSpectro < Minitest::Test

class TestCompiler < Minitest::Test

def setup
if File.exists?('test/files/.spectro/undefined.yml')
FileUtils.remove_file('test/files/.spectro/undefined.yml')
FileUtils.remove_file('test/files/.spectro/undefined.yml')
end
@compiler = Spectro::Compiler.instance
end

def teardown
if File.exists?('test/files/.spectro/undefined.yml')
FileUtils.remove_file('test/files/.spectro/undefined.yml')
FileUtils.remove_file('test/files/.spectro/undefined.yml')
end
end

def test_targets
Dir.chdir('test/files') do
Dir.chdir('test/files') do
assert_equal ['sample.rb', 'undefined_sample.rb'], @compiler.send(:targets).sort
end
end

def test_compile
Dir.chdir('test/files') do
Dir.chdir('test/files') do
@compiler.compile
end
expected_yaml = <<YAML
Expand Down Expand Up @@ -56,6 +56,14 @@ def test_compile
assert_equal YAML.load(expected_yaml), YAML.load_file('test/files/.spectro/undefined.yml')
end

def test_compile_without_init
Dir.chdir('test/uninitialized_project') do
assert_raises(SystemExit) do
@compiler.compile
end
end
end

end

end

0 comments on commit 3641f43

Please sign in to comment.