From 5f15891a41b10f8dcfbd8199d7a9a124ab7e589f Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 22 Mar 2021 17:05:28 -0600 Subject: [PATCH 1/7] Crystal 1.0.0 and Spectator 0.9.33 --- README.md | 2 +- shard.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0edf63f..172c5ad 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/shard.yml b/shard.yml index 1779903..f3242a5 100644 --- a/shard.yml +++ b/shard.yml @@ -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 -crystal: 0.35.1 +crystal: 1.0.0 license: MIT From 8fafd2467d9b09e0e0b5e781f9226e2058a77aa1 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Tue, 30 Mar 2021 00:18:08 -0400 Subject: [PATCH 2/7] Allow matching any line number of example in filter --- spec/line_number_spec.cr | 12 ++++++++---- src/spectator/dsl/examples.cr | 8 ++++---- src/spectator/line_example_filter.cr | 8 +++++++- src/spectator/source.cr | 6 +++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spec/line_number_spec.cr b/spec/line_number_spec.cr index 86d858b..b8c0668 100644 --- a/spec/line_number_spec.cr +++ b/spec/line_number_spec.cr @@ -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 diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index 641fe3b..06232e1 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -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}}, diff --git a/src/spectator/line_example_filter.cr b/src/spectator/line_example_filter.cr index 85cd739..4063f34 100644 --- a/src/spectator/line_example_filter.cr +++ b/src/spectator/line_example_filter.cr @@ -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 diff --git a/src/spectator/source.cr b/src/spectator/source.cr index fa8935d..699fb39 100644 --- a/src/spectator/source.cr +++ b/src/spectator/source.cr @@ -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. From 5bd911341b1e8a7c8cbb92ab93812ac1a2a66864 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Tue, 30 Mar 2021 15:29:51 -0400 Subject: [PATCH 3/7] Set end_line equal to line if end_line not provided --- src/spectator/line_example_filter.cr | 10 +++------- src/spectator/source.cr | 10 ++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/spectator/line_example_filter.cr b/src/spectator/line_example_filter.cr index 4063f34..0c65fba 100644 --- a/src/spectator/line_example_filter.cr +++ b/src/spectator/line_example_filter.cr @@ -7,13 +7,9 @@ module Spectator # Checks whether the example satisfies the filter. def includes?(example) : Bool - 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 + start_line = example.source.line + end_line = example.source.end_line + (start_line..end_line).covers?(@line) end end end diff --git a/src/spectator/source.cr b/src/spectator/source.cr index 699fb39..6afa3a7 100644 --- a/src/spectator/source.cr +++ b/src/spectator/source.cr @@ -4,15 +4,17 @@ module Spectator # Absolute file path. getter file : String - # Line number in the file. - # If end_line is present, this is the starting line + # Starting line number in the file. getter line : Int32 # Ending line number in the file. - getter end_line : Int32? + getter end_line : Int32 # Creates the source. - def initialize(@file, @line, @end_line = nil) + 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. From 91ea9e6cab1366a9a33f13f2e9be44570a161a1d Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Tue, 30 Mar 2021 15:31:23 -0400 Subject: [PATCH 4/7] Comment out failing expectation with reference to open issue --- spec/line_number_spec.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/line_number_spec.cr b/spec/line_number_spec.cr index b8c0668..ead7dd2 100644 --- a/spec/line_number_spec.cr +++ b/spec/line_number_spec.cr @@ -16,7 +16,8 @@ Spectator.describe Spectator do it "handles multiple lines and examples" do # Offset is important. expect(source.line).to eq(__LINE__ - 2) - expect(source.end_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 From 6481403c6f278aa96b00cc5847099a5bd206078d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 31 Mar 2021 15:01:01 -0600 Subject: [PATCH 5/7] Bump version to 0.9.34 --- shard.yml | 2 +- src/spectator.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index f3242a5..f6570b0 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: spectator -version: 0.9.33 +version: 0.9.34 description: | A feature-rich spec testing framework for Crystal with similarities to RSpec. diff --git a/src/spectator.cr b/src/spectator.cr index c669c1c..b01464d 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -6,7 +6,7 @@ module Spectator extend self # Current version of the Spectator library. - VERSION = "0.9.32" + VERSION = "0.9.34" # Top-level describe method. # All specs in a file must be wrapped in this call. From 347e07e10437eeed5a02ae4910aa6add317067ef Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 31 Mar 2021 15:07:00 -0600 Subject: [PATCH 6/7] Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52772fc..4df5da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [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) From 2ec6a31f34f197d1005f49f94a54b7955fac1510 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 31 Mar 2021 15:07:43 -0600 Subject: [PATCH 7/7] Update README to reference latest version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 172c5ad..ccfc5f1 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Add this to your application's `shard.yml`: development_dependencies: spectator: gitlab: arctic-fox/spectator - version: ~> 0.9.33 + version: ~> 0.9.34 ``` Usage