mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add basics for tracking source code location
This commit is contained in:
parent
b8dcf35165
commit
de55e31407
4 changed files with 29 additions and 6 deletions
|
@ -9,7 +9,7 @@ module Spectator
|
|||
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
||||
module Spectator
|
||||
module Examples
|
||||
DSL.describe({{what}}) {{block}}
|
||||
DSL.describe({{what}}, {{source_file}}, {{source_line}}) {{block}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,11 @@ require "./example_group"
|
|||
|
||||
module Spectator
|
||||
module DSL
|
||||
macro describe(what, type = "Describe", &block)
|
||||
context({{what}}, {{type}}) {{block}}
|
||||
macro describe(what, source_file = __FILE__, source_line = __LINE__, type = "Describe", &block)
|
||||
context({{what}}, {{source_file}}, {{source_line}}, {{type}}) {{block}}
|
||||
end
|
||||
|
||||
macro context(what, type = "Context", &block)
|
||||
macro context(what, source_file = __FILE__, source_line = __LINE__, type = "Context", &block)
|
||||
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %}
|
||||
{% module_name = (type.id + safe_name.camelcase).id %}
|
||||
{% parent_context_name = PARENT_CONTEXT_NAME %}
|
||||
|
@ -23,12 +23,16 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
macro it(description, &block)
|
||||
macro it(description, source_file = __FILE__, source_line = __LINE__, &block)
|
||||
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
|
||||
{% class_name = (safe_name.camelcase + "Example").id %}
|
||||
class {{class_name.id}} < ::Spectator::Example
|
||||
include Context
|
||||
|
||||
def source
|
||||
Source.new({{source_file}}, {{source_line}})
|
||||
end
|
||||
|
||||
def run
|
||||
{{block.body}}
|
||||
end
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require "./source"
|
||||
|
||||
module Spectator
|
||||
abstract class Example
|
||||
macro is_expected
|
||||
expect(subject)
|
||||
end
|
||||
|
||||
abstract def source : Source
|
||||
|
||||
abstract def run
|
||||
end
|
||||
end
|
||||
|
|
15
src/spectator/source.cr
Normal file
15
src/spectator/source.cr
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Spectator
|
||||
class Source
|
||||
getter file : String
|
||||
getter line : Int32
|
||||
|
||||
def initialize(@file, @line)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
io << file
|
||||
io << ':'
|
||||
io << line
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue