Skip to content
Browse files

Added a test for the installation process

  • Loading branch information...
1 parent bf486bb commit 7df97d7929364c7af53533b532c3e2f71614a39f @jferris jferris committed Jan 13, 2010
View
1 .gitignore
@@ -11,3 +11,4 @@ tags
.yardoc
doc
pkg
+*.gemspec
View
32 Rakefile
@@ -2,9 +2,10 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
+require 'cucumber/rake/task'
desc 'Default: run unit tests.'
-task :default => :test
+task :default => [:test, :cucumber]
desc 'Test the hoptoad_notifier gem.'
Rake::TestTask.new(:test) do |t|
@@ -29,8 +30,8 @@ begin
rescue LoadError
end
-PLUGIN_ROOT = File.dirname(__FILE__).freeze
-VERSION_FILE = File.join(PLUGIN_ROOT, 'lib', 'hoptoad_notifier', 'version')
+GEM_ROOT = File.dirname(__FILE__).freeze
+VERSION_FILE = File.join(GEM_ROOT, 'lib', 'hoptoad_notifier', 'version')
require VERSION_FILE
@@ -40,7 +41,7 @@ gemspec = Gem::Specification.new do |s|
s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}
s.files = FileList['[A-Z]*', 'generators/**/*.*', 'lib/**/*.rb',
- 'test/**/*.rb', 'rails/**.*.rb', 'recipes/**/*.rb',
+ 'test/**/*.rb', 'rails/**/*.rb', 'recipes/**/*.rb',
'tasks/**/*.rake']
s.require_path = 'lib'
s.test_files = Dir[*['test/**/*_test.rb']]
@@ -71,3 +72,26 @@ task :gemspec do
end
end
+LOCAL_GEM_ROOT = File.join(GEM_ROOT, 'tmp', 'local_gems').freeze
+LOCAL_GEMS = %w(rails sham_rack)
+
+task :vendor_test_gems do
+ LOCAL_GEMS.each do |gem_name|
+ pattern = File.join(LOCAL_GEM_ROOT, 'gems', "#{gem_name}-*")
+ existing = Dir.glob(pattern).first
+ unless existing
+ command = "gem install -i #{LOCAL_GEM_ROOT} --no-ri --no-rdoc #{gem_name}"
+ puts "Vendoring #{gem_name}..."
+ unless system(command)
+ $stderr.puts "Command failed: #{command}"
+ end
+ end
+ end
+end
+
+Cucumber::Rake::Task.new(:cucumber) do |t|
+ t.fork = true
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
+end
+
+task :cucumber => [:gemspec, :vendor_test_gems]
View
12 features/rails.feature
@@ -0,0 +1,12 @@
+Feature: Install the Gem in a Rails application
+
+ Background:
+ Given I have built and installed the "hoptoad_notifier" gem
+
+ Scenario: Use config.gem without vendoring the gem in a Rails application
+ 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 "script/generate hoptoad -k myapikey"
+ And I run "rake hoptoad:test --trace"
+ Then I should receive a Hoptoad notification
View
39 features/step_definitions/rails_application_steps.rb
@@ -0,0 +1,39 @@
+When /^I generate a new Rails application$/ do
+ @terminal.cd(TEMP_DIR)
+ @terminal.run("rails rails_root")
+end
+
+Given /^I have installed the "([^\"]*)" gem$/ do |gem_name|
+ @terminal.install_gem(gem_name)
+end
+
+Given /^I have built and installed the "([^\"]*)" gem$/ do |gem_name|
+ @terminal.build_and_install_gem(File.join(PROJECT_ROOT, "#{gem_name}.gemspec"))
+end
+
+When /^I configure my application to require the "([^\"]*)" gem$/ do |gem_name|
+ path = File.join(RAILS_ROOT, 'config', 'environment.rb')
+ run = "Rails::Initializer.run do |config|"
+ insert = " config.gem '#{gem_name}'"
+ content = File.read(path)
+ if content.sub!(run, "#{run}\n#{insert}")
+ File.open(path, 'wb') { |file| file.write(content) }
+ else
+ raise "Couldn't find #{run.inspect} in #{path}"
+ end
+end
+
+When /^I run "([^\"]*)"$/ do |command|
+ @terminal.cd(RAILS_ROOT)
+ @terminal.run(command)
+end
+
+Then /^I should receive a Hoptoad notification$/ do
+ @terminal.output.should include("[Hoptoad] Success: Net::HTTPOK")
+end
+
+When /^I configure the Hoptoad shim$/ do
+ shim_file = File.join(PROJECT_ROOT, 'features', 'support', 'hoptoad_shim.rb.template')
+ target = File.join(RAILS_ROOT, 'config', 'initializers', 'hoptoad_shim.rb')
+ FileUtils.cp(shim_file, target)
+end
View
12 features/support/env.rb
@@ -0,0 +1,12 @@
+PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
+TEMP_DIR = File.join(PROJECT_ROOT, 'tmp').freeze
+RAILS_ROOT = File.join(TEMP_DIR, 'rails_root').freeze
+BUILT_GEM_ROOT = File.join(TEMP_DIR, 'built_gems').freeze
+LOCAL_GEM_ROOT = File.join(TEMP_DIR, 'local_gems').freeze
+
+Before do
+ FileUtils.mkdir_p(TEMP_DIR)
+ FileUtils.rm_rf(BUILT_GEM_ROOT)
+ FileUtils.rm_rf(RAILS_ROOT)
+ FileUtils.mkdir_p(BUILT_GEM_ROOT)
+end
View
5 features/support/hoptoad_shim.rb.template
@@ -0,0 +1,5 @@
+require 'sham_rack'
+
+ShamRack.at("hoptoadapp.com") do |env|
+ ["200 OK", { "Content-type" => "text/xml" }, "<notice/>"]
+end
View
51 features/support/terminal.rb
@@ -0,0 +1,51 @@
+Before do
+ @terminal = Terminal.new
+end
+
+class Terminal
+
+ attr_reader :output, :status
+
+ def initialize
+ @cwd = FileUtils.pwd
+ @output = ""
+ @status = 0
+ end
+
+ def cd(directory)
+ @cwd = directory
+ end
+
+ def run(command)
+ output << "#{command}\n"
+ FileUtils.cd(@cwd) do
+ result = `#{environment_settings} #{command} 2>&1`
+ output << result
+ end
+ @status = $?
+ end
+
+ def build_and_install_gem(gemspec)
+ pkg_dir = File.join(TEMP_DIR, 'pkg')
+ FileUtils.mkdir_p(pkg_dir)
+ `gem build #{gemspec} 2>&1`
+ gem_file = Dir.glob("*.gem").first
+ target = File.join(pkg_dir, gem_file)
+ FileUtils.mv(gem_file, target)
+ install_gem_to(BUILT_GEM_ROOT, target)
+ end
+
+ def install_gem(gem)
+ install_gem_to(LOCAL_GEM_ROOT, gem)
+ end
+
+ private
+
+ def install_gem_to(root, gem)
+ `gem install -i #{root} --no-ri --no-rdoc #{gem}`
+ end
+
+ def environment_settings
+ "GEM_HOME=#{LOCAL_GEM_ROOT} GEM_PATH=#{LOCAL_GEM_ROOT}:#{BUILT_GEM_ROOT}"
+ end
+end
View
8 generators/hoptoad/hoptoad_generator.rb
@@ -14,14 +14,14 @@ def manifest
record do |m|
m.directory 'lib/tasks'
m.file 'hoptoad_notifier_tasks.rake', 'lib/tasks/hoptoad_notifier_tasks.rake'
- if File.exists?('config/deploy.rb')
- m.insert_into 'config/deploy.rb', "require 'hoptoad_notifier/recipes/hoptoad'"
- end
+ # if File.exists?('config/deploy.rb')
+ # m.insert_into 'config/deploy.rb', "require 'hoptoad_notifier/recipes/hoptoad'"
+ # end
unless options[:api_key].nil?
m.template 'initializer.rb', 'config/initializers/hoptoad.rb',
:assigns => {:api_key => options[:api_key]}
end
- m.rake "hoptoad:test", :generate_only => true
+ # m.rake "hoptoad:test", :generate_only => true
end
end
end
View
1 init.rb
@@ -1 +0,0 @@
-require File.join(File.dirname(__FILE__), 'rails', 'init')
View
1 lib/hoptoad_notifier.rb
@@ -2,6 +2,7 @@
require 'net/https'
require 'rubygems'
require 'active_support'
+require 'hoptoad_notifier/version'
require 'hoptoad_notifier/configuration'
require 'hoptoad_notifier/notice'
require 'hoptoad_notifier/sender'
View
11 lib/hoptoad_notifier/rails.rb
@@ -0,0 +1,11 @@
+if defined?(ActionController::Base) && !ActionController::Base.include?(HoptoadNotifier::Catcher)
+ ActionController::Base.send(:include, HoptoadNotifier::Catcher)
+end
+
+require 'hoptoad_notifier/rails_initializer'
+HoptoadNotifier::RailsInitializer.initialize
+
+HoptoadNotifier.configure(true) do |config|
+ config.environment_name = RAILS_ENV
+ config.project_root = RAILS_ROOT
+end
View
12 rails/init.rb
@@ -1,11 +1 @@
-if defined?(ActionController::Base) && !ActionController::Base.include?(HoptoadNotifier::Catcher)
- ActionController::Base.send(:include, HoptoadNotifier::Catcher)
-end
-
-require File.join(File.dirname(__FILE__), '..', 'lib', 'hoptoad_notifier', 'rails_initializer')
-HoptoadNotifier::RailsInitializer.initialize
-
-HoptoadNotifier.configure(true) do |config|
- config.environment_name = RAILS_ENV
- config.project_root = RAILS_ROOT
-end
+require 'hoptoad_notifier/rails'

0 comments on commit 7df97d7

Please sign in to comment.
Something went wrong with that request. Please try again.