waterlink / spec2.cr

Enhanced `spec` testing library for [Crystal](http://crystal-lang.org/).
MIT License
103 stars 22 forks source link

Error on mocking module methods #22

Closed marceloboeira closed 8 years ago

marceloboeira commented 8 years ago

When trying to mock a static method of a module, such as:

module A
  def self.b
    puts "b"
  end
end

create_mock A do
  mock self.b
end

describe A do
  it "example" do
    expect(A).to have_received(self.b)
  end
end

Raises a macro error:

Error:
  class ::A
        ^
A is not a class, it's a module
waterlink commented 8 years ago

@marceloboeira Thanks for a report. Yeah, at the moment mocks library can't create mocks for modules. Should be easily fixable by adding create_mock_module macro.

marceloboeira commented 8 years ago

@waterlink Sorry, once again I've opened the issue on the wrong repository. I'm going to close it here, and open on the mocks repo. You own too many Crystal libs. haha