Skip to content

Commit

Permalink
Switched out the Guard::UI and Guard::Notifier calls to use the Guard…
Browse files Browse the repository at this point in the history
…::CoffeeScript::Formatter instead.
  • Loading branch information
vizjerai committed May 12, 2011
1 parent 113fe08 commit 6373e23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/guard/coffeescript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Guard
class CoffeeScript < Guard

autoload :Formatter, 'guard/coffeescript/formatter'
autoload :Inspector, 'guard/coffeescript/inspector'
autoload :Runner, 'guard/coffeescript/runner'

Expand Down
12 changes: 6 additions & 6 deletions lib/guard/coffeescript/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def run(files, watchers, options = {})

changed_files
rescue ::CoffeeScript::EngineError => e
::Guard::UI.error "CoffeeScript engine error: " + e.message
Formatter.error("CoffeeScript engine error: " + e.message)
end

private

def notify_start(files, options)
message = options[:message] || "Compile #{ files.join(', ') }"
::Guard::UI.info message, :reset => true
Formatter.info(message, :reset => true)
end

def compile_files(files, options, watchers)
Expand All @@ -35,7 +35,7 @@ def compile_files(files, options, watchers)
rescue ::CoffeeScript::CompilationError => e
error_message = file + ': ' + e.message
errors << error_message
::Guard::UI.error(error_message)
Formatter.error(error_message)
end
end
end
Expand Down Expand Up @@ -76,11 +76,11 @@ def detect_nested_directories(watchers, files, options)

def notify_result(changed_files, errors, options = {})
if !errors.empty?
::Guard::Notifier.notify(errors.join("\n"), :title => 'CoffeeScript results', :image => :failed)
Formatter.notify(errors.join("\n"), :title => 'CoffeeScript results', :image => :failed)
elsif !options[:hide_success]
message = "Successfully generated #{ changed_files.join(', ') }"
::Guard::UI.info(message)
::Guard::Notifier.notify(message, :title => 'CoffeeScript results')
Formatter.success(message)
Formatter.notify(message, :title => 'CoffeeScript results')
end
end

Expand Down
11 changes: 5 additions & 6 deletions spec/guard/coffeescript/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
end

it 'shows a start notification' do
::Guard::UI.should_receive(:info).once.with('Compile a.coffee, b.coffee', { :reset => true })
::Guard::UI.should_receive(:info).once.with('Successfully generated ')
::Guard::CoffeeScript::Formatter.should_receive(:info).once.with('Compile a.coffee, b.coffee', { :reset => true })
::Guard::CoffeeScript::Formatter.should_receive(:success).once.with('Successfully generated ')
runner.run(['a.coffee', 'b.coffee'], [])
end

Expand Down Expand Up @@ -50,7 +50,7 @@
context 'with compilation errors' do
it 'shows the error messages' do
runner.should_receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'")
::Guard::UI.should_receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'")
::Guard::CoffeeScript::Formatter.should_receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'")
Guard::Notifier.should_receive(:notify).with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", :title => 'CoffeeScript results', :image => :failed)
runner.run(['a.coffee'], [watcher], { :output => 'javascripts' })
end
Expand All @@ -60,8 +60,7 @@
it 'shows a success messages' do
runner.should_receive(:compile).with('a.coffee', { :output => 'javascripts' }).and_return ["OK", true]
runner.should_receive(:notify_start).with(['a.coffee'], { :output => 'javascripts' })
::Guard::UI.should_receive(:info).with("\"^(.*)\\.coffee\" has been converted to /^(.*)\\.coffee/\n")
::Guard::UI.should_receive(:info).with('Successfully generated javascripts/a.js')
::Guard::CoffeeScript::Formatter.should_receive(:success).once.with('Successfully generated javascripts/a.js')
Guard::Notifier.should_receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results')
runner.run(['a.coffee'], [watcher], { :output => 'javascripts' })
end
Expand All @@ -71,7 +70,7 @@

it 'compiles the CoffeeScripts to the output and creates nested directories' do
FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y")
::Guard::UI.should_not_receive(:info).with('Successfully generated javascripts/a.js')
::Guard::CoffeeScript::Formatter.should_not_receive(:success).with('Successfully generated javascripts/a.js')
Guard::Notifier.should_not_receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results')
runner.run(['app/coffeescripts/x/y/a.coffee'], [watcher], { :output => 'javascripts', :hide_success => true })
end
Expand Down

0 comments on commit 6373e23

Please sign in to comment.