Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricter RSpec tests #375

Merged
merged 3 commits into from
Sep 1, 2024
Merged

Stricter RSpec tests #375

merged 3 commits into from
Sep 1, 2024

Conversation

dgmstuart
Copy link
Owner

No description provided.

If a doubled constant doesn't exist then Rails won't verify methods on
it, so we generally want to verify that they do exist. However, we
_don't_ want to verify them in two scenarios:

  - when running isolated spec files (since those constants won't be
    loaded, so would result in verification failures)
  - when TDDing a file (isolated or not) which uses collaborators which
    don't exist yet

In both of those scenarios we're running a single file, so we can use
that as a proxy.

Note that if we were to add it to rails_helper then it would only be
applied to files which were loaded after the first file which loaded
rails helper, which would lead to inconsistent behaviour because of our
random loading.
Found using rsp --warnings
When we use `require`, Ruby makes sure that we only load the file once,
but since here we're explictly pushing things onto the load path we need
to do that check ourself.

Found using bin/rspec --warnings, which showed the following:

    /Users/dgmstuart/dev/swing-out-london/config/locales/en.rb:3: warning: method redefined; discarding old ordinal_day
    /Users/dgmstuart/dev/swing-out-london/config/locales/en.rb:3: warning: previous definition of ordinal_day was here
    /Users/dgmstuart/dev/swing-out-london/config/locales/en.rb:7: warning: method redefined; discarding old human_date
    /Users/dgmstuart/dev/swing-out-london/config/locales/en.rb:7: warning: previous definition of human_date was here

...since these methods are defined in the locale file which is being
loaded here.
@dgmstuart dgmstuart merged commit cad63e9 into main Sep 1, 2024
1 check passed
@dgmstuart dgmstuart deleted the dgms/stricter-rspec branch September 1, 2024 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant