Allow matching any line number of example in filter

This commit is contained in:
matthewmcgarvey 2021-03-30 00:18:08 -04:00
parent 5f15891a41
commit 8fafd2467d
4 changed files with 24 additions and 10 deletions

View file

@ -19,9 +19,9 @@ module Spectator
{% end %}
{% if block.is_a?(Nop) %}
%source = ::Spectator::Source.new({{description.filename}}, {{description.line_number}})
%source = ::Spectator::Source.new({{description.filename}}, line: {{description.line_number}}, end_line: {{description.end_line_number}})
{% else %}
%source = ::Spectator::Source.new({{block.filename}}, {{block.line_number}})
%source = ::Spectator::Source.new({{block.filename}}, line: {{block.line_number}}, end_line: {{block.end_line_number}})
{% end %}
::Spectator::SpecBuilder.add_example(
{{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}},
@ -50,9 +50,9 @@ module Spectator
{% end %}
{% if block.is_a?(Nop) %}
%source = ::Spectator::Source.new({{description.filename}}, {{description.line_number}})
%source = ::Spectator::Source.new({{description.filename}}, line: {{description.line_number}}, end_line: {{description.end_line_number}})
{% else %}
%source = ::Spectator::Source.new({{block.filename}}, {{block.line_number}})
%source = ::Spectator::Source.new({{block.filename}}, line: {{block.line_number}}, end_line: {{block.end_line_number}})
{% end %}
::Spectator::SpecBuilder.add_pending_example(
{{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}},

View file

@ -7,7 +7,13 @@ module Spectator
# Checks whether the example satisfies the filter.
def includes?(example) : Bool
@line == example.source.line
source = example.source
# end_line is present so there is a range to check against
if end_line = source.end_line
(source.line..end_line).covers?(@line)
else
source.line == @line
end
end
end
end

View file

@ -5,10 +5,14 @@ module Spectator
getter file : String
# Line number in the file.
# If end_line is present, this is the starting line
getter line : Int32
# Ending line number in the file.
getter end_line : Int32?
# Creates the source.
def initialize(@file, @line)
def initialize(@file, @line, @end_line = nil)
end
# Parses a source from a string.