obmarg / ex_unit_fixtures

A library for defining modular dependencies (fixtures) for ExUnit tests.
MIT License
13 stars 5 forks source link

Consider improvements to the `teardown` syntax. #23

Open obmarg opened 8 years ago

obmarg commented 8 years ago

If a fixture needs to do some teardown, at the moment it ends up looking a bit like this:

deffixture db do
   db = setup_db
   teardown fn ->
     close_db(db)
   end
   db
end

It might be nice to provide a better mechanism for teardown code. py.test has it's yield fixtures which are pretty nice, but (failing anything nicer) we could maybe provide a macro named yield/return/something that provides a bit of sugar around the above:

deffixture db do
   db = setup_db
   yield db, teardown: fn ->
     close_db(db)
   end
end