diff --git a/spec/helpers/errored_example.cr b/spec/helpers/errored_example.cr index bd71bb4..f535ba7 100644 --- a/spec/helpers/errored_example.cr +++ b/spec/helpers/errored_example.cr @@ -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. diff --git a/spec/helpers/failing_example.cr b/spec/helpers/failing_example.cr index db07310..76792c5 100644 --- a/spec/helpers/failing_example.cr +++ b/spec/helpers/failing_example.cr @@ -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. diff --git a/spec/helpers/passing_example.cr b/spec/helpers/passing_example.cr index 0061fc3..dcd0a60 100644 --- a/spec/helpers/passing_example.cr +++ b/spec/helpers/passing_example.cr @@ -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. diff --git a/spec/helpers/spy_example.cr b/spec/helpers/spy_example.cr index 0d77df4..66e4338 100644 --- a/spec/helpers/spy_example.cr +++ b/spec/helpers/spy_example.cr @@ -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. diff --git a/spec/pending_example_spec.cr b/spec/pending_example_spec.cr index 0991359..9ea1a51 100644 --- a/spec/pending_example_spec.cr +++ b/spec/pending_example_spec.cr @@ -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 diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index 0272171..4583ec5 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -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 diff --git a/src/spectator/dummy_example.cr b/src/spectator/dummy_example.cr index d6e4eff..f58f91f 100644 --- a/src/spectator/dummy_example.cr +++ b/src/spectator/dummy_example.cr @@ -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. diff --git a/src/spectator/example.cr b/src/spectator/example.cr index 231913e..9f1ab0f 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -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. diff --git a/src/spectator/formatters/failure_block.cr b/src/spectator/formatters/failure_block.cr index 0d58c59..0834ccb 100644 --- a/src/spectator/formatters/failure_block.cr +++ b/src/spectator/formatters/failure_block.cr @@ -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)