carbonfive / raygun-rails

Rails 7 application template for Raygun, the Carbon Five Rails application generator.
https://github.com/carbonfive/raygun
52 stars 26 forks source link

Add faker gem and ensure unique generators are reset #710

Closed mattbrictson closed 2 years ago

mattbrictson commented 2 years ago

Proposal

Faker has its pros and cons. On the pro side, using randomly generated data is an easy way to broaden test coverage for cases you might not think to test manually (e.g. what happens when there is an apostrophe in user.last_name?).

The downside is that faker makes it easy to build factories containing nonsense data that don't represent real world use cases, and this can lead to flaky tests.

It's also possible, when building many factory objects that have unique constraints, to exhaust faker's pool of values, which can also lead to unreliable tests.

That said, every Rails project I can remember working on has used faker, and I think the pros outweight the cons. It is often one of the first gems I add to an app generated by raygun.

This commit adds the faker gem to the Gemfile and sets up an after-hook in RSpec to address the problem of running out of unique values.

New Dependencies

faker is well-maintained and extremely popular according to Ruby Toolbox:

https://www.ruby-toolbox.com/projects/faker

mattbrictson commented 2 years ago

On second thought, I think there enough potential downsides to faker (flaky tests) that it doesn't make sense to include out of the box. It is really easy to install if folks want to add it after generating the app. I'll withdraw the PR