Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break RSpec matcher to multiple lines

Tags:

ruby

rspec

Is there a way to break long RSpec line to two separate lines:

expect(....).to
   eq(.....)

?

Update:

Now I have an error:

Failure/Error: expect(@query_builder.questions_from_time(@time_to_test)).to ArgumentError: The expect syntax does not support operator matchers, so you must pass a matcher to #to.

The error is disappeared if I remove line break

like image 979
ceth Avatar asked Nov 29 '22 10:11

ceth


1 Answers

to is technically just a method, but the common style is to leave off the parenthesis on the to method in rspec. However, it seems the Ruby parser just doesn't realize you're attempting to send an argument to that to method if you separate it to a new line without parenthesis.

Any of the following should work…

expect(....).
  to eq(.....)

or

expect(....)
  .to eq(.....)

or

expect(....).to eq(
  .....
)

or

expect(
  ....
).to eq(.....)

or

expect(
  ....
).to eq(
  .....
)

I guess the long and short of it is just "don't break before an argument that isn't surrounded by parenthesis". As to which one of these to use — it depends on the particular code. I would do whatever is easiest to read and keeps the line length fairly short.

like image 161
Ben Coppock Avatar answered Dec 01 '22 23:12

Ben Coppock