Created
February 25, 2012 23:24
-
-
Save jwilger/1911579 to your computer and use it in GitHub Desktop.
TestData's @DaTa is a Hash that defaults to empty Hashes?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
...apparently you can also write Haskell in any language.