Poop Sheet

Shellspec

I picked shellspec without too much research or experience, so don’t really know how it compares to shUnit2 etc.

A snag is (at time of writing) it’s not included in Arch Linux’s pacman list, so needs to be manually installed.

This involves:

git clone https://github.com/shellspec/shellspec.git
cd shellspec
ln -s shellspec /usr/local/bin

Shellspec is a behavior-driven development (BDD) framework, broadly following its Given-When-Then syntax.

G i v e n W h e n T h e n

These tests are grouped in blocks using a choice of three synonymous keywords, and each test can start with one of three synomymous keywords.

Outer blocks (Describe and Context are aliases for ExampleGroup)

Inner blocks (It and Specify are aliases for Example)

Since I like example-driven development (ie examples double as documentation), I favour:

ExampleGroup 'my group of examples'

  Example 'first example'
    # Given is not a shellspec keyword
    When...
    # Then is not a shellspec keyword
  End

End

Given

Shellspec doesn’t use given, but does have Data to set the starting state.

When

Then

Shellspec uses The instead of then followed by modifiers and matchers.

The status should be failure # probably status is 127

The stderr should be present # probably stderr is “bar: not found”

The stdout should eq “ok” same as The output should eq “ok”

The stderr should eq “err” same as The error should eq “err”

The entire output should eq “ok${SHELLSPEC_LF}”

The variable var should eq 456

The value “$var” should eq 789

The function “foo” should eq “foo”

The “foo()” should eq “foo” # shorthand for function

The result of “foo()” should eq “ok”