-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dependency management test cases for each `Filter` with a dependency * Add `assert_dependency_management_error` custom assertion which asserts a custom exception and message are raised if a dependency is missing * Move all `Filter` dependencies to `Gemfile` `:test` block for test cases and CI * Implement `TestingDependency` helper to abstract unloading and loading `Gemfile` `:test` block gems when asserting dependency management errors * Implement `MissingDependencyException` custom exception with `MESSAGE` constant as a format string, so each `Filter` raises a uniform exception * Add `begin..rescue..end` blocks around each `Filter` `require` statement to raise a `MissingDependencyException` when a gem can not be loaded * Update README.md detailing new dependency management with listing of `Filter` gem dependencies * Add gemspec post install message to inform users their apps must bundle `Filter` dependencies
- Loading branch information
Simeon F. Willbanks
committed
Aug 25, 2013
1 parent
a731d82
commit d3fc6d9
Showing
23 changed files
with
282 additions
and
46 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 |
---|---|---|
@@ -1,9 +1,24 @@ | ||
source 'https://rubygems.org' | ||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in html-pipeline.gemspec | ||
gemspec | ||
|
||
group :development do | ||
gem 'bundler' | ||
gem 'rake' | ||
gem "bundler" | ||
gem "rake" | ||
end | ||
|
||
group :test do | ||
gem "rinku", "~> 1.7", :require => false | ||
gem "gemoji", "~> 1.0", :require => false | ||
gem "RedCloth", "~> 4.2.9", :require => false | ||
gem "escape_utils", "~> 0.3", :require => false | ||
gem "github-linguist", "~> 2.6.2", :require => false | ||
gem "github-markdown", "~> 0.5", :require => false | ||
|
||
if RUBY_VERSION < "1.9.2" | ||
gem "sanitize", ">= 2", "< 2.0.4", :require => false | ||
else | ||
gem "sanitize", "~> 2.0", :require => false | ||
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
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
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
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
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,92 @@ | ||
# Public: Methods useful for testing Filter dependencies. All methods are class | ||
# methods and should be called on the TestingDependency class. | ||
# | ||
# Examples | ||
# | ||
# TestingDependency.temporarily_remove_dependency_by gem_name do | ||
# exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do | ||
# load TestingDependency.filter_path_from filter_name | ||
# end | ||
# end | ||
class TestingDependency | ||
# Public: Use to safely test a Filter's gem dependency error handling. | ||
# For a certain gem dependency, remove the gem's loaded paths and features. | ||
# Once these are removed, yield to a block which can assert a specific | ||
# exception. Once the block is finished, add back the gem's paths and | ||
# features to the load path and loaded features, so other tests can assert | ||
# Filter functionality. | ||
# | ||
# gem_name - The String of the gem's name. | ||
# block - Required block which asserts gem dependency error handling. | ||
# | ||
# Examples | ||
# | ||
# TestingDependency.temporarily_remove_dependency_by gem_name do | ||
# exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do | ||
# load TestingDependency.filter_path_from filter_name | ||
# end | ||
# end | ||
# | ||
# Returns nothing. | ||
def self.temporarily_remove_dependency_by(gem_name, &block) | ||
paths = gem_load_paths_from gem_name | ||
features = gem_loaded_features_from gem_name | ||
|
||
$LOAD_PATH.delete_if { |path| paths.include? path } | ||
$LOADED_FEATURES.delete_if { |feature| features.include? feature } | ||
|
||
yield | ||
|
||
$LOAD_PATH.unshift(*paths) | ||
$LOADED_FEATURES.unshift(*features) | ||
end | ||
|
||
# Public: Find a Filter's load path. | ||
# | ||
# gem_name - The String of the gem's name. | ||
# | ||
# Examples | ||
# | ||
# filter_path_from("autolink_filter") | ||
# # => "/Users/simeon/Projects/html-pipeline/test/helpers/../../lib/html/pipeline/autolink_filter.rb" | ||
# | ||
# Returns String of load path. | ||
def self.filter_path_from(filter_name) | ||
File.join(File.dirname(__FILE__), "..", "..", "lib", "html", "pipeline", "#{filter_name}.rb") | ||
end | ||
|
||
private | ||
# Internal: Find a gem's load paths. | ||
# | ||
# gem_name - The String of the gem's name. | ||
# | ||
# Examples | ||
# | ||
# gem_load_paths_from("rinku") | ||
# # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib"] | ||
# | ||
# Returns Array of load paths. | ||
def self.gem_load_paths_from(gem_name) | ||
$LOAD_PATH.select{ |path| /#{gem_name}/i =~ path } | ||
end | ||
|
||
# Internal: Find a gem's loaded features. | ||
# | ||
# gem_name - The String of the gem's name. | ||
# | ||
# Examples | ||
# | ||
# gem_loaded_features_from("rinku") | ||
# # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.bundle", | ||
# "/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.rb"] | ||
# | ||
# Returns Array of loaded features. | ||
def self.gem_loaded_features_from(gem_name) | ||
# gem github-markdown has a feature "github/markdown.rb". | ||
# Replace gem name dashes and underscores with regexp | ||
# range to match all features. | ||
gem_name_regexp = gem_name.split(/[-_]/).join("[\/_-]") | ||
|
||
$LOADED_FEATURES.select{ |feature| /#{gem_name_regexp}/i =~ feature } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class HTML::Pipeline::EmailReplyFilterTest < Test::Unit::TestCase | ||
def test_dependency_management | ||
assert_dependency_management_error "email_reply_filter", "escape_utils" | ||
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
Oops, something went wrong.
d3fc6d9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qaseh fitrulqim