mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove specs since they're mostly invalidated by the refactor
This commit is contained in:
parent
07aeaecca4
commit
2c400950a4
43 changed files with 1 additions and 6919 deletions
|
@ -1,37 +0,0 @@
|
|||
# Example that always raises an exception.
|
||||
class ErroredExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what : Symbol | String
|
||||
"ERROR"
|
||||
end
|
||||
|
||||
# Dummy source.
|
||||
def source : ::Spectator::Source
|
||||
::Spectator::Source.new(__FILE__, __LINE__)
|
||||
end
|
||||
|
||||
# Dummy symbolic flag.
|
||||
def symbolic? : Bool
|
||||
false
|
||||
end
|
||||
|
||||
# Dummy instance.
|
||||
def instance
|
||||
nil
|
||||
end
|
||||
|
||||
# Run the example that always produces an error.
|
||||
private def run_instance
|
||||
raise "Oops"
|
||||
end
|
||||
|
||||
# Creates an errored example.
|
||||
def self.create
|
||||
hooks = Spectator::ExampleHooks.empty
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,59 +0,0 @@
|
|||
# Creates a new `Spectator::ExampleHooks` instance.
|
||||
# All arguments are optional,
|
||||
# only specify the sets of hooks that are needed.
|
||||
# The hooks that aren't specified will be left empty.
|
||||
def new_hooks(
|
||||
before_all = [] of ->,
|
||||
before_each = [] of ->,
|
||||
after_all = [] of ->,
|
||||
after_each = [] of ->,
|
||||
around_each = [] of Proc(Nil) ->
|
||||
)
|
||||
Spectator::ExampleHooks.new(before_all, before_each,
|
||||
after_all, after_each, around_each)
|
||||
end
|
||||
|
||||
# Creates a new `Spectator::ExampleHooks` instance.
|
||||
# All arguments are optional,
|
||||
# only specify a hook for the types that are needed.
|
||||
# The hooks that aren't specified will be left empty.
|
||||
def new_hooks(
|
||||
before_all : Proc(Nil)? = nil,
|
||||
before_each : Proc(Nil)? = nil,
|
||||
after_all : Proc(Nil)? = nil,
|
||||
after_each : Proc(Nil)? = nil,
|
||||
around_each : Proc(Proc(Nil), Nil)? = nil
|
||||
)
|
||||
new_hooks(
|
||||
before_all ? [before_all] : [] of ->,
|
||||
before_each ? [before_each] : [] of ->,
|
||||
after_all ? [after_all] : [] of ->,
|
||||
after_each ? [after_each] : [] of ->,
|
||||
around_each ? [around_each] : [] of Proc(Nil) ->
|
||||
)
|
||||
end
|
||||
|
||||
# Creates a new `Spectator::ExampleConditions` instance.
|
||||
# All arguments are optional,
|
||||
# only specify the sets of conditions that are needed.
|
||||
# The conditions that aren't specified will be left empty.
|
||||
def new_conditions(
|
||||
pre = [] of ->,
|
||||
post = [] of ->
|
||||
)
|
||||
Spectator::ExampleConditions.new(pre, post)
|
||||
end
|
||||
|
||||
# Creates a new `Spectator::ExampleConditions` instance.
|
||||
# All arguments are optional,
|
||||
# only specify a condition for the types that are needed.
|
||||
# The conditions that aren't specified will be left empty.
|
||||
def new_conditions(
|
||||
pre : Proc(Nil)? = nil,
|
||||
post : Proc(Nil)? = nil
|
||||
)
|
||||
new_conditions(
|
||||
pre ? [pre] : [] of ->,
|
||||
post ? [post] : [] of ->
|
||||
)
|
||||
end
|
|
@ -1,71 +0,0 @@
|
|||
# Utility methods for creating expectations, partials, and matchers.
|
||||
|
||||
def new_partial(actual : T, label : String) forall T
|
||||
test_value = Spectator::TestValue.new(actual, label)
|
||||
source = Spectator::Source.new(__FILE__, __LINE__)
|
||||
Spectator::Expectations::ExpectationPartial.new(test_value, source)
|
||||
end
|
||||
|
||||
def new_partial(actual : T = 123) forall T
|
||||
test_value = Spectator::TestValue.new(actual)
|
||||
source = Spectator::Source.new(__FILE__, __LINE__)
|
||||
Spectator::Expectations::ExpectationPartial.new(test_value, source)
|
||||
end
|
||||
|
||||
def new_block_partial(label = "BLOCK", &block)
|
||||
test_block = Spectator::TestBlock.new(block, label)
|
||||
source = Spectator::Source.new(__FILE__, __LINE__)
|
||||
Spectator::Expectations::ExpectationPartial.new(test_block, source)
|
||||
end
|
||||
|
||||
def new_matcher(expected : T, label : String) forall T
|
||||
test_value = Spectator::TestValue.new(expected, label)
|
||||
Spectator::Matchers::EqualityMatcher.new(test_value)
|
||||
end
|
||||
|
||||
def new_matcher(expected : T = 123) forall T
|
||||
test_value = Spectator::TestValue.new(expected)
|
||||
Spectator::Matchers::EqualityMatcher.new(test_value)
|
||||
end
|
||||
|
||||
def new_expectation(expected : ExpectedType = 123, actual : ActualType = 123) forall ExpectedType, ActualType
|
||||
partial = new_partial(actual, "foo")
|
||||
matcher = new_matcher(expected, "bar")
|
||||
match_data = matcher.match(partial.actual)
|
||||
Spectator::Expectations::Expectation.new(match_data, partial.source)
|
||||
end
|
||||
|
||||
def new_satisfied_expectation(value : T = 123) forall T
|
||||
new_expectation(value, value).tap do |expectation|
|
||||
expectation.satisfied?.should be_true # Sanity check.
|
||||
end
|
||||
end
|
||||
|
||||
def new_unsatisfied_expectation(expected : ExpectedType = 123, actual : ActualType = 456) forall ExpectedType, ActualType
|
||||
new_expectation(expected, actual).tap do |expectation|
|
||||
expectation.satisfied?.should be_false # Sanity check.
|
||||
end
|
||||
end
|
||||
|
||||
def create_expectations(success_count = 1, failure_count = 0)
|
||||
satisfied = Array.new(success_count) { new_satisfied_expectation }
|
||||
unsatisfied = Array.new(failure_count) { new_unsatisfied_expectation }
|
||||
(satisfied + unsatisfied).shuffle
|
||||
end
|
||||
|
||||
def generate_expectations(success_count = 1, failure_count = 0)
|
||||
satisfied = Array.new(success_count) { new_satisfied_expectation }
|
||||
unsatisfied = Array.new(failure_count) { new_unsatisfied_expectation }
|
||||
expectations = (satisfied + unsatisfied).shuffle
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(false)
|
||||
expectations.each do |expectation|
|
||||
reporter.report(expectation)
|
||||
end
|
||||
{satisfied: satisfied, unsatisfied: unsatisfied, expectations: expectations, reporter: reporter}
|
||||
end
|
||||
|
||||
def report_expectations(success_count = 1, failure_count = 0)
|
||||
harness = Spectator::Internals::Harness.current
|
||||
success_count.times { harness.report_expectation(new_satisfied_expectation) }
|
||||
failure_count.times { harness.report_expectation(new_unsatisfied_expectation) }
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
# Example that always fails.
|
||||
class FailingExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what : Symbol | String
|
||||
"FAIL"
|
||||
end
|
||||
|
||||
# Dummy source.
|
||||
def source : ::Spectator::Source
|
||||
::Spectator::Source.new(__FILE__, __LINE__)
|
||||
end
|
||||
|
||||
# Dummy symbolic flag.
|
||||
def symbolic? : Bool
|
||||
false
|
||||
end
|
||||
|
||||
# Dummy instance.
|
||||
def instance
|
||||
nil
|
||||
end
|
||||
|
||||
# Run the example that always fails.
|
||||
private def run_instance
|
||||
report_expectations(0, 1)
|
||||
end
|
||||
|
||||
# Creates a failing example.
|
||||
def self.create(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty)
|
||||
group = Spectator::RootExampleGroup.new(hooks, conditions)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
end
|
||||
end
|
||||
|
||||
# Creates a group of failing examples.
|
||||
def self.create_group(count = 5, hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
Spectator::RootExampleGroup.new(hooks, conditions).tap do |group|
|
||||
group.children = Array.new(count) { new(group, values).as(Spectator::ExampleComponent) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
# Retrieves a value from match data given its key/label.
|
||||
def match_data_value_with_key(match_data_values, key)
|
||||
labeled_value = match_data_values.find { |v| v.label == key }
|
||||
raise "#{key} is missing" unless labeled_value
|
||||
labeled_value.value
|
||||
end
|
||||
|
||||
# Retrieves the string representation and base value
|
||||
# from a `Spectator::Matchers::PrefixedMatchDataValue` (or similar)
|
||||
# in the values returned by `Spectator::Matchers::MatchData#values`.
|
||||
def match_data_value_sans_prefix(match_data_values, key)
|
||||
prefix = match_data_value_with_key(match_data_values, key)
|
||||
{to_s: prefix.to_s, value: prefix.value}
|
||||
end
|
||||
|
||||
# Check whether match data has a value with a specified key/label.
|
||||
def match_data_has_key?(match_data_values, key)
|
||||
found = match_data_values.find { |v| v.label == key }
|
||||
!!found
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
# Example that always succeeds.
|
||||
class PassingExample < Spectator::RunnableExample
|
||||
# Creates the example.
|
||||
def initialize(group, values, @symbolic = false)
|
||||
super(group, values)
|
||||
end
|
||||
|
||||
# Dummy description.
|
||||
def what : Symbol | String
|
||||
"PASS"
|
||||
end
|
||||
|
||||
# Dummy source.
|
||||
def source : ::Spectator::Source
|
||||
::Spectator::Source.new(__FILE__, __LINE__)
|
||||
end
|
||||
|
||||
# Dummy symbolic flag.
|
||||
def symbolic? : Bool
|
||||
@symbolic
|
||||
end
|
||||
|
||||
# Dummy instance.
|
||||
def instance
|
||||
nil
|
||||
end
|
||||
|
||||
# Run the example that always passes.
|
||||
# If this doesn't something broke.
|
||||
private def run_instance
|
||||
report_expectations(1, 0)
|
||||
end
|
||||
|
||||
# Creates a passing example.
|
||||
def self.create(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty)
|
||||
group = Spectator::RootExampleGroup.new(hooks, conditions)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
# Spy class for testing `Spectator::Result#call`.
|
||||
class ResultCallSpy
|
||||
{% for name in %i[success failure error pending] %}
|
||||
getter? {{name.id}} = false
|
||||
|
||||
def {{name.id}}
|
||||
@{{name.id}} = true
|
||||
{{name}}
|
||||
end
|
||||
|
||||
def {{name.id}}(arg)
|
||||
@{{name.id}} = true
|
||||
arg
|
||||
end
|
||||
{% end %}
|
||||
end
|
|
@ -1,69 +0,0 @@
|
|||
# Example that invokes a closure when it is run.
|
||||
# This is useful for capturing what's going on when an event is running.
|
||||
class SpyExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what : Symbol | String
|
||||
"SPY"
|
||||
end
|
||||
|
||||
# Dummy source.
|
||||
def source : ::Spectator::Source
|
||||
::Spectator::Source.new(__FILE__, __LINE__)
|
||||
end
|
||||
|
||||
# Dummy symbolic flag.
|
||||
def symbolic? : Bool
|
||||
false
|
||||
end
|
||||
|
||||
# Dummy instance.
|
||||
def instance
|
||||
nil
|
||||
end
|
||||
|
||||
# Captures the sample values when the example is created.
|
||||
def initialize(group, @sample_values)
|
||||
super(group, @sample_values)
|
||||
end
|
||||
|
||||
# Sample values given to the example.
|
||||
getter sample_values : Spectator::Internals::SampleValues
|
||||
|
||||
# Harness that was used while running the example.
|
||||
getter! harness : Spectator::Internals::Harness
|
||||
|
||||
setter block : Proc(Nil)? = nil
|
||||
|
||||
# Method called by the framework to run the example code.
|
||||
private def run_instance
|
||||
@harness = Spectator::Internals::Harness.current
|
||||
if block = @block
|
||||
block.call
|
||||
end
|
||||
end
|
||||
|
||||
# Creates a spy example.
|
||||
# The block passed to this method will be executed when the example runs.
|
||||
def self.create(hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty, &block)
|
||||
group = Spectator::RootExampleGroup.new(hooks, conditions)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
example.block = block
|
||||
end
|
||||
end
|
||||
|
||||
# Creates a group of spy examples.
|
||||
# Specify the number of examplese to create and a block to invoke when the example is run.
|
||||
# The block is given the index of the example in the group.
|
||||
def self.create_group(count, &block : Int32 -> Nil)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
Spectator::RootExampleGroup.new(Spectator::ExampleHooks.empty, Spectator::ExampleConditions.empty).tap do |group|
|
||||
group.children = Array.new(count) do |index|
|
||||
new(group, values).tap do |example|
|
||||
example.block = block.partial(index)
|
||||
end.as(Spectator::ExampleComponent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,47 +0,0 @@
|
|||
# Formatter that doubles as a spy.
|
||||
# This class tracks calls made to it.
|
||||
class SpyFormatter < Spectator::Formatting::Formatter
|
||||
{% for item in [
|
||||
{"start_suite", "Spectator::TestSuite"},
|
||||
{"start_example", "Spectator::Example"},
|
||||
{"end_example", "Spectator::Result"},
|
||||
] %}
|
||||
{% method_name = item[0].id %}
|
||||
{% argument_type = item[1].id %}
|
||||
|
||||
# Stores all invocations made to `#{{method_name}}`.
|
||||
# Each element is an invocation and the value is the argument passed to the method.
|
||||
getter {{method_name}}_calls = [] of {{argument_type}}
|
||||
|
||||
# Number of times the `#{{method_name}}` method was called.
|
||||
def {{method_name}}_call_count
|
||||
@{{method_name}}_calls.size
|
||||
end
|
||||
|
||||
# Increments `#{{method_name}}_call_count` and stores the argument.
|
||||
def {{method_name}}(arg : {{argument_type}})
|
||||
@all_calls << {{method_name.symbolize}}
|
||||
@{{method_name}}_calls << arg
|
||||
end
|
||||
|
||||
{% end %}
|
||||
|
||||
# Stores all invocatiosn made to `#end_suite`.
|
||||
# Each element is an invocation and the value is the arguments passed to the method.
|
||||
getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Spectator::Profile?)
|
||||
|
||||
# Number of times the `#end_suite` method was called.
|
||||
def end_suite_call_count
|
||||
@end_suite_calls.size
|
||||
end
|
||||
|
||||
# Increments `#end_suite_call_count` and stores the arguments.
|
||||
def end_suite(report, profile)
|
||||
@all_calls << :end_suite
|
||||
@end_suite_calls << {report: report, profile: profile}
|
||||
end
|
||||
|
||||
# Stores the methods that were called and in which order.
|
||||
# The symbols will be the method name (i.e. `:start_suite`).
|
||||
getter all_calls = [] of Symbol
|
||||
end
|
|
@ -1,28 +0,0 @@
|
|||
# Example system to test that doubles as a spy.
|
||||
# This class tracks calls made to it.
|
||||
class SpySUT
|
||||
{% for item in [
|
||||
{"==", "eq"},
|
||||
{"!=", "ne"},
|
||||
{"<", "lt"},
|
||||
{"<=", "le"},
|
||||
{">", "gt"},
|
||||
{">=", "ge"},
|
||||
{"===", "case_eq"},
|
||||
{"=~", "match"},
|
||||
{"includes?", "includes"},
|
||||
] %}
|
||||
{% operator = item[0].id %}
|
||||
{% name = item[1].id %}
|
||||
|
||||
# Number of times the `#{{operator}}` method was called.
|
||||
getter {{name}}_call_count = 0
|
||||
|
||||
# Returns true and increments `#{{name}}_call_count`.
|
||||
def {{operator}}(other : T) forall T
|
||||
@{{name}}_call_count += 1
|
||||
true
|
||||
end
|
||||
|
||||
{% end %}
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue