diff --git a/CHANGELOG.md b/CHANGELOG.md index e4be897..74b09f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Changed +- Forward example procsy `to_s` to underlying example. [#70](https://gitlab.com/arctic-fox/spectator/-/issues/70) + +## [0.10.5] - 2022-01-27 +### Fixed +- Fixed usage of `sample` with single block argument. [#41](https://github.com/icy-arctic-fox/spectator/issues/41#issuecomment-1022525702) + ## [0.10.4] - 2022-01-11 ### Added - Support string interpolation for example name/description. [#41](https://github.com/icy-arctic-fox/spectator/issues/41) @@ -367,8 +375,9 @@ This has been changed so that it compiles and raises an error at runtime with a First version ready for public use. -[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.4...master -[0.10.3]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.3...v0.10.4 +[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.5...master +[0.10.5]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.4...v0.10.5 +[0.10.4]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.3...v0.10.4 [0.10.3]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.2...v0.10.3 [0.10.2]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.1...v0.10.2 [0.10.1]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.0...v0.10.1 diff --git a/README.md b/README.md index 53d347d..78a6b17 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Add this to your application's `shard.yml`: development_dependencies: spectator: gitlab: arctic-fox/spectator - version: ~> 0.10.4 + version: ~> 0.10.5 ``` Usage diff --git a/shard.yml b/shard.yml index 343ed19..3eaf627 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: spectator -version: 0.10.4 +version: 0.10.5 description: | A feature-rich spec testing framework for Crystal with similarities to RSpec. diff --git a/spec/issues/github_issue_41_spec.cr b/spec/issues/github_issue_41_spec.cr new file mode 100644 index 0000000..1b75e40 --- /dev/null +++ b/spec/issues/github_issue_41_spec.cr @@ -0,0 +1,30 @@ +require "../spec_helper" + +Spectator.describe "GitHub Issue #41" do + sample [1, 2, 3] do |i| + it "is itself" do + expect(i).to eq i + end + end + + def self.an_array + [1, 2, 3] + end + + sample an_array do |i| + it "is itself" do + expect(i).to eq(i) + end + end + + # NOTE: NamedTuple does not work, must be Enumerable(T) for `sample`. + def self.a_hash + {:a => "a", :b => "b", :c => "c"} + end + + sample a_hash do |k, v| + it "works on hashes" do + expect(v).to eq(k.to_s) + end + end +end diff --git a/spec/issues/github_issue_42_spec.cr b/spec/issues/github_issue_42_spec.cr new file mode 100644 index 0000000..9ac6603 --- /dev/null +++ b/spec/issues/github_issue_42_spec.cr @@ -0,0 +1,43 @@ +require "../spec_helper" + +abstract class SdkInterface + abstract def register_hook(name, &block) +end + +class Example + def initialize(@sdk : Sdk) + end + + def configure + @sdk.register_hook("name") do + nil + end + end +end + +class Sdk < SdkInterface + def initialize + end + + def register_hook(name, &block) + nil + end +end + +Spectator.describe Example do + mock Sdk do + stub register_hook(name, &block) + end + + describe "#configure" do + it "registers a block on configure" do + sdk = Sdk.new + example_class = Example.new(sdk) + allow(sdk).to receive(register_hook()) + + example_class.configure + + expect(sdk).to have_received(register_hook()).with("name") + end + end +end diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 6c678b7..0e7b47b 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -101,9 +101,15 @@ module Spectator::DSL ) \{% if block %} - \{% for arg, i in block.args %} - let(\{{arg}}) do |example| - example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}] + \{% if block.args.size > 1 %} + \{% for arg, i in block.args %} + let(\{{arg}}) do |example| + example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}] + end + \{% end %} + \{% else %} + let(\{{block.args[0]}}) do |example| + example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item end \{% end %} diff --git a/src/spectator/example.cr b/src/spectator/example.cr index 93135a8..8f99e93 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -283,6 +283,12 @@ module Spectator # Allow instance to behave like an example. forward_missing_to @example + + # Constructs the full name or description of the example. + # This prepends names of groups this example is part of. + def to_s(io) : Nil + @example.to_s(io) + end end end end