Commit graph

476 commits

Author SHA1 Message Date
Michael Miller
5520999b6d
Add spec for GitHub issue 55
https://github.com/icy-arctic-fox/spectator/issues/55
2024-01-27 11:16:57 -07:00
Michael Miller
726a2e1515
Add non-captured block argument
Preparing for Crystal 1.8.0
https://github.com/crystal-lang/crystal/issues/8764
2023-01-26 17:19:31 -07:00
Michael Miller
528ad7257d
Disable GitHub issue 49 spec for now 2023-01-26 16:17:29 -07:00
Michael Miller
abbd6ffd71
Fix splat argument expansion in method redefinition
The constructed previous_def call was malformed for stub methods.
Resolves the original issue in
https://github.com/icy-arctic-fox/spectator/issues/49
2023-01-23 11:55:52 -07:00
Michael Miller
4a0bfc1cb2
Add smoke tag 2022-12-20 20:52:01 -07:00
Michael Miller
8c3900adcb
Add support for interpolation in context names 2022-12-20 20:32:40 -07:00
Michael Miller
30602663fe
Add tests for interpolated labels
The context label test intentionally fails.
This functionality still needs to be implemented.
2022-12-20 20:12:58 -07:00
Michael Miller
c4bcf54b98
Support casting types with should statements 2022-12-19 22:40:55 -07:00
Michael Miller
0f8c46d6ef
Support casting types with expect statements 2022-12-19 21:29:21 -07:00
Michael Miller
8f80b10fc1
Support injecting mock functionality into modules
Add mock registry for a single module.
2022-12-18 19:04:50 -07:00
Michael Miller
a3c55dfa47
Add tests for module mocks docs 2022-12-18 18:52:08 -07:00
Michael Miller
fa99987780
Support creating instances of mocked modules via class
This is a bit of a hack.
The `.new` method is added to the module, which creates an instance that includes the mocked module.
No changes to the def_mock and new_mock methods are necessary.

For some reason, infinite recursion occurs when calling `.new` on the class.
To get around the issue for now, the internal method of allocation is used.
That is, allocate + initialize.
2022-12-18 16:04:49 -07:00
Michael Miller
d378583054
Support mocking modules 2022-12-18 15:18:20 -07:00
Michael Miller
e6584c9f04
Prevent comparing range arguments with non-compatible types in stubs
Addresses https://github.com/icy-arctic-fox/spectator/issues/48
2022-12-18 11:35:43 -07:00
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