Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

test-cmd.rb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-cmd.rb

  • 0.12.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

About

test-cmd.rb provides an object-oriented interface for spawning a command.

Examples

Callbacks

The success and failure callbacks provide hooks for when a command exits successfully or unsuccessfully. The callbacks are passed an instance of Test::Cmd:

require "test-cmd"
cmd("ruby", "-e", "exit 0")
  .success { print "The command [#{_1.pid}] was successful", "\n" }
  .failure { print "The command [#{_1.pid}] was unsuccessful", "\n" }

Test::Unit

The following example demonstrates how tests might be written with test-unit from the standard library. The cmd method takes the name or path of a command, alongside any arguments:

require "test/unit"
require "test/cmd"

class CmdTest < Test::Unit::TestCase
  def test_ruby_stdout
    assert_equal "42\n", ruby("puts 42").stdout
  end

  def test_ruby_stderr
    assert_equal "42\n", ruby("warn 42").stderr
  end

  def test_ruby_success_exit_status
    assert_equal 0, ruby("exit 0").exit_status
  end

  def test_ruby_failure_exit_status
    assert_equal 1, ruby("exit 1").exit_status
  end

  private

  def ruby(code)
    cmd("ruby", "-e", code)
  end
end

Documentation

A complete API reference is available at 0x1eef.github.io/x/test-cmd.rb

Install

test-cmd.rb can be installed via rubygems.org:

gem install test-cmd.rb

Sources

License

BSD Zero Clause
See LICENSE

FAQs

Package last updated on 16 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc