mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Merge branch 'release/0.10' into specs
This commit is contained in:
parent
79d6ad93b3
commit
d612657b15
6 changed files with 57 additions and 7 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -29,6 +29,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Removed
|
||||
- Removed one-liner it syntax without braces (block).
|
||||
|
||||
## [0.9.34] - 2021-03-31
|
||||
### Changed
|
||||
- Allow filtering examples by using any line in the example block. [#19](https://github.com/icy-arctic-fox/spectator/issues/19) Thanks @matthewmcgarvey !
|
||||
|
||||
## [0.9.33] - 2021-03-22
|
||||
### Changed
|
||||
- Target Crystal 1.0
|
||||
|
||||
## [0.9.32] - 2021-02-03
|
||||
### Fixed
|
||||
- Fix source reference with brace-less example syntax. [#20](https://github.com/icy-arctic-fox/spectator/issues/20)
|
||||
|
@ -266,8 +274,10 @@ This has been changed so that it compiles and raises an error at runtime with a
|
|||
First version ready for public use.
|
||||
|
||||
|
||||
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.32...HEAD
|
||||
[0.9.31]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.31...v0.9.32
|
||||
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...HEAD
|
||||
[0.9.34]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.33...v0.9.34
|
||||
[0.9.33]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.32...v0.9.33
|
||||
[0.9.32]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.31...v0.9.32
|
||||
[0.9.31]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.30...v0.9.31
|
||||
[0.9.30]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.29...v0.9.30
|
||||
[0.9.29]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.28...v0.9.29
|
||||
|
|
|
@ -6,7 +6,7 @@ description: |
|
|||
authors:
|
||||
- Michael Miller <icy.arctic.fox@gmail.com>
|
||||
|
||||
crystal: 0.35.1
|
||||
crystal: 1.0.0
|
||||
|
||||
license: MIT
|
||||
|
||||
|
|
32
spec/line_number_spec.cr
Normal file
32
spec/line_number_spec.cr
Normal file
|
@ -0,0 +1,32 @@
|
|||
require "./spec_helper"
|
||||
|
||||
Spectator.describe Spectator do
|
||||
let(current_example) { ::Spectator::Example.current }
|
||||
subject(location) { current_example.location }
|
||||
|
||||
context "line numbers" do
|
||||
it "contains starting line of spec" do
|
||||
expect(location.line).to eq(__LINE__ - 1)
|
||||
end
|
||||
|
||||
it "contains ending line of spec" do
|
||||
expect(location.end_line).to eq(__LINE__ + 1)
|
||||
end
|
||||
|
||||
it "handles multiple lines and examples" do
|
||||
# Offset is important.
|
||||
expect(location.line).to eq(__LINE__ - 2)
|
||||
# This line fails, refer to https://github.com/crystal-lang/crystal/issues/10562
|
||||
# expect(location.end_line).to eq(__LINE__ + 2)
|
||||
# Offset is still important.
|
||||
end
|
||||
end
|
||||
|
||||
context "file names" do
|
||||
subject { location.file }
|
||||
|
||||
it "match source code" do
|
||||
is_expected.to eq(__FILE__)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -47,7 +47,7 @@ module Spectator::DSL
|
|||
|
||||
::Spectator::DSL::Builder.add_example(
|
||||
_spectator_example_name(\{{what}}),
|
||||
::Spectator::Location.new(\{{block.filename}}, \{{block.line_number}}),
|
||||
::Spectator::Location.new(\{{block.filename}}, \{{block.line_number}}, \{{block.end_line_number}}),
|
||||
new.as(::Spectator::Context),
|
||||
\%tags
|
||||
) do |example|
|
||||
|
|
|
@ -7,7 +7,9 @@ module Spectator
|
|||
|
||||
# Checks whether the example satisfies the filter.
|
||||
def includes?(example) : Bool
|
||||
@line == example.location.line
|
||||
start_line = example.location.line
|
||||
end_line = example.location.end_line
|
||||
(start_line..end_line).covers?(@line)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,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 location.
|
||||
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 location from a string.
|
||||
|
|
Loading…
Reference in a new issue