Commit Graph

462 Commits

Author SHA1 Message Date
Michael Miller f55c60e01f
Fix README spec
Mocked types cannot be private.
Moved to a module to prevent polluting the global namespace.
2022-12-17 21:01:22 -07:00
Michael Miller 4b68b8e3de
Fix resolution issue when mocked types use custom types
GitLab issue 51 is affected.
https://gitlab.com/arctic-fox/spectator/-/issues/51
Private types cannot be referenced with mocks.
2022-12-17 20:56:16 -07:00
Michael Miller 65a4b8e756
Populate previous_def/super with captured block args
The previous_def and super keywords do not propagate blocks.
See: https://github.com/crystal-lang/crystal/issues/10399
This works around the issue by populating arguments if the method uses a block.
2022-12-17 16:41:22 -07:00
Michael Miller b52593dbde
Cleanup 2022-12-17 16:39:47 -07:00
Michael Miller 952e949307
Handle 'self' and some other variants in method return types 2022-12-13 22:48:21 -07:00
Michael Miller 293faccd5c
Support free variables in mocked types 2022-12-13 18:22:22 -07:00
Michael Miller 47a62ece78
Add reduced test code for GitLab issue 80
https://gitlab.com/arctic-fox/spectator/-/issues/80
Note: This test only triggers a compiler bug when the file is compiled by itself.
Compiling/running the entire spec suite *does not* cause the bug.
2022-12-08 17:14:09 -07:00
Michael Miller fbe877690d
Adjust call argument matching
Reenable test for https://github.com/icy-arctic-fox/spectator/issues/44 and https://github.com/icy-arctic-fox/spectator/issues/47
2022-11-29 22:31:22 -07:00
Michael Miller a967dce241
Adjust double string representation
to_s and inspect (with variants) are no longer "original implementation."
2022-11-29 21:24:31 -07:00
Michael Miller 8efd38fbdd
Split Arguments class by functionality
Code changes for https://github.com/icy-arctic-fox/spectator/issues/47 caused a drastic increase in compilation times.
This improves compilation times by splitting concerns for arguments.
In one case, arguments are used for matching.
In the other, arguments are captured for comparison.
The second case has been moved to a FormalArguments class.
Theoretically, this reduces the complexity and combinations the compiler might be iterating.
2022-11-27 22:26:19 -07:00
Michael Miller 318e4eba89
Use shorter string when stub is treated as a message 2022-11-04 22:55:12 -06:00
Michael Miller a6149b2671
Use `before` instead of `before_each` (same for after) 2022-11-04 16:56:03 -06:00
Michael Miller 4dacaab6dc
Fix missing keyword arguments after splat 2022-10-23 22:36:20 -06:00
Michael Miller c77da67341
Hide splat label in certain situations
Undefined double methods were reporting splat arguments, which is technically correct.
But for output in these cases, it makes more sense to show the exact calling args.
2022-10-23 21:56:37 -06:00
Michael Miller e2130d12d3
Implement arguments case equality
Implements https://github.com/icy-arctic-fox/spectator/issues/47
Some specs are failing and need to be resolved before the new feature is considered done.
2022-10-23 20:42:08 -06:00
Michael Miller a728a037d4
Rename attributes 2022-10-23 15:37:55 -06:00
Michael Miller 163f94287e
Fix Arguments to_s 2022-10-23 15:27:39 -06:00
Michael Miller e38e3ecc32
Initial rework of arguments to support named positionals 2022-10-23 15:22:50 -06:00
Michael Miller 70d0009db5
Disable issue 47 test for now 2022-10-09 18:23:39 -06:00
Michael Miller d9082dab45
Test behavior and for leakages with allow syntax 2022-10-09 17:14:20 -06:00
Michael Miller b3aa2d62c0
Ensure stubs don't leak between examples 2022-10-09 16:59:39 -06:00
Michael Miller c6afa0adb3
Use different value than original 2022-10-09 16:58:56 -06:00
Michael Miller bc0a9c03c9
Remove runtime compilation tests
These may be readded later.
Right now they're failing because the GitHub issue 44 spec changes the behavior of Process.run.
The changes made by that spec shouldn't leak, but to fix correctly requires substantial changes.
These runtime tests provide little value right now and slow down testing.
2022-10-09 16:47:54 -06:00
Michael Miller 090c95b162
Ensure stubs defined with allow syntax are cleared 2022-10-09 15:48:00 -06:00
Michael Miller 2516803b0d
Add spec for GitHub issue 47
https://github.com/icy-arctic-fox/spectator/issues/47
2022-10-09 15:35:22 -06:00
Michael Miller 5c910e5a85
Clear stubs defined with `expect().to receive()` syntax after test finishes 2022-10-09 13:57:28 -06:00
Michael Miller 422b0efa59
Update test to account for fix in Crystal 1.6
Keyword arguments cannot be used as a short-hand for positional arguments (yet).
https://github.com/icy-arctic-fox/spectator/issues/44
2022-10-09 12:33:31 -06:00
Michael Miller c1e1666449
Formatting 2022-10-08 14:05:53 -06:00
Michael Miller 4dfa5ccb6e
Prevent defining stubs on undefined methods in LazyDouble
In Crystal 1.6, a segfault would occur in the spec spec/spectator/mocks/lazy_double_spec.cr:238
I suspect this is a Crystal bug of some kind, but can't reduce it.
The methods produced by `method_missing` don't have a return type including Symbol.
Symbol is excluded from the union of return types (Int32 | String | Nil).
The program segfaults when calling a method on the actual value, which is a symbol.
It ultimately crashes when producing a failure message, which indicates the value it tested doesn't equal the expected value (a symbol of the same value).
Avoid this issue by preventing stubs on undefined/untyped methods.
2022-10-08 14:04:02 -06:00
Michael Miller 079272c9de
Add spec for custom matchers docs
Related: https://github.com/icy-arctic-fox/spectator/issues/46
2022-09-03 16:46:17 -06:00
Michael Miller 17a3ca3ac7
Fix https://gitlab.com/arctic-fox/spectator/-/issues/77 2022-08-07 14:58:09 -06:00
Michael Miller 18e9c1c35d
Workaround issue with Box.unbox causing segfault
Using Box.unbox on a nil value with a union type causes:

