theSteveMitchell / after_party

Automated post-deploy tasks for Ruby/Rails. Your deployment is the party. This is the after party
MIT License
241 stars 50 forks source link

adding a test generator? #47

Open nevadajames opened 5 years ago

nevadajames commented 5 years ago

Sometimes I find it useful to write tests for after_party tasks, depending on the complexity, even though they are just run once. Maybe it would be useful to be able to automatically generate a test file via a command line argument?
example: rails generate after_party:task test_task --test

And have a basic spec file set up to run the task created.

I've got a working version of this that's been useful for me (and maybe would be a good feature for anyone else using rspec)

Thanks!

theSteveMitchell commented 5 years ago

Hi @navadajames, thanks for the issue and the pr. This is a really good idea, I’m worried though that this could encourage an anti-pattern.

I’ve always held that after party tasks should be as simple as possible - generally my tasks are one-liners that simply call a class method that is already well tested in spece/models. I believe that to be best practice. If we generate specs automatically for each task, I think it would set the expectation that tasks should have logic outside of that scope. The fact that rake tasks are hard to test is a good motivator for developers to follow the best practice.

I believe the best strategy to test after-party tasks is similar to how schema migrations are tested — we run them locally and ensure tests pass after. That said, I’m open to any code change that would help encourage that best practice

nevadajames commented 5 years ago

Hi @theSteveMitchell,
That's a good point about best practices. I did want to include it as an optional argument, just to have it available. But if you don't think as an option as test generator is something you want to include, I'll go ahead and close the PR.

thanks again!