Merge branch 'release/0.10' into specs

This commit is contained in:
Michael Miller 2021-03-31 15:28:16 -06:00
parent 79d6ad93b3
commit d612657b15
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
6 changed files with 57 additions and 7 deletions

View file

@ -29,6 +29,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Removed one-liner it syntax without braces (block). - 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 ## [0.9.32] - 2021-02-03
### Fixed ### Fixed
- Fix source reference with brace-less example syntax. [#20](https://github.com/icy-arctic-fox/spectator/issues/20) - 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. First version ready for public use.
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.32...HEAD [Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...HEAD
[0.9.31]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.31...v0.9.32 [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.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.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 [0.9.29]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.28...v0.9.29

View file

@ -6,7 +6,7 @@ description: |
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

32
spec/line_number_spec.cr Normal file
View 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

View file

@ -47,7 +47,7 @@ module Spectator::DSL
::Spectator::DSL::Builder.add_example( ::Spectator::DSL::Builder.add_example(
_spectator_example_name(\{{what}}), _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), new.as(::Spectator::Context),
\%tags \%tags
) do |example| ) do |example|

View file

@ -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.location.line start_line = example.location.line
end_line = example.location.end_line
(start_line..end_line).covers?(@line)
end end
end end
end end

View file

@ -6,11 +6,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 location. # 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 end
# Parses a location from a string. # Parses a location from a string.