From 157fdb813cb27e0778cee4aa72eb3e2b624e919f Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 2 Apr 2019 19:46:32 -0600 Subject: [PATCH 1/4] Fix doc regarding hook execution order --- src/spectator/dsl/structure_dsl.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index be3edfb..2cceea4 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -1272,7 +1272,7 @@ module Spectator::DSL # pre_condition { expect(array.size).to eq(3) } # 2 # ``` # - # With nested groups, the inner blocks will run first. + # With nested groups, the outer blocks will run first. # ``` # describe Something do # pre_condition { is_expected.to_not be_nil } # 1 From c18d9c4ffde535bc0db8928df46eb8334eae2ecd Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 5 Apr 2019 18:38:57 -0600 Subject: [PATCH 2/4] Allow top-level context macro --- src/spectator.cr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/spectator.cr b/src/spectator.cr index b11eef7..c00c080 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -47,6 +47,11 @@ module Spectator end end + # ditto + macro context(what, &block) + describe({{what}}) {{block}} + end + # Flag indicating whether Spectator should automatically run tests. # This should be left alone (set to true) in typical usage. # There are times when Spectator shouldn't run tests. From 53de72805b16fbbccc9a714710ede01f3f2fb5d6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 5 Apr 2019 20:07:04 -0600 Subject: [PATCH 3/4] Add skip macro as alternative to pending --- src/spectator/dsl/structure_dsl.cr | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index 93dfe94..8319b0c 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -1499,6 +1499,18 @@ module Spectator::DSL peding({{block.body.stringify}}) {{block}} end + # Same as `#pending`. + # Included for compatibility with RSpec. + macro skip(what, &block) + pending({{what}}) {{block}} + end + + # Same as `#pending`. + # Included for compatibility with RSpec. + macro skip(&block) + pending({{block.body.stringify}}) {{block}} + end + # Same as `#pending`. # Included for compatibility with RSpec. macro xit(what, &block) From 9650d7f9c180aacda822a99f8431e3f7f457713c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 5 Apr 2019 23:13:23 -0600 Subject: [PATCH 4/4] Use inspect on values in to_s The to_json method calls to_s, which results in incorrect output. --- src/spectator/matchers/alternative_match_data_value.cr | 2 +- src/spectator/matchers/generic_match_data_value.cr | 2 +- src/spectator/matchers/negatable_match_data_value.cr | 2 +- src/spectator/matchers/negatable_prefixed_match_data_value.cr | 2 +- src/spectator/matchers/prefixed_match_data_value.cr | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spectator/matchers/alternative_match_data_value.cr b/src/spectator/matchers/alternative_match_data_value.cr index 49e904a..e368c0f 100644 --- a/src/spectator/matchers/alternative_match_data_value.cr +++ b/src/spectator/matchers/alternative_match_data_value.cr @@ -21,7 +21,7 @@ module Spectator::Matchers # Produces a stringified value. def to_s(io) - io << value + @value.inspect(io) end # Produces a stringified value with additional information. diff --git a/src/spectator/matchers/generic_match_data_value.cr b/src/spectator/matchers/generic_match_data_value.cr index 3d751f9..9069489 100644 --- a/src/spectator/matchers/generic_match_data_value.cr +++ b/src/spectator/matchers/generic_match_data_value.cr @@ -12,7 +12,7 @@ module Spectator::Matchers # Stringifies the value. def to_s(io) - io << @value + @value.inspect(io) end # Inspects the value. diff --git a/src/spectator/matchers/negatable_match_data_value.cr b/src/spectator/matchers/negatable_match_data_value.cr index ac764fe..62abf49 100644 --- a/src/spectator/matchers/negatable_match_data_value.cr +++ b/src/spectator/matchers/negatable_match_data_value.cr @@ -21,7 +21,7 @@ module Spectator::Matchers # The string will be prefixed with "Not" when negated. def to_s(io) io << "Not " if @negated - io << @value + @value.inspect(io) end # Produces a stringified value with additional information. diff --git a/src/spectator/matchers/negatable_prefixed_match_data_value.cr b/src/spectator/matchers/negatable_prefixed_match_data_value.cr index f4cf4ea..9cc6138 100644 --- a/src/spectator/matchers/negatable_prefixed_match_data_value.cr +++ b/src/spectator/matchers/negatable_prefixed_match_data_value.cr @@ -26,7 +26,7 @@ module Spectator::Matchers def to_s(io) io << prefix io << ' ' - io << @value + @value.inspect(io) end # Produces a stringified value with additional information. diff --git a/src/spectator/matchers/prefixed_match_data_value.cr b/src/spectator/matchers/prefixed_match_data_value.cr index 1e22002..feea8cc 100644 --- a/src/spectator/matchers/prefixed_match_data_value.cr +++ b/src/spectator/matchers/prefixed_match_data_value.cr @@ -14,7 +14,7 @@ module Spectator::Matchers def to_s(io) io << @prefix io << ' ' - io << @value + @value.inspect(io) end # Outputs details of the formatted value with a prefix.