mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow matching any line number of example in filter
This commit is contained in:
parent
5f15891a41
commit
8fafd2467d
4 changed files with 24 additions and 10 deletions
|
@ -5,15 +5,19 @@ Spectator.describe Spectator do
|
|||
subject(source) { current_example.source }
|
||||
|
||||
context "line numbers" do
|
||||
subject { source.line }
|
||||
it "contains starting line of spec" do
|
||||
expect(source.line).to eq(__LINE__ - 1)
|
||||
end
|
||||
|
||||
it "match source code" do
|
||||
is_expected.to eq(__LINE__ - 1)
|
||||
it "contains ending line of spec" do
|
||||
expect(source.end_line).to eq(__LINE__ + 1)
|
||||
end
|
||||
|
||||
it "handles multiple lines and examples" do
|
||||
# Offset is important.
|
||||
is_expected.to eq(__LINE__ - 2)
|
||||
expect(source.line).to eq(__LINE__ - 2)
|
||||
expect(source.end_line).to eq(__LINE__ + 2)
|
||||
# Offset is still important.
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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}},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue