Skip to content

Commit

Permalink
Add --with-wrapper option to template wrapper biogems
Browse files Browse the repository at this point in the history
  • Loading branch information
wwood committed Jan 5, 2013
1 parent 42e41ff commit 15c6cc7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/bio-gem/mod/jeweler.rb
Expand Up @@ -31,6 +31,7 @@ def initialize(options = {})
development_dependencies << ["activesupport", ">= 3.0.7"]
development_dependencies << ["sqlite3", ">= 1.3.3"]
end
development_dependencies << ['systemu', '>=2.5.2'] if options[:wrapper]
end

alias original_project_name project_name
Expand Down
4 changes: 4 additions & 0 deletions lib/bio-gem/mod/jeweler/options.rb
Expand Up @@ -62,6 +62,10 @@ def initialize(args)
self[:biogem_db] = true
end

o.on('--with-wrapper', 'setup the biogem to be a wrapper around a command line application') do
self[:wrapper] = true
end

o.separator ""

o.separator "These options are for Jeweler"
Expand Down
18 changes: 17 additions & 1 deletion lib/bio-gem/templates/lib/plugin.rb
@@ -1,3 +1,19 @@
module <%= constant_name %>
<% if options[:wrapper] %>require 'systemu'
<% end %>
module <%= constant_name %>
<% if options[:wrapper] %>
class Wrapper
def run
command = "some_application arguments"
status, stdout, stderr = systemu command, 0 => 'dummy stdin'
if status.exitstatus != 0
$stderr.puts "Failed to run wrapping command correctly, as non-zero exit status "+
"#{status.exitstatus} detected. Command run was `#{command}'"
else
# All good. Now to something useful with the stdout..
end
end
end
<% end %>
end
24 changes: 21 additions & 3 deletions test/test_bio-gem.rb
Expand Up @@ -5,6 +5,12 @@

class TestBiorubyGem < Test::Unit::TestCase
TEST_DIR = 'test/bioruby-biogem-test'
def basic_generated_files(project_name)
%W(Gemfile lib lib/bio-#{project_name}.rb LICENSE.txt Rakefile README.rdoc test test/helper.rb test/test_bio-#{project_name}.rb).map do |file_name_to_test|
File.join("bioruby-#{project_name}",file_name_to_test)
end
end

def setup
# check and create test directory
FileUtils.rm_rf(TEST_DIR) if Dir.exist?(TEST_DIR)
Expand All @@ -21,11 +27,23 @@ def test_create_basic_project
project_name = "biogem-test"
Dir.chdir(TEST_DIR) do
application_exit = Bio::Gem::Generator::Application.run!("--no-create-repo", "--user-name=\"fake_name\"", "--user-email=\"fake_email\"", "--github-username=\"fake_github_user\"","#{project_name}")
files_tested = %W(Gemfile lib lib/bio-#{project_name}.rb LICENSE.txt Rakefile README.rdoc test test/helper.rb test/test_bio-#{project_name}.rb).map do |file_name_to_test|
File.exist?(File.join("bioruby-#{project_name}",file_name_to_test))
basic_generated_files(project_name).each do |path|
assert File.exist?(path), path
end
assert_equal [true, true, true, true, true, true, true, true, true], files_tested
end

end

def test_create_wrapper_project
project_name = "biogem-test2"
Dir.chdir(TEST_DIR) do
application_exit = Bio::Gem::Generator::Application.run!('--with-wrapper',"--no-create-repo", "--user-name=\"fake_name\"", "--user-email=\"fake_email\"", "--github-username=\"fake_github_user\"","#{project_name}")
basic_generated_files(project_name).each do |path|
assert File.exist?(path), path
end
assert File.read(File.join("bioruby-#{project_name}",'lib',"bio-#{project_name}","#{project_name}.rb")).match(/require 'systemu'/)
assert File.read(File.join("bioruby-#{project_name}",'lib',"bio-#{project_name}","#{project_name}.rb")).match(/systemu command/)
assert File.read(File.join("bioruby-#{project_name}",'Gemfile')).match(/gem "systemu"/)
end
end
end

0 comments on commit 15c6cc7

Please sign in to comment.