thoughtbot / factory_bot

A library for setting up Ruby objects as test data.
https://thoughtbot.com
MIT License
7.89k stars 2.6k forks source link

While loading spec_helper a `raise SyntaxError` occurred, RSpec will now quit. #1627

Closed pboling closed 4 months ago

pboling commented 4 months ago

Description

To quote my comment on the commit that introduced the "bug":

Was this intentionally released as a non-breaking change, and thus a "not-a-major" version bump?

Using the ... operator, as noted in the git commit comment, is Ruby 3.0+ only. For Rails apps this isn't a huge deal, as they only deal with one version of Ruby at a time. For other libraries that depend on factory_bot this is awful (e.g. https://github.com/pboling/activerecord-transactionable/actions/runs/8169704061/job/22334293843). In that link the latest (broken) gem is installing fine on Ruby 2.5.

I know there is a fair bit of disagreement over how SemVer is interpreted... and this is not serving the community very well.

The person who invented SemVer has recently written an opinion on this topic that I agree with: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html

  1. Good - Major Version Bump
  2. Stinky, but tolerable - update the minimum ruby version of the gem, to 3.0 in this case, in a patch release (this did not happen!)
  3. To the Pain - just break the code, and drop it like it's hot (this is what happened 😿 )

I love the gem. Thanks for all you've done, but I hope this process can improve somehow!

Reproduction Steps

Using a Ruby < 3.0, for example, Ruby 2.5:

gem install factory_bot

Then set it up and use it. 💥

Expected behavior

If the gem sits it fits.

Actual behavior

The gem blew up:

While loading spec_helper a `raise SyntaxError` occurred, RSpec will now quit.
Failure/Error: require "factory_bot"

SyntaxError:
  /home/runner/work/activerecord-transactionable/activerecord-transactionable/vendor/bundle/ruby/2.5.0/gems/factory_bot-6.4.5/lib/factory_bot/evaluator.rb:38: syntax error, unexpected ...
  ...method_missing(method_name, ...)
  ...                            ^~~
  /home/runner/work/activerecord-transactionable/activerecord-transactionable/vendor/bundle/ruby/2.5.0/gems/factory_bot-6.4.5/lib/factory_bot/evaluator.rb:40: syntax error, unexpected ..., expecting ')'
  ...@instance.send(method_name, ...)
  ...                            ^~~
  /home/runner/work/activerecord-transactionable/activerecord-transactionable/vendor/bundle/ruby/2.5.0/gems/factory_bot-6.4.5/lib/factory_bot/evaluator.rb:42: syntax error, unexpected ..., expecting ')'
  ...unner.new.send(method_name, ...)
  ...                            ^~~

System configuration

factory_bot version: 6.4.5 rails version: N/A ruby version: 2.5.9

pboling commented 4 months ago

Duplicate of https://github.com/thoughtbot/factory_bot/issues/1614