-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afa1b34
commit 3a5c89a
Showing
9 changed files
with
201 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "../../spec_helper" | ||
|
||
describe Spectator::Core::Example do | ||
describe "#description" do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
require "./hooks" | ||
require "./item" | ||
|
||
module Spectator::Core | ||
abstract class Context | ||
module Context | ||
include Hooks | ||
|
||
def describe(description, &) | ||
context(description) { with self yield self } | ||
end | ||
|
||
abstract def context(description, &) | ||
|
||
def it(description, &block : Example ->) : Example | ||
Example.new(description, &block).tap do |example| | ||
example.parent = self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "./location_range" | ||
|
||
module Spectator::Core | ||
class ContextHook | ||
getter! location : LocationRange | ||
|
||
getter! exception : Exception | ||
|
||
@called = Atomic::Flag.new | ||
|
||
def initialize(@location = nil, &@block : ->) | ||
end | ||
|
||
def initialize(@block : ->) | ||
end | ||
|
||
def call | ||
# Ensure the hook is called once. | ||
called = @called.test_and_set | ||
# Re-raise previous error if there was one. | ||
@exception.try { |ex| raise ex } | ||
# Only call hook if it hasn't been called yet. | ||
return unless called | ||
|
||
begin | ||
@block.call | ||
rescue ex | ||
@exception = ex | ||
raise ex | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "./example" | ||
require "./location_range" | ||
|
||
module Spectator::Core | ||
class ExampleHook(T) | ||
getter! location : LocationRange | ||
|
||
getter! exception : Exception | ||
|
||
def initialize(@location = nil, &@block : T ->) | ||
end | ||
|
||
def initialize(@block : T ->) | ||
end | ||
|
||
def call(example : T) | ||
# Re-raise previous error if there was one. | ||
@exception.try { |ex| raise ex } | ||
|
||
begin | ||
@block.call(example) | ||
rescue ex | ||
@exception = ex | ||
raise ex | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.