File tree 3 files changed +42
-7
lines changed
3 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
9
9
### Added
10
10
11
11
- [ #7 ] ( https://github.com/kddnewton/syntax_tree/issues/7 ) Better formatting for hashes and arrays that are values in hashes.
12
+ - [ #9 ] ( https://github.com/kddnewton/syntax_tree/issues/9 ) Special handling for RSpec matchers when nesting ` CommandCall ` nodes.
12
13
13
14
## [ 1.1.0] - 2021-12-08
14
15
Original file line number Diff line number Diff line change @@ -3771,14 +3771,8 @@ def format(q)
3771
3771
end
3772
3772
3773
3773
if arguments
3774
- width = doc_width ( doc ) + 1
3775
3774
q . text ( " " )
3776
-
3777
- if width > ( q . maxwidth / 2 )
3778
- q . format ( arguments )
3779
- else
3780
- q . nest ( width ) { q . format ( arguments ) }
3781
- end
3775
+ q . nest ( argument_alignment ( q , doc ) ) { q . format ( arguments ) }
3782
3776
end
3783
3777
end
3784
3778
end
@@ -3843,6 +3837,28 @@ def doc_width(parent)
3843
3837
3844
3838
width
3845
3839
end
3840
+
3841
+ def argument_alignment ( q , doc )
3842
+ # Very special handling case for rspec matchers. In general with rspec
3843
+ # matchers you expect to see something like:
3844
+ #
3845
+ # expect(foo).to receive(:bar).with(
3846
+ # 'one',
3847
+ # 'two',
3848
+ # 'three',
3849
+ # 'four',
3850
+ # 'five'
3851
+ # )
3852
+ #
3853
+ # In this case the arguments are aligned to the left side as opposed to
3854
+ # being aligned with the `receive` call.
3855
+ if [ "to" , "not_to" , "to_not" ] . include? ( message . value )
3856
+ 0
3857
+ else
3858
+ width = doc_width ( doc ) + 1
3859
+ width > ( q . maxwidth / 2 ) ? 0 : width
3860
+ end
3861
+ end
3846
3862
end
3847
3863
3848
3864
# :call-seq:
Original file line number Diff line number Diff line change 5
5
-
6
6
foo.bar barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr,
7
7
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
8
+ %
9
+ expect(foo).to receive(fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo)
10
+ -
11
+ expect(foo).to receive(
12
+ fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
13
+ )
14
+ %
15
+ expect(foo).not_to receive(fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo)
16
+ -
17
+ expect(foo).not_to receive(
18
+ fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
19
+ )
20
+ %
21
+ expect(foo).to_not receive(fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo)
22
+ -
23
+ expect(foo).to_not receive(
24
+ fooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
25
+ )
You can’t perform that action at this time.
0 commit comments