Invalid memory access (signal 11) at address 0x8

Related Crystal issue: https://github.com/crystal-lang/crystal/issues/11839
Fixes: https://gitlab.com/arctic-fox/spectator/-/issues/76
2022-07-18 19:47:34 -06:00
Michael Miller 95764140ee
Add spec for GitLab issue 51
https://gitlab.com/arctic-fox/spectator/-/issues/51
2022-07-14 22:01:33 -06:00
Michael Miller 7e09016e5c
Add count modifiers for have_received matcher 2022-07-14 20:46:52 -06:00
Michael Miller e2e33e440b
Add link 2022-07-14 19:59:47 -06:00
Michael Miller d14a2fa27e
Change "title" 2022-07-14 19:59:14 -06:00
Michael Miller 9c888fef3f
Add specs for mocks and stubs docs 2022-07-14 19:11:45 -06:00
Michael Miller c0a32505ee
Address Ameba issue 2022-07-14 13:53:30 -06:00
Michael Miller c228984956
Add specs for anonymous and null object doubles docs 2022-07-14 13:51:24 -06:00
Michael Miller 827b69483b
Disallow stubs for undefined methods in null double
Any method_missing invocation should return self.
2022-07-14 13:37:09 -06:00
Michael Miller 7dd77a2096
Add spec for doubles docs 2022-07-14 13:18:13 -06:00
Michael Miller be973cdc4b
Add spec for GitHub issue 44
https://github.com/icy-arctic-fox/spectator/issues/44
2022-07-13 15:52:31 -06:00
Michael Miller f1465c44d8
Fix Ameba issues 2022-07-13 13:42:44 -06:00
Michael Miller aa9ca7a98e
Don't return nil for methods using NoReturn 2022-07-13 12:24:29 -06:00
Michael Miller 14d8c046f0
Workaround absolute path requirement for mock injection 2022-07-13 12:23:28 -06:00
Michael Miller da3fbc9607
Add spec for GitHub issue 43
https://github.com/icy-arctic-fox/spectator/issues/43
2022-07-13 11:17:10 -06:00
Michael Miller 181a34a0b3
Display "None" when no methods are called 2022-07-13 10:53:57 -06:00
Michael Miller e52f187eb7
Show new mock and double system in README 2022-07-12 23:22:47 -06:00
Michael Miller 754bfd6939
Intercept most exit calls and raise instead 2022-07-12 23:02:20 -06:00
Michael Miller 3c9c7f88be
Reenable test relying on doubles 2022-07-12 22:32:09 -06:00