From a0af1e7cd19859438e3966bd6d6ce6864639ac70 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 17 Sep 2020 09:35:49 -0600 Subject: [PATCH 1/4] Allow string interpolation in some macros Enables interpolation in example and group descriptions, as well as anonymous doubles. Addresses https://github.com/icy-arctic-fox/spectator/issues/10 --- src/spectator/dsl/examples.cr | 4 ++-- src/spectator/dsl/groups.cr | 2 +- src/spectator/dsl/mocks.cr | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index b356ea5..bcb1425 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -20,7 +20,7 @@ module Spectator %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) ::Spectator::SpecBuilder.add_example( - {{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}}, + {{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}}, %source, {{@type.name}} ) { |test| test.as({{@type.name}}).%run } @@ -47,7 +47,7 @@ module Spectator %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) ::Spectator::SpecBuilder.add_pending_example( - {{description.is_a?(StringLiteral) || description.is_a?(NilLiteral) ? description : description.stringify}}, + {{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}}, %source, {{@type.name}} ) { |test| test.as({{@type.name}}).%run } diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 0ad5f72..5a37715 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -5,7 +5,7 @@ module Spectator macro context(what, _source_file = __FILE__, _source_line = __LINE__, &block) class Context%context < {{@type.id}} {% - description = if what.is_a?(StringLiteral) + description = if what.is_a?(StringLiteral) || what.is_a?(StringInterpolation) if what.starts_with?("#") || what.starts_with?(".") what.id.symbolize else diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 07d3c00..7ffcfc8 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -2,7 +2,7 @@ require "../mocks" module Spectator::DSL macro double(name = "Anonymous", **stubs, &block) - {% if name.is_a?(StringLiteral) %} + {% if name.is_a?(StringLiteral) || name.is_a?(StringInterpolation) %} anonymous_double({{name}}, {{stubs.double_splat}}) {% else %} {% @@ -56,7 +56,7 @@ module Spectator::DSL end macro null_double(name, **stubs, &block) - {% if name.is_a?(StringLiteral) %} + {% if name.is_a?(StringLiteral) || name.is_a?(StringInterpolation) %} anonymous_null_double({{name}}, {{stubs.double_splat}}) {% else %} {% From db284066f6879ee0dcc68b564bed9842cac47651 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 17 Sep 2020 10:13:41 -0600 Subject: [PATCH 2/4] Bump version to 0.9.24 --- shard.yml | 2 +- src/spectator.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index ed86687..dfc5dcc 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: spectator -version: 0.9.23 +version: 0.9.24 description: | A feature-rich spec testing framework for Crystal with similarities to RSpec. diff --git a/src/spectator.cr b/src/spectator.cr index 0b5d7ff..8fd45fe 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -6,7 +6,7 @@ module Spectator extend self # Current version of the Spectator library. - VERSION = "0.9.23" + VERSION = "0.9.24" # Top-level describe method. # All specs in a file must be wrapped in this call. From a4680f25848bcc467917970f79b32d99efc47666 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Sep 2020 10:50:18 -0600 Subject: [PATCH 3/4] Don't splat values for failed match data This caused an issue where keys with the same name as existing arguments couldn't be used. In this case, "description" and "failure_message". Fixes https://github.com/icy-arctic-fox/spectator/issues/13 --- src/spectator/matchers/attributes_matcher.cr | 4 ++-- src/spectator/matchers/have_predicate_matcher.cr | 4 ++-- src/spectator/matchers/predicate_matcher.cr | 4 ++-- src/spectator/matchers/respond_matcher.cr | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/spectator/matchers/attributes_matcher.cr b/src/spectator/matchers/attributes_matcher.cr index 2a72d5b..ec8826f 100644 --- a/src/spectator/matchers/attributes_matcher.cr +++ b/src/spectator/matchers/attributes_matcher.cr @@ -30,7 +30,7 @@ module Spectator::Matchers if match?(snapshot) SuccessfulMatchData.new(description) else - FailedMatchData.new(description, "#{actual.label} does not have attributes #{expected.label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} does not have attributes #{expected.label}", values(snapshot).to_a) end end @@ -39,7 +39,7 @@ module Spectator::Matchers def negated_match(actual : TestExpression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - FailedMatchData.new(description, "#{actual.label} has attributes #{expected.label}", **negated_values(snapshot)) + FailedMatchData.new(description, "#{actual.label} has attributes #{expected.label}", negated_values(snapshot).to_a) else SuccessfulMatchData.new(description) end diff --git a/src/spectator/matchers/have_predicate_matcher.cr b/src/spectator/matchers/have_predicate_matcher.cr index 7b23cd0..5cb3f94 100644 --- a/src/spectator/matchers/have_predicate_matcher.cr +++ b/src/spectator/matchers/have_predicate_matcher.cr @@ -20,7 +20,7 @@ module Spectator::Matchers if match?(snapshot) SuccessfulMatchData.new(description) else - FailedMatchData.new(description, "#{actual.label} does not have #{expected.label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} does not have #{expected.label}", values(snapshot).to_a) end end @@ -29,7 +29,7 @@ module Spectator::Matchers def negated_match(actual : TestExpression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - FailedMatchData.new(description, "#{actual.label} has #{expected.label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} has #{expected.label}", values(snapshot).to_a) else SuccessfulMatchData.new(description) end diff --git a/src/spectator/matchers/predicate_matcher.cr b/src/spectator/matchers/predicate_matcher.cr index bacfac0..bda4f9b 100644 --- a/src/spectator/matchers/predicate_matcher.cr +++ b/src/spectator/matchers/predicate_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers if match?(snapshot) SuccessfulMatchData.new(description) else - FailedMatchData.new(description, "#{actual.label} is not #{expected.label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} is not #{expected.label}", values(snapshot).to_a) end end @@ -35,7 +35,7 @@ module Spectator::Matchers def negated_match(actual : TestExpression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - FailedMatchData.new(description, "#{actual.label} is #{expected.label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} is #{expected.label}", values(snapshot).to_a) else SuccessfulMatchData.new(description) end diff --git a/src/spectator/matchers/respond_matcher.cr b/src/spectator/matchers/respond_matcher.cr index 59a955f..87f95a9 100644 --- a/src/spectator/matchers/respond_matcher.cr +++ b/src/spectator/matchers/respond_matcher.cr @@ -19,7 +19,7 @@ module Spectator::Matchers if snapshot.values.all? SuccessfulMatchData.new(description) else - FailedMatchData.new(description, "#{actual.label} does not respond to #{label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} does not respond to #{label}", values(snapshot).to_a) end end @@ -28,7 +28,7 @@ module Spectator::Matchers def negated_match(actual : TestExpression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if snapshot.values.any? - FailedMatchData.new(description, "#{actual.label} responds to #{label}", **values(snapshot)) + FailedMatchData.new(description, "#{actual.label} responds to #{label}", values(snapshot).to_a) else SuccessfulMatchData.new(description) end From a39223ff21e011641293e938d67ed006c73ca6d1 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Sep 2020 11:03:11 -0600 Subject: [PATCH 4/4] Bump to 0.9.25 --- shard.yml | 2 +- src/spectator.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index dfc5dcc..e5c0a65 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: spectator -version: 0.9.24 +version: 0.9.25 description: | A feature-rich spec testing framework for Crystal with similarities to RSpec. diff --git a/src/spectator.cr b/src/spectator.cr index 8fd45fe..c3e1bef 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -6,7 +6,7 @@ module Spectator extend self # Current version of the Spectator library. - VERSION = "0.9.24" + VERSION = "0.9.25" # Top-level describe method. # All specs in a file must be wrapped in this call.