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

Commit b5beccf

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 725284c commit b5beccf

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
### Development (unreleased)
22

33
Breaking Changes:
4-
54
* Ruby < 2.3 is no longer supported. (Phil Pirozhkov, #436)
65

76
Bug Fixes:
87
* Use `Mutex#owned?` to allow `RSpec::Support::ReentrantMutex` to work in
98
nested Fibers on Ruby 3.0 and later. (Benoit Daloze, #503)
9+
* Support `end`-less methods in `RSpec::Support::Source::Token`
10+
so that RSpec won't hang when an `end`-less method raises an error. (Yuji Nakayama, #505)
1011

1112
### 3.10.0 / 2020-10-30
1213

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)