Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 0310777

Browse files
yujinakayamaJonRowe
authored andcommitted
Merge pull request #505 from rspec/support-end-less-methods-in-snippet-extractor
Support end-less methods in Source::Token
1 parent 25f4e3b commit 0310777

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Bug Fixes:
44

55
* Use `Mutex#owned?` to allow `RSpec::Support::ReentrantMutex` to work in
66
nested Fibers on Ruby 3.0 and later. (Benoit Daloze, #503, #504)
7+
* Support `end`-less methods in `RSpec::Support::Source::Token`
8+
so that RSpec won't hang when an `end`-less method raises an error. (Yuji Nakayama, #505)
79

810
### 3.10.2 / 2021-01-28
911
[Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.1...v3.10.2)

lib/rspec/support/source/token.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ def keyword?
5454
type == :on_kw
5555
end
5656

57+
def equals_operator?
58+
type == :on_op && string == '='
59+
end
60+
5761
def opening?
5862
opening_delimiter? || opening_keyword?
5963
end
6064

6165
def closed_by?(other)
62-
closed_by_delimiter?(other) || closed_by_keyword?(other)
66+
delimiter_closed_by?(other) || keyword_closed_by?(other)
6367
end
6468

6569
private
@@ -73,13 +77,16 @@ def opening_keyword?
7377
CLOSING_KEYWORDS_BY_OPENING_KEYWORD.key?(string)
7478
end
7579

76-
def closed_by_delimiter?(other)
80+
def delimiter_closed_by?(other)
7781
other.type == CLOSING_TYPES_BY_OPENING_TYPE[type]
7882
end
7983

80-
def closed_by_keyword?(other)
81-
return false unless other.keyword?
82-
other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string]
84+
def keyword_closed_by?(other)
85+
return false unless keyword?
86+
return true if other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string]
87+
88+
# Ruby 3's `end`-less method definition: `def method_name = body`
89+
string == 'def' && other.equals_operator? && location.line == other.location.line
8390
end
8491
end
8592
end

0 commit comments

Comments
 (0)