From bbd9acda33c2be7517074b35a3f7dac479105ed2 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 9 Feb 2021 18:31:41 -0700 Subject: [PATCH 1/4] Capture test results from JUnit output --- .gitlab-ci.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index caf6bad..14d3678 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,13 @@ before_script: spec: script: - shards - - crystal spec --error-on-warnings + - crystal spec --error-on-warnings --junit_output=. + artifacts: + when: always + paths: + - output.xml + reports: + junit: output.xml format: script: @@ -31,8 +37,14 @@ nightly: allow_failure: true script: - shards --ignore-crystal-version - - crystal spec --error-on-warnings + - crystal spec --error-on-warnings --junit_output=. - crystal tool format --check + artifacts: + when: always + paths: + - output.xml + reports: + junit: output.xml pages: stage: deploy From b2aaac9a4698f5f8232b3371b432626c53ec8802 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 9 Feb 2021 19:08:58 -0700 Subject: [PATCH 2/4] Only run spec that was changed --- .guardian.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.guardian.yml b/.guardian.yml index ad67b38..f283d96 100644 --- a/.guardian.yml +++ b/.guardian.yml @@ -1,5 +1,11 @@ -files: ./**/*.cr +files: ./src/**/*.cr run: time crystal spec --error-trace --- +files: ./src/**/*.cr +run: bin/ameba %file% +--- +files: ./spec/**/*.cr +run: time crystal spec --error-trace %file% +--- files: ./shard.yml run: shards From 6f81011ba1fcb812fe0117405799c13b023426b2 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 9 Feb 2021 19:09:58 -0700 Subject: [PATCH 3/4] Ignore JUnit output --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e29dae7..c4166ba 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # Libraries don't need dependency lock # Dependencies will be locked in application that uses them /shard.lock + +# Ignore JUnit output +output.xml From ae26377b3d18fe5c09c169260bbd34e75c800fa6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 9 Feb 2021 19:10:11 -0700 Subject: [PATCH 4/4] Test and improve "Anything" --- spec/spectator/anything_spec.cr | 49 +++++++++++++++++++++++++++++++++ src/spectator/anything.cr | 21 ++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 spec/spectator/anything_spec.cr diff --git a/spec/spectator/anything_spec.cr b/spec/spectator/anything_spec.cr new file mode 100644 index 0000000..11672a5 --- /dev/null +++ b/spec/spectator/anything_spec.cr @@ -0,0 +1,49 @@ +require "../spec_helper" + +Spectator.describe Spectator::Anything do + it "equals everything" do + expect(true).to eq(subject) + expect(false).to eq(subject) + expect(nil).to eq(subject) + expect(42).to eq(subject) + expect(42.as(Int32 | String)).to eq(subject) + expect(["foo", "bar"]).to eq(subject) + end + + it "matches everything" do + expect(true).to match(subject) + expect(false).to match(subject) + expect(nil).to match(subject) + expect(42).to match(subject) + expect(42.as(Int32 | String)).to match(subject) + expect(["foo", "bar"]).to match(subject) + end + + context "nested in a container" do + it "equals everything" do + expect(["foo", "bar"]).to eq(["foo", subject]) + expect({"foo", "bar"}).to eq({"foo", subject}) + expect({foo: "bar"}).to eq({foo: subject}) + expect({"foo" => "bar"}).to eq({"foo" => subject}) + end + + it "matches everything" do + expect(["foo", "bar"]).to match(["foo", subject]) + expect({"foo", "bar"}).to match({"foo", subject}) + expect({foo: "bar"}).to match({foo: subject}) + expect({"foo" => "bar"}).to match({"foo" => subject}) + end + end + + describe "#to_s" do + subject { super.to_s } + + it { is_expected.to contain("anything") } + end + + describe "#inspect" do + subject { super.inspect } + + it { is_expected.to contain("anything") } + end +end diff --git a/src/spectator/anything.cr b/src/spectator/anything.cr index 511a024..6dafc60 100644 --- a/src/spectator/anything.cr +++ b/src/spectator/anything.cr @@ -1,15 +1,36 @@ module Spectator + # Type dedicated to matching everything. + # This is intended to be used as a value to compare against when the value doesn't matter. + # Can be used like so: + # ``` + # anything = Spectator::Anything.new + # array = ["foo", anything] + # expect(["foo", "bar"]).to eq(array) + # ``` struct Anything + # Always returns true. def ==(other) true end + # Always returns true. def ===(other) true end + # Always returns true. def =~(other) true end + + # Displays "anything". + def to_s(io) + io << "anything" + end + + # Displays "". + def inspect(io) + io << "" + end end end