Skip to content

Instantly share code, notes, and snippets.

@jwilger
Created February 25, 2012 23:24
Show Gist options
  • Save jwilger/1911579 to your computer and use it in GitHub Desktop.
Save jwilger/1911579 to your computer and use it in GitHub Desktop.
TestData's @DaTa is a Hash that defaults to empty Hashes?
class MyGivenDriver < Kookaburra::GivenDriver
def a_bar(name)
bar_data = test_data.default(:bar)
record = api.create_bar(bar_data)
test_data.set_bars(name, record)
end
def a_foo(name, bar_name)
foo_data = test_data.default(:foo)
# I didn't expect `bar` to ever be nil, but it was. See comment in `#fetch_bar`
bar = fetch_bar(bar_name)
foo_data[:bar_id] = bar.id
record = api.create_foo(foo_data)
test_data.set_foos(name, record)
end
private
def fetch_bar(name)
# The fact that the first method call here didn't return nil even when
# the specified name was definitely *not* in the collection yet was
# very surprising to me
test_data.bars(name) || begin
a_bar(name)
test_data.fetch_bars(name)
end
end
end
@geeksam
Copy link

geeksam commented Feb 26, 2012

...apparently you can also write Haskell in any language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment