mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Experimenting with auto-mocking methods
This commit is contained in:
parent
a49f8eaa71
commit
4abf97139b
4 changed files with 55 additions and 0 deletions
5
src/spectator/dsl/mock_dsl.cr
Normal file
5
src/spectator/dsl/mock_dsl.cr
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module Spectator::DSL
|
||||||
|
module MockDSL
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -1419,6 +1419,24 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro mock(type)
|
||||||
|
{% real_type = type.resolve %}
|
||||||
|
{% if real_type < ::Reference %}
|
||||||
|
class ::{{real_type.name.id}}
|
||||||
|
include ::Spectator::Mock
|
||||||
|
end
|
||||||
|
{% elsif real_type < ::Value %}
|
||||||
|
struct ::{{real_type.name.id}}
|
||||||
|
include ::Spectator::Mock
|
||||||
|
end
|
||||||
|
{% else %}
|
||||||
|
module ::{{real_type.name.id}}
|
||||||
|
include ::Spectator::Mock
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
{% debug %}
|
||||||
|
end
|
||||||
|
|
||||||
# Creates an example, or a test case.
|
# Creates an example, or a test case.
|
||||||
# The *what* argument describes "what" is being tested or asserted.
|
# The *what* argument describes "what" is being tested or asserted.
|
||||||
# The block contains the code to run the test.
|
# The block contains the code to run the test.
|
||||||
|
|
|
@ -30,6 +30,8 @@ require "./example_group"
|
||||||
require "./nested_example_group"
|
require "./nested_example_group"
|
||||||
require "./root_example_group"
|
require "./root_example_group"
|
||||||
|
|
||||||
|
require "./mock"
|
||||||
|
|
||||||
require "./config"
|
require "./config"
|
||||||
require "./config_builder"
|
require "./config_builder"
|
||||||
require "./config_source"
|
require "./config_source"
|
||||||
|
|
30
src/spectator/mock.cr
Normal file
30
src/spectator/mock.cr
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module Spectator
|
||||||
|
module Mock
|
||||||
|
macro included
|
||||||
|
{% for meth in @type.methods %}
|
||||||
|
{% if meth.visibility != :public %}{{meth.visibility.id}} {% end %}def {{meth.name.id}}(
|
||||||
|
{% for arg, i in meth.args %}
|
||||||
|
{% if meth.splat_index && i == meth.splat_index %}
|
||||||
|
*{{arg}}{% if i + (meth.accepts_block? ? 0 : 1) < meth.args.size %},{% end %}
|
||||||
|
{% else %}
|
||||||
|
{{arg}}{% if i + (meth.accepts_block? ? 0 : 1) < meth.args.size %},{% end %}
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
|
{% if meth.accepts_block? %}&{% if meth.block_arg %}{{meth.block_arg}}{% else %}__spec_block{% end %}{% end %}
|
||||||
|
){% if meth.return_type %} : {{meth.return_type}}{% end %}
|
||||||
|
previous_def(
|
||||||
|
{% for arg, i in meth.args %}
|
||||||
|
{% if !meth.splat_index || i < meth.splat_index %}
|
||||||
|
{{arg.name.id}}{% if i + (meth.accepts_block? ? 0 : 1) < meth.args.size %},{% end %}
|
||||||
|
{% elsif meth.splat_index && i > meth.splat_index %}
|
||||||
|
{{arg.name.id}}: {{arg.name}}{% if i + (meth.accepts_block? ? 0 : 1) < meth.args.size %},{% end %}
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
|
{% if meth.accepts_block? %}&{% if meth.block_arg %}{{meth.block_arg}}{% else %}__spec_block{% end %}{% end %}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
{% debug %}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue