-1

I am using rubocop gem. Following is my factorybot code.

factory :cut, class: CutSetting do

  maximum_length 100
  max_colors_cut_together -1

end

Rubocop give the following errors for negative value -1.

Lint/AmbiguousOperator: Ambiguous negative number operator. Parenthesize the method arguments if it's surely a negative number operator, or add a whitespace to the right of the - if it should be a subtraction. (https://github.com/rubocop-hq/ruby-style-guide#method-invocation-parens)

How to solve this problem. PLEASE HELP ME :(.

Thanks in advance.

mikdiet
  • 9,859
  • 8
  • 59
  • 68
Bablu Patel
  • 85
  • 1
  • 8
  • Note that static attributes are deprecated in FactoryBot. In the next version you'll need to use brackets `{}` around all values. – Drenmi Oct 10 '18 at 04:48

2 Answers2

1

I can't add more to Rubocop's error description, it's clear and comprehensive. Adding brackets to -1:

max_colors_cut_together { -1 }

should eliminate that error.

See this cheatsheet as a quick guide on factory_bot patterns.

Ilya Konyukhov
  • 2,666
  • 1
  • 12
  • 21
1

max_colors_cut_together -1 is actually ruby's syntax sugar for method invocation max_colors_cut_together(-1)

mikdiet
  • 9,859
  • 8
  • 59
  • 68