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:
|
development_dependencies:
|
||||||
spectator:
|
spectator:
|
||||||
gitlab: arctic-fox/spectator
|
gitlab: arctic-fox/spectator
|
||||||
version: ~> 0.9.31
|
version: ~> 0.9.33
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
name: spectator
|
name: spectator
|
||||||
version: 0.9.32
|
version: 0.9.33
|
||||||
description: |
|
description: |
|
||||||
A feature-rich spec testing framework for Crystal with similarities to RSpec.
|
A feature-rich spec testing framework for Crystal with similarities to RSpec.
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Michael Miller <icy.arctic.fox@gmail.com>
|
- Michael Miller <icy.arctic.fox@gmail.com>
|
||||||
|
|
||||||
crystal: 0.35.1
|
crystal: 1.0.0
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,20 @@ Spectator.describe Spectator do
|
||||||
subject(source) { current_example.source }
|
subject(source) { current_example.source }
|
||||||
|
|
||||||
context "line numbers" do
|
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
|
it "contains ending line of spec" do
|
||||||
is_expected.to eq(__LINE__ - 1)
|
expect(source.end_line).to eq(__LINE__ + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles multiple lines and examples" do
|
it "handles multiple lines and examples" do
|
||||||
# Offset is important.
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ module Spectator
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
{% if block.is_a?(Nop) %}
|
{% 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 %}
|
{% 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 %}
|
{% end %}
|
||||||
::Spectator::SpecBuilder.add_example(
|
::Spectator::SpecBuilder.add_example(
|
||||||
{{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}},
|
{{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}},
|
||||||
|
@ -50,9 +50,9 @@ module Spectator
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
{% if block.is_a?(Nop) %}
|
{% 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 %}
|
{% 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 %}
|
{% end %}
|
||||||
::Spectator::SpecBuilder.add_pending_example(
|
::Spectator::SpecBuilder.add_pending_example(
|
||||||
{{description.is_a?(StringLiteral) || description.is_a?(StringInterpolation) || description.is_a?(NilLiteral) ? description : description.stringify}},
|
{{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.
|
# Checks whether the example satisfies the filter.
|
||||||
def includes?(example) : Bool
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,11 +4,17 @@ module Spectator
|
||||||
# Absolute file path.
|
# Absolute file path.
|
||||||
getter file : String
|
getter file : String
|
||||||
|
|
||||||
# Line number in the file.
|
# Starting line number in the file.
|
||||||
getter line : Int32
|
getter line : Int32
|
||||||
|
|
||||||
|
# Ending line number in the file.
|
||||||
|
getter end_line : Int32
|
||||||
|
|
||||||
# Creates the source.
|
# 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
|
end
|
||||||
|
|
||||||
# Parses a source from a string.
|
# Parses a source from a string.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue