Skip to content

Commit

Permalink
Implement #turn_off for TerminalNotifier. Fixes #472.
Browse files Browse the repository at this point in the history
  • Loading branch information
rymai committed Sep 11, 2013
1 parent c21611f commit 05637fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -40,7 +40,8 @@

### Bug fixes

- [#457][] Raise an exception when a group is called "all". Fixes [#457][]. (reported by [@rweng][], fixed by [@rymai][])
- [#472][] Implement #turn_off for TerminalNotifier. (reported by [@shyam-habarakada][], fixed by [@rymai][])
- [#457][] Raise an exception when a group is called "all". (reported by [@rweng][], fixed by [@rymai][])
- [#471][] Only init once per plugin when running `guard init` (reported by [@simon-ohara][], fixed by [@thibaudgg][])
- [#456][] Fix notifu notifier. ([@netzpirat][])
- [#435][] Fix pressing `C-c` when interactor thread is not started. ([@netzpirat][])
Expand Down Expand Up @@ -839,6 +840,7 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[#460]: https://github.com/guard/guard/issues/460
[#463]: https://github.com/guard/guard/issues/463
[#471]: https://github.com/guard/guard/issues/471
[#472]: https://github.com/guard/guard/issues/472
[@Gazer]: https://github.com/Gazer
[@Maher4Ever]: https://github.com/Maher4Ever
[@Nerian]: https://github.com/Nerian
Expand Down Expand Up @@ -914,6 +916,7 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@schmurfy]: https://github.com/schmurfy
[@scottdavis]: https://github.com/scottdavis
[@semperos]: https://github.com/semperos
[@shyam-habarakada]: https://github.com/shyam-habarakada
[@simon-ohara]: https://github.com/simon-ohara
[@spadin]: https://github.com/spadin
[@steakknife]: https://github.com/steakknife
Expand Down
8 changes: 7 additions & 1 deletion lib/guard/notifiers/terminal_notifier.rb
Expand Up @@ -57,7 +57,13 @@ def notify(message, opts = {})
opts.delete(:image)
opts[:title] = title || [opts.delete(:app_name) { 'Guard' }, opts[:type].downcase.capitalize].join(' ')

::TerminalNotifier::Guard.execute(false, opts.merge(message: message))
::TerminalNotifier::Guard.notify(message, opts)
end

# Notification stopping. Restore the previous Terminal title state.
#
def turn_off
::TerminalNotifier::Guard.remove
end

# @private
Expand Down
23 changes: 11 additions & 12 deletions spec/guard/notifiers/terminal_notifier_spec.rb
Expand Up @@ -26,33 +26,32 @@

describe '#notify' do
it 'should call the notifier.' do
::TerminalNotifier::Guard.should_receive(:execute).with(false,
title: 'any title',
type: :success,
message: 'any message')
::TerminalNotifier::Guard.should_receive(:notify).with('any message', title: 'any title', type: :success)

notifier.notify('any message', title: 'any title')
end

it "should allow the title to be customized" do
::TerminalNotifier::Guard.should_receive(:execute).with(false,
title: 'any title',
message: 'any message',
type: :error)
::TerminalNotifier::Guard.should_receive(:notify).with('any message', title: 'any title', type: :error)

notifier.notify('any message', type: :error, title: 'any title')
end

context 'without a title set' do
it 'should show the app name in the title' do
::TerminalNotifier::Guard.should_receive(:execute).with(false,
title: 'FooBar Success',
type: :success,
message: 'any message')
::TerminalNotifier::Guard.should_receive(:notify).with('any message', title: 'FooBar Success', type: :success)

notifier.notify('any message', title: nil, app_name: 'FooBar')
end
end
end

describe '#turn_off' do
it 'should call #remove on the notifier.' do
::TerminalNotifier::Guard.should_receive(:remove)

notifier.turn_off
end
end

end

0 comments on commit 05637fc

Please sign in to comment.