This repository has been archived by the owner on Nov 11, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for the installation process
- Loading branch information
Showing
12 changed files
with
165 additions
and
20 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -11,3 +11,4 @@ tags | ||
.yardoc | .yardoc | ||
doc | doc | ||
pkg | pkg | ||
*.gemspec |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
require 'sham_rack' | |||
|
|||
ShamRack.at("hoptoadapp.com") do |env| | |||
["200 OK", { "Content-type" => "text/xml" }, "<notice/>"] | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,11 +1 @@ | |||
if defined?(ActionController::Base) && !ActionController::Base.include?(HoptoadNotifier::Catcher) | require 'hoptoad_notifier/rails' | ||
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 |