diff --git a/README.md b/README.md index 319255a..e4c3f58 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ In no particular order, features that have been implemented and are planned: - [ ] Should syntax - [X] Helper methods and modules - [ ] Aliasing - custom example group types with preset attributes - - [ ] Pending tests - `pending` + - [X] Pending tests - `pending` - [ ] Shared examples - `behaves_like`, `include_examples` - [ ] Matchers - [ ] Equality matchers - `eq`, `be`, `be_a`, `match` diff --git a/src/spectator/dsl.cr b/src/spectator/dsl.cr index 4f815dc..840c707 100644 --- a/src/spectator/dsl.cr +++ b/src/spectator/dsl.cr @@ -182,6 +182,63 @@ module Spectator {% 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 raise NotImplementedError.new("Spectator::DSL#it_behaves_like") end diff --git a/src/spectator/pending_example.cr b/src/spectator/pending_example.cr new file mode 100644 index 0000000..e8d3f13 --- /dev/null +++ b/src/spectator/pending_example.cr @@ -0,0 +1,9 @@ +require "./example" + +module Spectator + abstract class PendingExample < Example + def run + PendingExampleResult.new(self) + end + end +end diff --git a/src/spectator/pending_example_result.cr b/src/spectator/pending_example_result.cr new file mode 100644 index 0000000..c5122e0 --- /dev/null +++ b/src/spectator/pending_example_result.cr @@ -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 diff --git a/src/spectator/reporters/standard_reporter.cr b/src/spectator/reporters/standard_reporter.cr index d20910c..30b8c1d 100644 --- a/src/spectator/reporters/standard_reporter.cr +++ b/src/spectator/reporters/standard_reporter.cr @@ -18,6 +18,8 @@ module Spectator print case result when SuccessfulExampleResult ".".colorize.green + when PendingExampleResult + "P".colorize.yellow when ErroredExampleResult "E".colorize.magenta when FailedExampleResult