diff --git a/CHANGELOG.md b/CHANGELOG.md index 72d1db9..fb7b645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - Added ability to cast types using the return value from expect/should statements with a type matcher. +- Added support for string interpolation in context names/labels. ### Fixed - Fix invalid syntax (unterminated call) when recording calls to stubs with an un-named splat. diff --git a/spec/features/interpolated_label_spec.cr b/spec/features/interpolated_label_spec.cr index 9c78c15..5506a1f 100644 --- a/spec/features/interpolated_label_spec.cr +++ b/spec/features/interpolated_label_spec.cr @@ -8,7 +8,7 @@ Spectator.describe "Interpolated Label" do expect(example.name).to eq("interpolates example labels") end - context "within a \#{bar}" do + context "within a #{bar}" do let(foo) { "multiple" } it "interpolates context labels" do |example| diff --git a/src/spectator/context.cr b/src/spectator/context.cr index 7fc126b..b9f532a 100644 --- a/src/spectator/context.cr +++ b/src/spectator/context.cr @@ -4,6 +4,11 @@ # This type is intentionally outside the `Spectator` module. # The reason for this is to prevent name collision when using the DSL to define a spec. abstract class SpectatorContext + # Evaluates the contents of a block within the scope of the context. + def eval + with self yield + end + # Produces a dummy string to represent the context as a string. # This prevents the default behavior, which normally stringifies instance variables. # Due to the sheer amount of types Spectator can create diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 0e7b47b..f595791 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -137,7 +137,7 @@ module Spectator::DSL what.is_a?(NilLiteral) %} {{what}} {% elsif what.is_a?(StringInterpolation) %} - {% raise "String interpolation isn't supported for example group names" %} + {{@type.name}}.new.eval { {{what}} } {% else %} {{what.stringify}} {% end %}