Replace source file and line with source struct

This commit is contained in:
Michael Miller 2019-02-17 12:40:16 -07:00
parent ffca0316a4
commit ed01a95e67
9 changed files with 26 additions and 70 deletions

View file

@ -5,14 +5,9 @@ class ErroredExample < Spectator::RunnableExample
"ERROR"
end
# Dummy source file.
def source_file
__FILE__
end
# Dummy source line number.
def source_line
__LINE__
# Dummy source.
def source
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy instance.

View file

@ -5,14 +5,9 @@ class FailingExample < Spectator::RunnableExample
"FAIL"
end
# Dummy source file.
def source_file
__FILE__
end
# Dummy source line number.
def source_line
__LINE__
# Dummy source.
def source
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy instance.

View file

@ -5,14 +5,9 @@ class PassingExample < Spectator::RunnableExample
"PASS"
end
# Dummy source file.
def source_file
__FILE__
end
# Dummy source line number.
def source_line
__LINE__
# Dummy source.
def source
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy instance.

View file

@ -6,14 +6,9 @@ class SpyExample < Spectator::RunnableExample
"SPY"
end
# Dummy source file.
def source_file
__FILE__
end
# Dummy source line number.
def source_line
__LINE__
# Dummy source.
def source
::Spectator::Source.new(__FILE__, __LINE__)
end
# Dummy instance.

View file

@ -5,12 +5,8 @@ class ConcretePendingExample < Spectator::PendingExample
"PENDING_TEST_EXAMPLE"
end
def source_file
__FILE__
end
def source_line
__LINE__
def source
::Spectator::Source.new(__FILE__, __LINE__)
end
def instance

View file

@ -1354,14 +1354,9 @@ module Spectator::DSL
# Create a class derived from `RunnableExample` to run the test code.
_spectator_example(Example%example, Test%example, ::Spectator::RunnableExample, {{what}}) do
# Source file the example originated from.
def source_file
{{_source_file}}
end
# Line number in the source file the example originated from.
def source_line
{{_source_line}}
# Source where the example originated from.
def source
::Spectator::Source.new({{_source_file}}, {{_source_line}})
end
# Implement abstract method to run the wrapped example block.
@ -1408,14 +1403,9 @@ module Spectator::DSL
# Create a class derived from `PendingExample` to skip the test code.
_spectator_example(Example%example, Test%example, ::Spectator::PendingExample, {{what}}) do
# Source file the example originated from.
def source_file
{{_source_file}}
end
# Line number in the source file the example originated from.
def source_line
{{_source_line}}
# Source where the example originated from.
def source
::Spectator::Source.new({{_source_file}}, {{_source_line}})
end
end

View file

@ -14,14 +14,9 @@ module Spectator
"DUMMY"
end
# Dummy source file.
def source_file
__FILE__
end
# Dummy source line number.
def source_line
__LINE__
# Dummy source.
def source
Source.new(__FILE__, __LINE__)
end
# Dummy instance.

View file

@ -13,11 +13,8 @@ module Spectator
# Retrieves the internal wrapped instance.
abstract def instance
# Source file the example originated from.
abstract def source_file : String
# Line number in the source file the example originated from.
abstract def source_line : Int64
# Source where the example originated from.
abstract def source : Source
# Runs the example code.
# A result is returned, which represents the outcome of the test.

View file

@ -4,9 +4,7 @@ module Spectator::Formatters
end
def source(io)
io << @result.example.source_file
io << ':'
io << @result.example.source_line
@result.example.source.to_s(io)
end
def to_s(io)