mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Quick implementation of pending examles
This commit is contained in:
parent
7cfa432dfd
commit
dc8e651209
5 changed files with 82 additions and 1 deletions
|
@ -95,7 +95,7 @@ In no particular order, features that have been implemented and are planned:
|
||||||
- [ ] Should syntax
|
- [ ] Should syntax
|
||||||
- [X] Helper methods and modules
|
- [X] Helper methods and modules
|
||||||
- [ ] Aliasing - custom example group types with preset attributes
|
- [ ] Aliasing - custom example group types with preset attributes
|
||||||
- [ ] Pending tests - `pending`
|
- [X] Pending tests - `pending`
|
||||||
- [ ] Shared examples - `behaves_like`, `include_examples`
|
- [ ] Shared examples - `behaves_like`, `include_examples`
|
||||||
- [ ] Matchers
|
- [ ] Matchers
|
||||||
- [ ] Equality matchers - `eq`, `be`, `be_a`, `match`
|
- [ ] Equality matchers - `eq`, `be`, `be_a`, `match`
|
||||||
|
|
|
@ -182,6 +182,63 @@ module Spectator
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro pending(description, &block)
|
||||||
|
{%
|
||||||
|
parent_module = @type
|
||||||
|
safe_name = description.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_")
|
||||||
|
class_name = (safe_name.camelcase + "Example").id
|
||||||
|
given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given]
|
||||||
|
var_names = given_vars.map { |v| v[:name] }
|
||||||
|
%}
|
||||||
|
|
||||||
|
class Example%example
|
||||||
|
include ExampleDSL
|
||||||
|
include {{parent_module}}
|
||||||
|
|
||||||
|
def %run({{ var_names.join(", ").id }})
|
||||||
|
{{block.body}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class {{class_name.id}} < ::Spectator::PendingExample
|
||||||
|
{% for given_var, i in given_vars %}
|
||||||
|
@%var{i} : ValueWrapper
|
||||||
|
|
||||||
|
private def %var{i}
|
||||||
|
@%var{i}.unsafe_as(TypedValueWrapper(typeof({{given_var[:type_def]}}))).value
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
def initialize(context{% for v, i in var_names %}, %var{i}{% end %})
|
||||||
|
super(context)
|
||||||
|
{% for given_var, i in given_vars %}
|
||||||
|
@%var{i} = TypedValueWrapper(typeof({{given_var[:type_def]}})).new(%var{i})
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
{% if description.is_a?(StringLiteral) %}
|
||||||
|
{{description}}
|
||||||
|
{% else %}
|
||||||
|
{{description.stringify}}
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%current_context = ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]
|
||||||
|
{% for given_var, i in given_vars %}
|
||||||
|
{%
|
||||||
|
var_name = given_var[:name]
|
||||||
|
collection = given_var[:collection]
|
||||||
|
%}
|
||||||
|
{{collection}}.each do |%var{i}|
|
||||||
|
{% end %}
|
||||||
|
%current_context.examples << {{class_name.id}}.new(%current_context {% for v, i in var_names %}, %var{i}{% end %})
|
||||||
|
{% for given_var in given_vars %}
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
|
||||||
def it_behaves_like
|
def it_behaves_like
|
||||||
raise NotImplementedError.new("Spectator::DSL#it_behaves_like")
|
raise NotImplementedError.new("Spectator::DSL#it_behaves_like")
|
||||||
end
|
end
|
||||||
|
|
9
src/spectator/pending_example.cr
Normal file
9
src/spectator/pending_example.cr
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
require "./example"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
abstract class PendingExample < Example
|
||||||
|
def run
|
||||||
|
PendingExampleResult.new(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
src/spectator/pending_example_result.cr
Normal file
13
src/spectator/pending_example_result.cr
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
require "./example_result"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
class PendingExampleResult < ExampleResult
|
||||||
|
def passed?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(@example)
|
||||||
|
super(@example, Time::Span.new(nanoseconds: 0))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,6 +18,8 @@ module Spectator
|
||||||
print case result
|
print case result
|
||||||
when SuccessfulExampleResult
|
when SuccessfulExampleResult
|
||||||
".".colorize.green
|
".".colorize.green
|
||||||
|
when PendingExampleResult
|
||||||
|
"P".colorize.yellow
|
||||||
when ErroredExampleResult
|
when ErroredExampleResult
|
||||||
"E".colorize.magenta
|
"E".colorize.magenta
|
||||||
when FailedExampleResult
|
when FailedExampleResult
|
||||||
|
|
Loading…
Reference in a new issue