This PR refactors the test suites for _user_util_links.html.erb_spec.rb and _index_list_default.html.erb_spec.rb to remove the deprecated stub_chain methods. The code now relies on cleaner, up-to-date RSpec syntax, and is more maintainable as a result.
Details
Deprecated stub_chain methods were removed from both files, replacing them with cleaner helper methods to improve readability and maintainability.
The test in _index_list_default.html.erb_spec.rb was making a direct Solr call, which has now been mocked to isolate the test from external dependencies. This also allows the test to be run outside of the Solr environment. (If the stub is removed and the Solr environment is active, the test still passes.)
How the stub_chain is handled:
Helper method for setting up a mock for current_ability
def stub_current_ability(return_value)
current_ability = double('CurrentAbility')
allow(view).to receive(:current_ability).and_return(current_ability)
allow(current_ability).to receive(:can_create_any_work?).and_return(return_value)
end
Usage inside the before block
stub_current_ability(true)
Why "allow" Over "expect"
We opted to use allow instead of expect because these stubs were set up in before-do blocks and are not the primary behavior under test. By using allow, we can establish the necessary background for the actual tests without enforcing strict expectations on the messages received by our doubles, making the tests less brittle and more focused on what we are actually interested in testing.
Additional changes
added two tests for inheritance to offset supposed decrease in test coverage
added option to pull environment variable for FITS_FILENAME so that developers using "fits" instead of "fits.sh" will be able to add that ENV variable to their local config and override the default "fits.sh". If they use a local environment variable, it will eliminate accidental overwrites of the config/initializers/hyrax.rb file with local changes.
Fixes #1082
_Removes old stubchain methods
Summary
This PR refactors the test suites for _user_util_links.html.erb_spec.rb and _index_list_default.html.erb_spec.rb to remove the deprecated stub_chain methods. The code now relies on cleaner, up-to-date RSpec syntax, and is more maintainable as a result.
Details
How the stub_chain is handled:
Helper method for setting up a mock for current_ability
Usage inside the before block
Why "allow" Over "expect"
We opted to use allow instead of expect because these stubs were set up in before-do blocks and are not the primary behavior under test. By using allow, we can establish the necessary background for the actual tests without enforcing strict expectations on the messages received by our doubles, making the tests less brittle and more focused on what we are actually interested in testing.
Additional changes
config/initializers/hyrax.rb
file with local changes.