Merge branch 'master' into mock-redesign

This commit is contained in:
Michael Miller 2022-02-28 20:39:33 -07:00
commit 0ea7890ece
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
7 changed files with 101 additions and 7 deletions

View file

@ -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/), 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). 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 ## [0.10.4] - 2022-01-11
### Added ### Added
- Support string interpolation for example name/description. [#41](https://github.com/icy-arctic-fox/spectator/issues/41) - 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. First version ready for public use.
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.4...master [Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.5...master
[0.10.3]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.3...v0.10.4 [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.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.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 [0.10.1]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.10.0...v0.10.1

View file

@ -25,7 +25,7 @@ Add this to your application's `shard.yml`:
development_dependencies: development_dependencies:
spectator: spectator:
gitlab: arctic-fox/spectator gitlab: arctic-fox/spectator
version: ~> 0.10.4 version: ~> 0.10.5
``` ```
Usage Usage

View file

@ -1,5 +1,5 @@
name: spectator name: spectator
version: 0.10.4 version: 0.10.5
description: | description: |
A feature-rich spec testing framework for Crystal with similarities to RSpec. A feature-rich spec testing framework for Crystal with similarities to RSpec.

View file

@ -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

View file

@ -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

View file

@ -101,11 +101,17 @@ module Spectator::DSL
) )
\{% if block %} \{% if block %}
\{% if block.args.size > 1 %}
\{% for arg, i in block.args %} \{% for arg, i in block.args %}
let(\{{arg}}) do |example| let(\{{arg}}) do |example|
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}] example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item[\{{i}}]
end end
\{% end %} \{% end %}
\{% else %}
let(\{{block.args[0]}}) do |example|
example.group.as(::Spectator::ExampleGroupIteration(typeof(Group\%group.\%collection.first))).item
end
\{% end %}
\{{block.body}} \{{block.body}}
\{% end %} \{% end %}

View file

@ -283,6 +283,12 @@ module Spectator
# Allow instance to behave like an example. # Allow instance to behave like an example.
forward_missing_to @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 end
end end