Commit Graph

493 Commits

Author SHA1 Message Date
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 fd372226ab
Revert "Use separate context for example name interpolation"
This reverts commit d46698d81a.
2022-12-21 18:51:09 -07:00
Michael Miller 6a5e5b8f7a
Catch errors while evaluating node labels 2022-12-20 21:40:47 -07:00
Michael Miller d46698d81a
Use separate context for example name interpolation
This simplifies some code.
2022-12-20 20:43:47 -07:00
Michael Miller 8c3900adcb
Add support for interpolation in context names 2022-12-20 20:32:40 -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 275b217c6c
Allow metadata to be stored as nil 2022-11-29 23:22:42 -07:00
Michael Miller 4906dfae0d
Add short before/after hook name 2022-11-04 16:55:31 -06:00
Michael Miller 8e83edcc35
Simpler conditional block inclusion 2022-10-09 16:04:07 -06:00
Michael Miller 17a3ca3ac7
Fix https://gitlab.com/arctic-fox/spectator/-/issues/77 2022-08-07 14:58:09 -06:00
Michael Miller 1d58824e6c
Support default stubs for class_double 2022-07-14 13:18:02 -06:00
Michael Miller ac3b322900
Use absolute path for inject_mock
This is necessary to override the original type instead of creating a new one within the spec.
2022-07-13 11:29:19 -06:00
Michael Miller 2e5f822e1d
Remove `new` from reserved keywords
This effectively allows stubs to be placed on the `new` method for types.
A strange issue arose when the keyword was allowed.
The compiler failed to resolve the Stub type from the Double initializer.
The error trace goes through null_double_spec.cr.
Running just that spec file confirms the issue is there, but running other individual files doesn't produce the error.
As a workaround, I've put the full path of Stub in the initializer.
2022-07-12 22:30:04 -06:00
Michael Miller fe88eefa86
Add inject_mock to DSL 2022-07-12 22:12:48 -06:00
Michael Miller 99fb47c6e9
Remove redundant block conditionals 2022-07-12 21:46:12 -06:00
Michael Miller df5a4fa77c
Use tap to modify new mock
Without this, mocked structs were not getting their stubs applied.
An unintended side-effect is the tap shows up in recorded calls.
This seems to be harmless, but might need to be revisited.
2022-07-12 21:19:51 -06:00
Michael Miller 0e556c3d55
Clear stubs and recorded calls after example completes 2022-07-12 20:40:27 -06:00
Michael Miller bb0c85d9ec
Fix possible shadowing of `mock` 2022-07-12 19:50:04 -06:00
Michael Miller 3d7655a5d1
Add support for any_args in DSL 2022-07-12 19:05:55 -06:00
Michael Miller 4aaa8db5e2
Rename Arguments.empty to Arguments.none 2022-07-12 18:59:23 -06:00
Michael Miller 694e2e6259
Initial implementation of `have_received` 2022-07-11 20:25:15 -06:00
Michael Miller 32a9bfd356
Add no_args 2022-07-10 18:51:58 -06:00
Michael Miller b9eaefb424
Add docs 2022-07-10 18:33:56 -06:00
Michael Miller cd177dd2ae
Implement ProcStub 2022-07-10 11:54:51 -06:00
Michael Miller 813983de4b
Implement and test DSL for class mocks and doubles 2022-07-07 19:09:18 -06:00
Michael Miller 77096b76e9
Allow StubbedType alongside Stubbable for allow() 2022-07-07 19:01:02 -06:00
Michael Miller fb5f44ef10
Add 'new' and 'allocate' to reserved keywords 2022-07-04 20:06:26 -06:00
Michael Miller effad28559
Better compiler error for wrong argument type passed to mock 2022-06-01 22:23:39 -06:00
Michael Miller 3f4216a271
Allow passing default value stubs to mock initialization 2022-06-01 22:04:18 -06:00
Michael Miller b6083f0e09
Fix passing along mock body 2022-05-28 10:10:20 -06:00
Michael Miller 03754321b5
Fix existing mock DSL macros
Initial code for mock DSL.
2022-05-28 09:18:49 -06:00
Michael Miller 0758c19a86
Remove need for nillable argument to cast macro
The `class` method cannot be stubbed as this causes the cast (via `as`) to fail at compile-time.
2022-04-16 16:33:37 -06:00
Michael Miller 0ad1ec11f3
Initial macros for defining and initializing mocks 2022-04-02 18:43:13 -06:00
Michael Miller d97a62e601
Rename constant DOUBLES to TYPES
Will use for doubles and mocks.
2022-04-02 17:58:15 -06:00
Michael Miller 318e4f3707
Store location information in stub
Allows tracking where a stub was originally defined.
2022-04-02 10:39:59 -06:00
Michael Miller e61b31e47b
Add docs for allow and receive 2022-04-02 10:25:27 -06:00
Michael Miller e05ef94ef5
Initial work on stub DSL - found bug in Crystal compiler
```
Module validation failed: Invalid bitcast
  %4 = bitcast i32* %3 to %"(Spectator::Arguments(T, NT) | Nil)", !dbg !16
 (Exception)
  from /crystal/src/int.cr:541:9 in 'finish'
  from /crystal/src/compiler/crystal/codegen/codegen.cr:71:7 in 'codegen'
  from /crystal/src/compiler/crystal/compiler.cr:173:16 in 'compile'
  from /crystal/src/compiler/crystal/command/spec.cr:98:14 in 'spec'
  from /crystal/src/hash.cr:901:11 in '__crystal_main'
  from /crystal/src/crystal/main.cr:115:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Error: you've found a bug in the Crystal compiler. ...
```

I haven't been able to reproduce this in a simplified form.

Passing the `constraint` argument in NullStub#and_return to ValueStub.new triggers the bug.
Removing the `constraint` argument fixes the issue.
2022-03-31 22:49:45 -06:00
Michael Miller 9c1357da3f
Allow passing predefined stubs in as keyword args 2022-03-31 18:55:12 -06:00
Michael Miller c1195ef687
Simplify macro eval by returning a lazy double 2022-03-31 18:54:39 -06:00
Michael Miller 914def05e1
Add docs 2022-03-31 18:51:28 -06:00
Michael Miller 18a03b02fe
Include reserved 2022-03-19 22:36:25 -06:00
Michael Miller 04cf211f24
Move reserved keywords to a separate file
Add finalize as a reserved keyword.
2022-03-19 21:56:18 -06:00
Michael Miller bed84b315d
Add lazy double 2022-03-19 19:32:41 -06:00
Michael Miller 99aa8afdce
Add as_null_object method 2022-03-19 14:41:45 -06:00
Michael Miller 5a4e95e8a2
Split double macro into def_double and new_double 2022-03-19 11:41:53 -06:00
Michael Miller 4dff018330
Pass along block only if it exists 2022-03-19 11:28:36 -06:00
Michael Miller 20087f1c57
Treat any tokens starting with _spectator as reserved 2022-03-12 19:17:38 -07:00
Michael Miller 59f966d0e0
Fix missing double name
Rename internal method to _spectator_stubbed_name.
This is a better name for mocks and doubles.
Improve some handling around stubbed name.
2022-03-12 12:17:27 -07:00
Michael Miller 76c1d6a096
Some rework of stubs and doubles 2022-03-12 09:39:32 -07:00
Michael Miller 8668e495ef
Placeholder mocks DSL 2022-03-05 10:41:52 -07:00