Skip to content

Commit

Permalink
Fix adding stubs to class methods on mocked types
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Oct 12, 2021
1 parent 5692a77 commit f1f1659
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Better handling of the `be(nil)` when used with value types. [#37](https://github.com/icy-arctic-fox/spectator/issues/37)
- Fix missing arguments for stubbed top-level methods (`system`, `exit`, etc.). [#36](https://github.com/icy-arctic-fox/spectator/issues/36)
- Fix outdated naming when using `expect_any_instance_of`.
- Fix adding stubs to class methods on mocked types.

### Changed
- Elegantly handle missing/undefined methods with `have_attributes` matcher.
Expand Down
4 changes: 4 additions & 0 deletions src/spectator/mocks/registry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module Spectator::Mocks
fetch_instance(object).stubs.unshift(stub)
end

def add_stub(type : T.class, stub : MethodStub) : Nil forall T
add_type_stub(type, stub)
end

def add_type_stub(type, stub : MethodStub) : Nil
fetch_type(type).stubs.unshift(stub)
end
Expand Down

0 comments on commit f1f1659

Please sign in to comment.