mocks.cr
mocks.cr copied to clipboard
Support type-restricted args
Simple example:
# works.cr
module Notifier
def self.notify(message)
end
end
create_module_mock Notifier do
mock self.notify(message)
end
allow(Notifier).to receive(self.notify("John")).and_return("Just great!")
Notifier.notify("John") # => "Just great!"
# doesnt_work.cr
module Notifier
def self.notify(message : String)
end
end
create_module_mock Notifier do
# can't do `message : String` here at the moment
mock self.notify(message)
end
allow(Notifier).to receive(self.notify("John")).and_return("Just great!")
Notifier.notify("John") # => nil
So, mock
macro should be able to parse type-restricted arguments, and define mocked version of method correctly.
refs waterlink/spec2-mocks.cr#3
/cc @marceloboeira
@marceloboeira If you want to take a stab on it, go on. I need to rest a bit for today. If not, I will most probably handle this tomorrow.
@waterlink I would never guess that the type restriction was actually the problem. I'm going to take a look, but I'm also tired hehe. Anyway, thanks for all the support!
Any news here?