forked from thoughtbot/hoptoad_notifier
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configuration option and features for Rake handler
- Loading branch information
1 parent
9620bd6
commit 34521f9
Showing
5 changed files
with
110 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Feature: Use the Gem to catch errors in a Rake application | ||
Background: | ||
Given I have built and installed the "hoptoad_notifier" gem | ||
|
||
Scenario: Catching exceptions in Rake | ||
When I run rake with hoptoad | ||
Then Hoptoad should catch the exception | ||
|
||
Scenario: Disabling Rake exception catcher | ||
When I run rake with hoptoad disabled | ||
Then Hoptoad should not catch the exception | ||
|
||
Scenario: Autodetect, running from terminal | ||
When I run rake with hoptoad autodetect from terminal | ||
Then Hoptoad should not catch the exception | ||
|
||
Scenario: Autodetect, not running from terminal | ||
When I run rake with hoptoad autodetect not from terminal | ||
Then Hoptoad should catch the exception | ||
|
||
Scenario: Sendind the correct component name | ||
When I run rake with hoptoad | ||
Then Hoptoad should send the rake command line as the component name |
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,17 @@ | ||
When /I run rake with (.+)/ do |command| | ||
@rake_command = "rake #{command.gsub(' ','_')}" | ||
@rake_result = `cd features/support/rake && GEM_HOME=#{BUILT_GEM_ROOT} #{@rake_command} 2>&1` | ||
end | ||
|
||
Then /Hoptoad should (|not) ?catch the exception/ do |condition| | ||
if condition=='not' | ||
@rake_result.should_not =~ /^hoptoad/ | ||
else | ||
@rake_result.should =~ /^hoptoad/ | ||
end | ||
end | ||
|
||
Then /Hoptoad should send the rake command line as the component name/ do | ||
component = @rake_result.match(/^hoptoad (.*)$/)[1] | ||
component.should == @rake_command | ||
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,57 @@ | ||
# A test harness for RakeHandler | ||
# | ||
require 'rake' | ||
require 'rubygems' | ||
require 'hoptoad_notifier' | ||
require 'hoptoad_notifier/rake_handler' | ||
|
||
HoptoadNotifier.configure do |c| | ||
end | ||
|
||
# Should catch exception | ||
task :hoptoad do | ||
HoptoadNotifier.configuration.rescue_rake_exceptions = true | ||
stub_tty_output(true) | ||
raise_exception | ||
end | ||
|
||
# Should not catch exception | ||
task :hoptoad_disabled do | ||
HoptoadNotifier.configuration.rescue_rake_exceptions = false | ||
stub_tty_output(true) | ||
raise_exception | ||
end | ||
|
||
# Should not catch exception as tty_output is true | ||
task :hoptoad_autodetect_from_terminal do | ||
HoptoadNotifier.configuration.rescue_rake_exceptions = nil | ||
stub_tty_output(true) | ||
raise_exception | ||
end | ||
|
||
# Should catch exception as tty_output is false | ||
task :hoptoad_autodetect_not_from_terminal do | ||
HoptoadNotifier.configuration.rescue_rake_exceptions = nil | ||
stub_tty_output(false) | ||
raise_exception | ||
end | ||
|
||
module HoptoadNotifier | ||
def self.notify(*args) | ||
# TODO if you need to check more params, you'll have to use json.dump or something | ||
$stderr.puts "hoptoad #{args[1][:component]}" | ||
end | ||
end | ||
|
||
def stub_tty_output(value) | ||
Rake.application.instance_eval do | ||
@tty_output_stub = value | ||
def tty_output? | ||
@tty_output_stub | ||
end | ||
end | ||
end | ||
|
||
def raise_exception | ||
raise 'TEST' | ||
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