Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Test your shell scripts!

Merge pull request #48 from AdrieanKhisbe/master

Support for the antigen package manager
latest commit 7fc56e4e82
Ryland Herrick authored

README.md

shpec Build Status

Test your shell scripts!

Screenshot of shpec

Using shpec

This repo itself is using shpec, so feel free to use it as an example. Here is the basic structure that you'll want:

└── shpec
    └── an_example_shpec.sh
    └── another_shpec.sh

Then to run your tests:

shpec [shpec_files]

If you'd like your tests to run automatically when they change, we recommend the entr utility:

find . -name "*_shpec.sh" | entr shpec

Examples

shpec's own tests are a great place to start. More detailed examples to come.

Matchers

The general format is:

assert matcher arguments

where matcher is one of the following:

Binary Matchers

equal         # equality
unequal       # inequality
gt            # algebraic '>'
lt            # algebraic '<'
match         # regex match
no_match      # lack of regex match

Unary Matchers

present       # string presence
blank         # string absence
file_present  # file presence
file_absent   # file absence
symlink       # tests a symlink's target
test          # evaluates a test string

Custom Matchers

Custom matchers are loaded from shpec/matchers/*.sh.

For example, here's how you'd create a still_alive matcher:

# in shpec/matchers/network.sh
still_alive() {
  ping -oc1 "$1" > /dev/null 2>&1
  assert equal "$?" 0
}

Then you can use that matcher like any other:

# in shpec/network_shpec.sh
describe "my server"
  it "serves responses"
    assert still_alive "my-site.com"
  end
end

Installation

you can either install with curl

sh -c "`curl -L https://raw.github.com/rylnd/shpec/master/install.sh`"

or with antigen for zsh by putting antigen bundle rylnd/shpec in your .zshrc

Contributing

Pull requests are always welcome.

Something went wrong with that request. Please try again.