This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure library a bit... and use rspec
- Loading branch information
Peter Kieltyka
committed
Oct 31, 2011
1 parent
33ec2a1
commit 0a91a97
Showing
14 changed files
with
149 additions
and
116 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source :rubygems | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
subexec (0.2.0) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.3) | ||
rake (0.9.2.2) | ||
rspec (2.7.0) | ||
rspec-core (~> 2.7.0) | ||
rspec-expectations (~> 2.7.0) | ||
rspec-mocks (~> 2.7.0) | ||
rspec-core (2.7.1) | ||
rspec-expectations (2.7.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.7.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rake | ||
rspec (~> 2.7.0) | ||
subexec! |
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 |
---|---|---|
@@ -1,22 +1,14 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
require 'rake/gempackagetask' | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks | ||
|
||
spec = eval(File.read('subexec.gemspec')) | ||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.gem_spec = spec | ||
end | ||
|
||
Rake::TestTask.new(:test) do |test| | ||
test.libs << 'test' | ||
test.pattern = 'test/**/*_test.rb' | ||
test.verbose = true | ||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
spec.pattern = 'spec/**/*_spec.rb' | ||
end | ||
|
||
desc "Benchmark" | ||
task :benchmark do | ||
sh "ruby test/benchmark.rb" | ||
sh "ruby benchmark/run.rb" | ||
end | ||
|
||
task :default => :test | ||
task :default => :spec |
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
File renamed without changes.
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,26 @@ | ||
begin | ||
require 'bundler' | ||
Bundler.setup(:default, :development) | ||
rescue LoadError => e | ||
# Fall back on doing an unlocked resolve at runtime. | ||
$stderr.puts e.message | ||
$stderr.puts "Try running `bundle install`" | ||
exit! | ||
end | ||
|
||
$:.unshift(File.dirname(__FILE__)) | ||
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
|
||
begin | ||
require 'ruby-debug' | ||
rescue LoadError | ||
end | ||
|
||
require 'subexec' | ||
require 'rspec' | ||
|
||
RSpec.configure do |config| | ||
config.mock_with :rspec | ||
end | ||
|
||
TEST_PROG = File.join(File.dirname(__FILE__), 'helloworld.sh') |
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,42 @@ | ||
require 'spec_helper' | ||
|
||
describe Subexec do | ||
context 'Subexec class' do | ||
|
||
it 'run helloworld script' do | ||
sub = Subexec.run "#{TEST_PROG} 1" | ||
sub.output.should == "Hello\nWorld\n" | ||
sub.exitstatus.should == 0 | ||
end | ||
|
||
it 'timeout helloworld script' do | ||
sub = Subexec.run "#{TEST_PROG} 2", :timeout => 1 | ||
if RUBY_VERSION >= '1.9' | ||
sub.exitstatus.should == nil | ||
else | ||
# Ruby 1.8 doesn't support the timeout, so the | ||
# subprocess will have to exit on its own | ||
sub.exitstatus.should == 0 | ||
end | ||
end | ||
|
||
it 'set LANG env variable on request' do | ||
original_lang = `echo $LANG` | ||
|
||
sub = Subexec.run "echo $LANG", :lang => "fr_FR.UTF-8" | ||
sub.output.should == "fr_FR.UTF-8\n" | ||
sub = Subexec.run "echo $LANG", :lang => "C" | ||
sub.output.should == "C\n" | ||
sub = Subexec.run "echo $LANG", :lang => "en_US.UTF-8" | ||
sub.output.should == "en_US.UTF-8\n" | ||
|
||
`echo $LANG`.should == original_lang | ||
end | ||
|
||
it 'default LANG to C' do | ||
sub = Subexec.run "echo $LANG" | ||
sub.output.should == "C\n" | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
version = File.read("VERSION").strip | ||
$:.push File.expand_path('../lib', __FILE__) | ||
require 'subexec' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'subexec' | ||
s.version = version | ||
s.version = Subexec::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.summary = "Subexec spawns an external command with a timeout" | ||
s.description = "Subexec spawns an external command with a timeout" | ||
s.summary = "Subexec spawns a subprocess with an optional timeout" | ||
s.description = s.summary | ||
|
||
s.authors = ["Peter Kieltyka"] | ||
s.email = ["peter@nulayer.com"] | ||
s.homepage = "http://github.com/nulayer/subexec" | ||
|
||
s.files = Dir['README.rdoc', 'VERSION', 'lib/**/*'] | ||
s.files = Dir['README.md', 'lib/**/*'] | ||
s.require_path = 'lib' | ||
|
||
s.add_development_dependency('rake') | ||
s.add_development_dependency('rspec', ['~> 2.7.0']) | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.