mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add ability to test expectations directly
This commit is contained in:
parent
fab216419c
commit
62fd289b0f
2 changed files with 30 additions and 0 deletions
|
@ -28,6 +28,10 @@ Spectator.describe "Runtime compilation" do
|
|||
it "does something" do
|
||||
expect(true).to be_false
|
||||
end
|
||||
|
||||
it "doesn't run" do
|
||||
expect(true).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
it "detects failed examples" do
|
||||
|
@ -43,4 +47,12 @@ Spectator.describe "Runtime compilation" do
|
|||
it "raises on compilation errors" do
|
||||
expect { malformed_example }.to raise_error(/compilation/i)
|
||||
end
|
||||
|
||||
given_expectation satisfied_expectation do
|
||||
expect(true).to be_true
|
||||
end
|
||||
|
||||
it "can compile and retrieve expectations" do
|
||||
expect(satisfied_expectation).to be_satisfied
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,3 +26,21 @@ macro given_example(id, &block)
|
|||
).result
|
||||
end
|
||||
end
|
||||
|
||||
# Defines an example ("it" block) that is lazily compiled.
|
||||
# The "it" block must be omitted, as the block provided to this macro will be wrapped in one.
|
||||
# When the expectation is referenced with *id*, it will be compiled and the result retrieved.
|
||||
# The value returned by *id* will be a `Spectator::SpecHelpers::Expectation`.
|
||||
# This allows an expectation to be inspected.
|
||||
# Only the last expectation performed will be returned.
|
||||
# An error is raised if no expectations ran.
|
||||
macro given_expectation(id, &block)
|
||||
let({{id}}) do
|
||||
result = ::Spectator::SpecHelpers::Example.new(
|
||||
{{__FILE__}},
|
||||
{{id.id.stringify}},
|
||||
{{"it do\n" + block.body.stringify + "\nend"}}
|
||||
).result
|
||||
result.expectations.last || raise("No expectations found from {{id.id}}")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue