Skip to content
Beth Skurrie edited this page May 27, 2015 · 3 revisions

Expect stub not to have been called

describe "when there are no triggers" "$(
  stub run_loader
  it 'does not run' "$(
    run_if_new_data
    expect $(stub_called_times run_loader) to_be '0'
  )"
)"

Expect stub to have been called with arguments

describe "when there are triggers" "$(
  it 'runs the loader with the names of the datasets to load' "$(
    stub run_loader
    create_triggers_database
    add_trigger 'bake-sale'
    add_trigger 'lemonade-stand'
    run_if_new_data
    expect $(stub_called_with_times run_loader bake-sale lemonade-stand) to_be '1'
  )"
)"

Expect stub to have been called with arguments within a subshell

This is a bit of a dirty hack, but it gets the job done.

describe "when there are triggers" "$(
  it 'runs the loader with the names of the datasets to load' "$(
      rm -rf tmp/verify-run-loader-args
      stub_and_eval run_loader 'echo $@ > tmp/verify-run-loader-args'
      create_triggers_database
      add_trigger 'bake-sale'
      add_trigger 'lemonade-stand'
      expect "$(cat tmp/verify-run-loader-args)" to_be "bake-sale lemonade-stand"
  )"
)"