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

Remove arguments from perform method #140

Merged
merged 1 commit into from
Sep 17, 2020

Conversation

morgoth
Copy link
Collaborator

@morgoth morgoth commented Sep 17, 2020

Follow up to #136 (comment)

@morgoth
Copy link
Collaborator Author

morgoth commented Sep 17, 2020

The linter fails because code uses Ruby 2.5 syntax and Rubocop is set to lint against 2.4 (the same as in gemspec https://github.com/bensheldon/good_job/blob/main/good_job.gemspec#L48) but there are no tests for Ruby 2.4.
Should I change the code to 2.4 syntax or do you think it is fine to bump gem to use 2.5?

@bensheldon
Copy link
Owner

@morgoth Oof, sorry you got bitten by that inconsistency. Let's drop support for Ruby 2.4; it looks like Ruby 2.4 EOLed on March 31, 2020.

Could you please remove the references to 2.4, and change the Linter config to 2.5 as its own PR?

Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic! 🙌

I left some feedback on the tests, specifically to use RSpec message stubs instead of manually setting and resetting global values. I have to apologize (and express my gratitude to you for working in them) because those tests could be more exemplary.

Once you fix the linter issue, and make the changes to the tests, this is ready to go 👍

@@ -204,11 +204,16 @@ def perform(result_value = nil, raise_error: false)
end

it 'can preserve the job' do
good_job.perform(destroy_after: false)
current_preserve_job_records = GoodJob.preserve_job_records
GoodJob.preserve_job_records = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RSpec-y way to do this is with a message stub which will be automatically cleaned up and reset at the end of the test example: allow(GoodJob).to receive(:preserve_job_records).and_return(true)

Comment on lines +215 to +218
if GoodJob.preserve_job_records
save!
else
destroy!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads so much better now with the positive condition coming first 🎉

Comment on lines 273 to 276
current_reperform_jobs_on_standard_error = GoodJob.reperform_jobs_on_standard_error
current_preserve_job_records = GoodJob.preserve_job_records
GoodJob.reperform_jobs_on_standard_error = true
GoodJob.preserve_job_records = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using message stubs allow this to be moved up to the context block so that they are applied to all tests within that context block and avoid test setup repetition.

context 'when true' do
  before do
    allow(GoodJob).to receive(:reperform_jobs_on_standard_error).and_return(true)
    allow(GoodJob).to receive(:preserve_job_records).and_return(true)
   end

   #....

@bensheldon
Copy link
Owner

@morgoth I just merged #142 to unblock this.

@morgoth morgoth force-pushed the remove-args-from-perform branch from 5ca59ca to 72ef163 Compare September 17, 2020 15:12
@morgoth
Copy link
Collaborator Author

morgoth commented Sep 17, 2020

@bensheldon updated and tests are green now. Thanks

@bensheldon bensheldon merged commit 539dabe into bensheldon:main Sep 17, 2020
@bensheldon
Copy link
Owner

@morgoth Thank you! 🙌

@bensheldon bensheldon added the refactor Code changes that do not introduce new features label Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code changes that do not introduce new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants