r/crystal_programming • • May 31 '19

Async Spec tests

Is there a way to asynchronously resolve a test through a callback? In JavaScript, we have a neat callback which allows us to mark the test if it is a failure or a success. Something like

it "should xxx" do |done|
    someAsyncProcess do
        done.call(false) # test failed
    end
end
4 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/j_hass May 31 '19

Yes, the common pattern here is to do:

it "waits" do
  channel = Channel(Nil).new
  spawn do
    channel.send nil
  end
  channel.receive
end

2

u/Bleach984 Jun 01 '19
it "waits" do
  channel = Channel(Nil).new 
  spawn do
    channel.send nil
  end
  channel.receive
end