Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

106 lines (86 sloc) 2.815 kB
describe "shpec"
describe "basic operations"
it "asserts equality"
assert equal "foo" "foo"
it "asserts inequality"
assert unequal "foo" "bar"
it "asserts less than"
assert lt 5 7
it "asserts greater than"
assert gt 7 5
it "asserts partial matches"
assert match "partially" "partial"
it "asserts presence"
assert present "something"
it "asserts blankness"
assert blank ""
end_describe
describe "equality matcher"
it "handles newlines properly"
string_with_newline_char="new\nline"
multiline_string='new
line'
assert equal "$multiline_string" "$string_with_newline_char"
end_describe
describe "passing through to the test builtin"
it "asserts an arbitrary algebraic test"
assert test "[[ 5 -lt 10 ]]"
end_describe
describe "stubbing commands"
it "stubs to the null command by default"
stub_command "exit"
exit # doesn't really exit
assert equal "$?" 0
unstub_command "exit"
it "accepts an optional function body"
stub_command "curl" "echo 'stubbed body'"
assert equal "$(curl)" "stubbed body"
unstub_command "curl"
end_describe
describe "testing files"
it "asserts file absence"
assert file_absent /tmp/foo
it "asserts file existence"
touch /tmp/foo
assert file_present /tmp/foo
rm /tmp/foo
it "can verify the pointer of a symlink"
ln -s $HOME /tmp/link
assert symlink /tmp/link "$HOME"
rm /tmp/link
end_describe
describe "custom matcher"
it "allows custom matchers"
assert custom_assertion "argument"
end_describe
describe "exit codes"
shpec_cmd="$shpec_root/../bin/shpec"
it "returns nonzero if any test fails"
$shpec_cmd $shpec_root/etc/failing_example &> /dev/null
assert unequal "$?" "0"
it "returns zero if a suite passes"
$shpec_cmd $shpec_root/etc/passing_example &> /dev/null
assert equal "$?" "0"
end_describe
describe "output"
it "outputs passing tests to STDOUT"
message="$(. $shpec_root/etc/passing_example)"
assert match "$message" "a\ passing\ test"
it "outputs failing tests to STDOUT"
message="$(. $shpec_root/etc/failing_example)"
assert match "$message" "a\ failing\ test"
end_describe
describe "commandline options"
shpec_cmd="$shpec_root/../bin/shpec"
describe "--version"
it "outputs the current version number"
message="$($shpec_cmd --version)"
assert match "$message" "$(cat $shpec_root/../VERSION)"
end_describe
describe "-v"
it "outputs the current version number"
message="$($shpec_cmd -v)"
assert match "$message" "$(cat $shpec_root/../VERSION)"
end_describe
end_describe
end_describe
Jump to Line
Something went wrong with that request. Please try again.