mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Merge branch 'issues/19'
This commit is contained in:
commit
10d597b951
6 changed files with 27 additions and 14 deletions
|
@ -25,7 +25,7 @@ Add this to your application's `shard.yml`:
|
|||
development_dependencies:
|
||||
spectator:
|
||||
gitlab: arctic-fox/spectator
|
||||
version: ~> 0.9.31
|
||||
version: ~> 0.9.33
|
||||
```
|
||||
|
||||
Usage
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
name: spectator
|
||||
version: 0.9.32
|
||||
version: 0.9.33
|
||||
description: |
|
||||
A feature-rich spec testing framework for Crystal with similarities to RSpec.
|
||||
|
||||
authors:
|
||||
- Michael Miller <icy.arctic.fox@gmail.com>
|
||||
|
||||
crystal: 0.35.1
|
||||
crystal: 1.0.0
|
||||
|
||||
license: MIT
|
||||
|
||||
|
|
|
@ -5,15 +5,20 @@ 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)
|
||||
# This line fails, refer to https://github.com/crystal-lang/crystal/issues/10562
|
||||
# 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,9 @@ module Spectator
|
|||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example) : Bool
|
||||
@line == example.source.line
|
||||
start_line = example.source.line
|
||||
end_line = example.source.end_line
|
||||
(start_line..end_line).covers?(@line)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,11 +4,17 @@ module Spectator
|
|||
# Absolute file path.
|
||||
getter file : String
|
||||
|
||||
# Line number in the file.
|
||||
# Starting line number in the file.
|
||||
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)
|
||||
# if an end line is not provided,
|
||||
# make the end line the same as the start line
|
||||
@end_line = end_line || @line
|
||||
end
|
||||
|
||||
# Parses a source from a string.
|
||||
|
|
Loading…
Reference in a new issue