capture-output-1.0.0/0000755000175000001440000000000012471217512013041 5ustar gquserscapture-output-1.0.0/LICENSE.txt0000644000175000001440000000204312471217512014663 0ustar gqusersCopyright (c) 2012 Jakub Pastuszek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. capture-output-1.0.0/lib/0000755000175000001440000000000012471217512013607 5ustar gquserscapture-output-1.0.0/lib/capture-output.rb0000644000175000001440000000055312471217512017140 0ustar gqusersmodule Capture def self.output(out = STDOUT) r, w = IO.pipe old_out = out.clone out.reopen(w) data = '' t = Thread.new do data << r.read end begin yield ensure w.close out.reopen(old_out) end t.join data end def self.stdout(&block) output(STDOUT, &block) end def self.stderr(&block) output(STDERR, &block) end end capture-output-1.0.0/.rspec0000644000175000001440000000001012471217512014145 0ustar gqusers--color capture-output-1.0.0/.document0000644000175000001440000000006712471217512014663 0ustar gquserslib/**/*.rb bin/* - features/**/*.feature LICENSE.txt capture-output-1.0.0/VERSION0000644000175000001440000000000512471217512014104 0ustar gqusers1.0.0capture-output-1.0.0/spec/0000755000175000001440000000000012471217512013773 5ustar gquserscapture-output-1.0.0/spec/spec_helper.rb0000644000175000001440000000055412471217512016615 0ustar gqusers$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rspec' require 'capture-output' # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} RSpec.configure do |config| end capture-output-1.0.0/spec/capture-output_spec.rb0000644000175000001440000000131212471217512020330 0ustar gqusersrequire File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Capture do it "#stdout should capture all STDOUT IO content" do Capture.stdout do Process.spawn('echo "hello world"') STDOUT.puts 'puts' end.should == "hello world\nputs\n" end it "#stderr should capture all STDERR IO content" do Capture.stderr do Process.spawn('echo "hello world" 1>&2') STDERR.puts 'puts' end.should == "hello world\nputs\n" end it "#stdout and #stderr in combination" do Capture.stdout do Capture.stderr do Process.spawn('echo "hello world out"') Process.spawn('echo "hello world err" 1>&2') end.should == "hello world err\n" end.should == "hello world out\n" end end capture-output-1.0.0/metadata.yml0000644000175000001440000000536012471217512015350 0ustar gqusers--- !ruby/object:Gem::Specification name: capture-output version: !ruby/object:Gem::Version version: 1.0.0 prerelease: platform: ruby authors: - Jakub Pastuszek autorequire: bindir: bin cert_chain: [] date: 2012-02-06 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rspec requirement: &14873960 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 2.8.0 type: :development prerelease: false version_requirements: *14873960 - !ruby/object:Gem::Dependency name: rdoc requirement: &14872280 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '3.12' type: :development prerelease: false version_requirements: *14872280 - !ruby/object:Gem::Dependency name: bundler requirement: &14886820 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 1.0.0 type: :development prerelease: false version_requirements: *14886820 - !ruby/object:Gem::Dependency name: jeweler requirement: &14886100 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 1.8.3 type: :development prerelease: false version_requirements: *14886100 - !ruby/object:Gem::Dependency name: simplecov requirement: &14885380 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *14885380 description: Provides Caputere.output, Capture.stdout and Capture.stderr methods that can be used to grab output generated by current or spawned process email: jpastuszek@gmail.com executables: [] extensions: [] extra_rdoc_files: - LICENSE.txt - README.md files: - .document - .rspec - Gemfile - Gemfile.lock - LICENSE.txt - README.md - Rakefile - VERSION - capture-output.gemspec - lib/capture-output.rb - spec/capture-output_spec.rb - spec/spec_helper.rb homepage: http://github.com/jpastuszek/capture-output licenses: - MIT post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -841742823095545510 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.15 signing_key: specification_version: 3 summary: Grabs given IO (STDOUT, STDERR or other) output and returns it as a string test_files: [] capture-output-1.0.0/capture-output.gemspec0000644000175000001440000000411412471217512017407 0ustar gqusers# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "capture-output" s.version = "1.0.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Jakub Pastuszek"] s.date = "2012-02-06" s.description = "Provides Caputere.output, Capture.stdout and Capture.stderr methods that can be used to grab output generated by current or spawned process" s.email = "jpastuszek@gmail.com" s.extra_rdoc_files = [ "LICENSE.txt", "README.md" ] s.files = [ ".document", ".rspec", "Gemfile", "Gemfile.lock", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "capture-output.gemspec", "lib/capture-output.rb", "spec/capture-output_spec.rb", "spec/spec_helper.rb" ] s.homepage = "http://github.com/jpastuszek/capture-output" s.licenses = ["MIT"] s.require_paths = ["lib"] s.rubygems_version = "1.8.15" s.summary = "Grabs given IO (STDOUT, STDERR or other) output and returns it as a string" if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q, ["~> 2.8.0"]) s.add_development_dependency(%q, ["~> 3.12"]) s.add_development_dependency(%q, ["~> 1.0.0"]) s.add_development_dependency(%q, ["~> 1.8.3"]) s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, ["~> 2.8.0"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, ["~> 2.8.0"]) s.add_dependency(%q, ["~> 3.12"]) s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.8.3"]) s.add_dependency(%q, [">= 0"]) end end capture-output-1.0.0/README.md0000644000175000001440000000323612471217512014324 0ustar gqusers# capture-output Capture STDOUT, STDERR or other IO output and return it as a string. This is useful for testing when you need to start a process and check its output or when you need to check current process output. ## Installing gem install capture-output ## Usage Grab STDOUT: ```ruby require 'capture-output' out = Capture.stdout do Process.spawn('echo "hello world"') STDOUT.puts 'puts' end # out contains "hello world\nputs\n" ``` Grab STDERR: ```ruby require 'capture-output' out = Capture.stderr do Process.spawn('echo "hello world" 1>&2') STDERR.puts 'puts' end # out contains "hello world\nputs\n" ``` Grab STDOUT and STDERR: ```ruby require 'capture-output' err = nil out = Capture.stdout do err = Capture.stderr do Process.spawn('echo "hello world out"') Process.spawn('echo "hello world err" 1>&2') end end # err contains "hello world err\n" # out contains "hello world out\n" ``` ## Contributing to caputer-output * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. ## Copyright Copyright (c) 2012 Jakub Pastuszek. See LICENSE.txt for further details. capture-output-1.0.0/Gemfile0000644000175000001440000000061112471217512014332 0ustar gquserssource "http://rubygems.org" # Add dependencies required to use your gem here. # Example: # gem "activesupport", ">= 2.3.5" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. group :development do gem "rspec", "~> 2.8.0" gem "rdoc", "~> 3.12" gem "bundler", "~> 1.0.0" gem "jeweler", "~> 1.8.3" gem "simplecov", ">= 0" end capture-output-1.0.0/Rakefile0000644000175000001440000000266612471217512014520 0ustar gqusers# encoding: utf-8 require 'rubygems' require 'bundler' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e $stderr.puts e.message $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end require 'rake' require 'jeweler' Jeweler::Tasks.new do |gem| # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options gem.name = "capture-output" gem.homepage = "http://github.com/jpastuszek/capture-output" gem.license = "MIT" gem.summary = "Grabs given IO (STDOUT, STDERR or other) output and returns it as a string" gem.description = "Provides Caputere.output, Capture.stdout and Capture.stderr methods that can be used to grab output generated by current or spawned process" gem.email = "jpastuszek@gmail.com" gem.authors = ["Jakub Pastuszek"] # dependencies defined in Gemfile end Jeweler::RubygemsDotOrgTasks.new require 'rspec/core' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList['spec/**/*_spec.rb'] end RSpec::Core::RakeTask.new(:rcov) do |spec| spec.pattern = 'spec/**/*_spec.rb' spec.rcov = true end task :default => :spec require 'rdoc/task' Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' rdoc.title = "capture-output #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end capture-output-1.0.0/Gemfile.lock0000644000175000001440000000130412471217512015261 0ustar gqusersGEM remote: http://rubygems.org/ specs: diff-lcs (1.1.3) git (1.2.5) jeweler (1.8.3) bundler (~> 1.0) git (>= 1.2.5) rake rdoc json (1.6.5) multi_json (1.0.4) rake (0.9.2.2) rdoc (3.12) json (~> 1.4) rspec (2.8.0) rspec-core (~> 2.8.0) rspec-expectations (~> 2.8.0) rspec-mocks (~> 2.8.0) rspec-core (2.8.0) rspec-expectations (2.8.0) diff-lcs (~> 1.1.2) rspec-mocks (2.8.0) simplecov (0.5.4) multi_json (~> 1.0.3) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) PLATFORMS ruby DEPENDENCIES bundler (~> 1.0.0) jeweler (~> 1.8.3) rdoc (~> 3.12) rspec (~> 2.8.0) simplecov