Skip to content

Commit

Permalink
Changed rake tasks to be included instead of copied
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 19, 2010
1 parent 18854ae commit ad3d087
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
log/* log/*
tmp/**/* tmp
db/schema.rb db/schema.rb
db/*.sqlite3 db/*.sqlite3
public/system public/system
Expand Down
9 changes: 9 additions & 0 deletions features/rails.feature
Expand Up @@ -10,6 +10,15 @@ Feature: Install the Gem in a Rails application
And I run "script/generate hoptoad -k myapikey" And I run "script/generate hoptoad -k myapikey"
Then I should receive a Hoptoad notification Then I should receive a Hoptoad notification


Scenario: vendor the gem and uninstall
When I generate a new Rails application
And I configure the Hoptoad shim
And I configure my application to require the "hoptoad_notifier" gem
And I run "rake gems:unpack"
And I uninstall the "hoptoad_notifier" gem
And I run "script/generate hoptoad -k myapikey"
Then I should receive a Hoptoad notification

Scenario: Configure the notifier by hand Scenario: Configure the notifier by hand
When I generate a new Rails application When I generate a new Rails application
And I configure the Hoptoad shim And I configure the Hoptoad shim
Expand Down
4 changes: 4 additions & 0 deletions features/step_definitions/rails_application_steps.rb
Expand Up @@ -52,3 +52,7 @@
Then /^I should see "([^\"]*)"$/ do |expected_text| Then /^I should see "([^\"]*)"$/ do |expected_text|
@terminal.output.should include(expected_text) @terminal.output.should include(expected_text)
end end

When /^I uninstall the "([^\"]*)" gem$/ do |gem_name|
@terminal.uninstall_gem(gem_name)
end
10 changes: 9 additions & 1 deletion features/support/terminal.rb
Expand Up @@ -3,13 +3,13 @@
end end


class Terminal class Terminal

attr_reader :output, :status attr_reader :output, :status


def initialize def initialize
@cwd = FileUtils.pwd @cwd = FileUtils.pwd
@output = "" @output = ""
@status = 0 @status = 0
@logger = Logger.new(File.join(TEMP_DIR, 'terminal.log'))
end end


def cd(directory) def cd(directory)
Expand All @@ -19,7 +19,9 @@ def cd(directory)
def run(command) def run(command)
output << "#{command}\n" output << "#{command}\n"
FileUtils.cd(@cwd) do FileUtils.cd(@cwd) do
logger.debug(command)
result = `#{environment_settings} #{command} 2>&1` result = `#{environment_settings} #{command} 2>&1`
logger.debug(result)
output << result output << result
end end
@status = $? @status = $?
Expand All @@ -39,6 +41,10 @@ def install_gem(gem)
install_gem_to(LOCAL_GEM_ROOT, gem) install_gem_to(LOCAL_GEM_ROOT, gem)
end end


def uninstall_gem(gem)
`gem uninstall -i #{BUILT_GEM_ROOT} #{gem}`
end

private private


def install_gem_to(root, gem) def install_gem_to(root, gem)
Expand All @@ -48,4 +54,6 @@ def install_gem_to(root, gem)
def environment_settings def environment_settings
"GEM_HOME=#{LOCAL_GEM_ROOT} GEM_PATH=#{LOCAL_GEM_ROOT}:#{BUILT_GEM_ROOT}" "GEM_HOME=#{LOCAL_GEM_ROOT} GEM_PATH=#{LOCAL_GEM_ROOT}:#{BUILT_GEM_ROOT}"
end end

attr_reader :logger
end end
90 changes: 3 additions & 87 deletions generators/hoptoad/templates/hoptoad_notifier_tasks.rake
@@ -1,89 +1,5 @@
namespace :hoptoad do Dir[File.join(RAILS_ROOT, 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
desc "Notify Hoptoad of a new deploy." $: << File.join(vendored_notifier, 'lib')
task :deploy => :environment do
require 'hoptoad_tasks'
HoptoadTasks.deploy(:rails_env => ENV['TO'],
:scm_revision => ENV['REVISION'],
:scm_repository => ENV['REPO'],
:local_username => ENV['USER'],
:api_key => ENV['API_KEY'])
end

task :log_stdout do
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end

desc "Verify your gem installation by sending a test exception to the hoptoad service"
task :test => ['hoptoad:log_stdout', :environment] do
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG

require 'action_controller/test_process'
require 'app/controllers/application' if File.exists?('app/controllers/application.rb')

request = ActionController::TestRequest.new
response = ActionController::TestResponse.new

class HoptoadTestingException < RuntimeError; end

unless HoptoadNotifier.configuration.api_key
puts "Hoptoad needs an API key configured! Check the README to see how to add it."
exit
end

HoptoadNotifier.configuration.development_environments = []

in_controller = ApplicationController.included_modules.include? HoptoadNotifier::Catcher
in_base = ActionController::Base.included_modules.include? HoptoadNotifier::Catcher
if !in_controller || !in_base
puts "HoptoadNotifier::Catcher must be included inside your ApplicationController class."
exit
end

puts "Configuration:"
HoptoadNotifier.configuration.to_hash.each do |key, value|
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
end

puts 'Setting up the Controller.'
class ApplicationController
# This is to bypass any filters that may prevent access to the action.
prepend_before_filter :test_hoptoad
def test_hoptoad
puts "Raising '#{exception_class.name}' to simulate application failure."
raise exception_class.new, 'Testing hoptoad via "rake hoptoad:test". If you can see this, it works.'
end

def rescue_action exception
rescue_action_in_public exception
end

# Ensure we actually have an action to go to.
def verify; end

def consider_all_requests_local
false
end

def local_request?
false
end

def exception_class
exception_name = ENV['EXCEPTION'] || "HoptoadTestingException"
Object.const_get(exception_name)
rescue
Object.const_set(exception_name, Class.new(Exception))
end

def logger
nil
end
end

puts 'Processing request.'
class HoptoadVerificationController < ApplicationController; end
HoptoadVerificationController.new.process(request, response)
end
end end


require 'hoptoad_notifier/tasks'
91 changes: 91 additions & 0 deletions lib/hoptoad_notifier/tasks.rb
@@ -0,0 +1,91 @@
require 'hoptoad_notifier'

namespace :hoptoad do
desc "Notify Hoptoad of a new deploy."
task :deploy => :environment do
require 'hoptoad_tasks'
HoptoadTasks.deploy(:rails_env => ENV['TO'],
:scm_revision => ENV['REVISION'],
:scm_repository => ENV['REPO'],
:local_username => ENV['USER'],
:api_key => ENV['API_KEY'])
end

task :log_stdout do
require 'logger'
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
end

desc "Verify your gem installation by sending a test exception to the hoptoad service"
task :test => ['hoptoad:log_stdout', :environment] do
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG

require 'action_controller/test_process'
require 'app/controllers/application' if File.exists?('app/controllers/application.rb')

request = ActionController::TestRequest.new
response = ActionController::TestResponse.new

class HoptoadTestingException < RuntimeError; end

unless HoptoadNotifier.configuration.api_key
puts "Hoptoad needs an API key configured! Check the README to see how to add it."
exit
end

HoptoadNotifier.configuration.development_environments = []

in_controller = ApplicationController.included_modules.include? HoptoadNotifier::Catcher
in_base = ActionController::Base.included_modules.include? HoptoadNotifier::Catcher
if !in_controller || !in_base
puts "HoptoadNotifier::Catcher must be included inside your ApplicationController class."
exit
end

puts "Configuration:"
HoptoadNotifier.configuration.to_hash.each do |key, value|
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
end

puts 'Setting up the Controller.'
class ApplicationController
# This is to bypass any filters that may prevent access to the action.
prepend_before_filter :test_hoptoad
def test_hoptoad
puts "Raising '#{exception_class.name}' to simulate application failure."
raise exception_class.new, 'Testing hoptoad via "rake hoptoad:test". If you can see this, it works.'
end

def rescue_action exception
rescue_action_in_public exception
end

# Ensure we actually have an action to go to.
def verify; end

def consider_all_requests_local
false
end

def local_request?
false
end

def exception_class
exception_name = ENV['EXCEPTION'] || "HoptoadTestingException"
Object.const_get(exception_name)
rescue
Object.const_set(exception_name, Class.new(Exception))
end

def logger
nil
end
end

puts 'Processing request.'
class HoptoadVerificationController < ApplicationController; end
HoptoadVerificationController.new.process(request, response)
end
end

0 comments on commit ad3d087

Please sign in to comment.