mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Make Example comparable against names and sources
This will be needed for filtering examples.
This commit is contained in:
parent
4f3ca20741
commit
2f8b4761de
3 changed files with 140 additions and 0 deletions
|
@ -119,4 +119,66 @@ describe Spectator::PendingExample do
|
|||
example.to_s.should contain(group.what.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#===" do
|
||||
context "with a matching Regex" do
|
||||
it "is true" do
|
||||
example = new_pending_example
|
||||
regex = Regex.new(Regex.escape(example.what))
|
||||
(example === regex).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching Regex" do
|
||||
it "is false" do
|
||||
example = new_pending_example
|
||||
regex = /BOGUS/
|
||||
(example === regex).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a String equal to the name" do
|
||||
it "is true" do
|
||||
example = new_pending_example
|
||||
(example === example.to_s).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a String different than the name" do
|
||||
it "is false" do
|
||||
example = new_pending_example
|
||||
(example === "BOGUS").should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a matching source location" do
|
||||
it "is true" do
|
||||
example = new_pending_example
|
||||
(example === example.source).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching source location" do
|
||||
it "is false" do
|
||||
example = new_pending_example
|
||||
source = Spectator::Source.new(__FILE__, __LINE__)
|
||||
(example === source).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a matching source line" do
|
||||
it "is true" do
|
||||
example = new_pending_example
|
||||
(example === example.source.line).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching source line" do
|
||||
it "is false" do
|
||||
example = new_pending_example
|
||||
line = example.source.line + 5
|
||||
(example === line).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1565,4 +1565,66 @@ describe Spectator::RunnableExample do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#===" do
|
||||
context "with a matching Regex" do
|
||||
it "is true" do
|
||||
example = new_runnable_example
|
||||
regex = Regex.new(Regex.escape(example.what))
|
||||
(example === regex).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching Regex" do
|
||||
it "is false" do
|
||||
example = new_runnable_example
|
||||
regex = /BOGUS/
|
||||
(example === regex).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a String equal to the name" do
|
||||
it "is true" do
|
||||
example = new_runnable_example
|
||||
(example === example.to_s).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a String different than the name" do
|
||||
it "is false" do
|
||||
example = new_runnable_example
|
||||
(example === "BOGUS").should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a matching source location" do
|
||||
it "is true" do
|
||||
example = new_runnable_example
|
||||
(example === example.source).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching source location" do
|
||||
it "is false" do
|
||||
example = new_runnable_example
|
||||
source = Spectator::Source.new(__FILE__, __LINE__)
|
||||
(example === source).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with a matching source line" do
|
||||
it "is true" do
|
||||
example = new_runnable_example
|
||||
(example === example.source.line).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a non-matching source line" do
|
||||
it "is false" do
|
||||
example = new_runnable_example
|
||||
line = example.source.line + 5
|
||||
(example === line).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,5 +59,21 @@ module Spectator
|
|||
def to_json(json : ::JSON::Builder)
|
||||
json.string(to_s)
|
||||
end
|
||||
|
||||
# Checks if this example matches some criteria.
|
||||
# This is used to filter examples.
|
||||
def ===(other)
|
||||
other === to_s
|
||||
end
|
||||
|
||||
# Checks if this example is at the specified source.
|
||||
def ===(other : Source)
|
||||
source == other
|
||||
end
|
||||
|
||||
# Checks if this example is at the specified line number.
|
||||
def ===(other : Int32)
|
||||
source.line === other
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue