mocks.cr icon indicating copy to clipboard operation
mocks.cr copied to clipboard

Support type-restricted args

Open waterlink opened this issue 9 years ago • 3 comments

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

waterlink avatar Feb 20 '16 01:02 waterlink

@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 avatar Feb 20 '16 01:02 waterlink

@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!

marceloboeira avatar Feb 20 '16 01:02 marceloboeira

Any news here?

simaoneves avatar Sep 01 '17 22:09 simaoneves