Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created March 15, 2013 03:48
Show Gist options
  • Save thinkerbot/5167345 to your computer and use it in GitHub Desktop.
Save thinkerbot/5167345 to your computer and use it in GitHub Desktop.
shpec carryover examples

Illustrates carryover between shspec examples.

Carryover example to example:

$ shpec carryover_it_to_it.sh
shpec
  shares state between examples a
  shares state between examples b
  (Expected [] to equal [value])

real  0m0.002s
user	0m0.001s
sys	0m0.000s
2 examples, 1 failures

Carryover file to file, resulting in order dependence:

$ shpec carryover_file_to_file_{a,b}.sh shpec
  shares state between files a
shpec
  shares state between files b
  (Expected [] to equal [value])

real	0m0.003s
user	0m0.002s
sys	0m0.001s
2 examples, 1 failures

$ shpec carryover_file_to_file_{b,a}.sh
shpec
  shares state between files b
shpec
  shares state between files a

real	0m0.002s
user	0m0.001s
sys	0m0.000s
2 examples, 0 failures
describe "shpec"
it "shares state between files a"
variable="value"
assert equal "value" "$variable"
end_describe
describe "shpec"
it "shares state between files b"
assert equal "" "$variable"
end_describe
describe "shpec"
it "shares state between examples a"
variable="value"
assert equal "value" "$variable"
it "shares state between examples b"
assert equal "" "$variable"
end_describe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment