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

Running command against changed file #76

Closed
nickhammond opened this issue Sep 29, 2021 · 6 comments · Fixed by #79
Closed

Running command against changed file #76

nickhammond opened this issue Sep 29, 2021 · 6 comments · Fixed by #79
Assignees

Comments

@nickhammond
Copy link

Hey @AlexB52! Really enjoying retest, really lightweight and simple.

I wanted to ping you to see if you had anything in mind or if this is something you have a workflow for. I'd like to run the test like you normally would but then also run rubocop against the changed file as well as the test file.

Something like this:

retest 'bin/rails test <test> && bundle exec rubocop <test> <changed>'

I noticed you just gsub <test> from the command system command.gsub('<test>', cached_test_file) but I think by the time it gets to the runner retest has already detected which spec|test file to use. The rubocop command will take as many files as you throw at it so they can just be listed one after another too.

@AlexB52
Copy link
Owner

AlexB52 commented Sep 29, 2021

Hi @nickhammond

Thanks for the feedback and glad you enjoy retest.

Having a <changed> reference for retest seems like an excellent idea. I'll think about how this could work out. Few things need to be considered like when <test> and <changed> are the same for example.

I'll definitely consider this for the next release but I can't promise a time frame.

@AlexB52
Copy link
Owner

AlexB52 commented Oct 17, 2021

Hello @nickhammond

I have release v1.5.0 which allows you to do what you want.

Based on your example I would recommend using

retest 'bin/rails test <test> && bundle exec rubocop <changed>'

instead of

retest 'bin/rails test <test> && bundle exec rubocop <test> <changed>'

For example, if we have a post.rb and post_test.rb files. Here are the different scenarios

A change on post.rb results in:

  • <changed> => post.rb
  • <test> => post_test.rb

A change on post_test.rb results in:

  • <changed> => post_test.rb
  • <test> => post_test.rb

Let me know if this works as expected :)
Cheers

@nickhammond
Copy link
Author

This is great!! I'll give this a go tomorrow and let ya know.

@nickhammond
Copy link
Author

@AlexB52 Thanks for making this change!

Only feedback I have would be to update the "Files Selected" labels to match the placeholders, swap file: with changed:, your call though.

Files Selected:
  - file: test/models/coupon_test.rb
  - test: test/models/coupon_test.rb
retest 'bin/rails test <test> && bundle exec rubocop <changed>'

@nickhammond
Copy link
Author

@AlexB52 Having <test> <changed> is actually intentional here so that Rubocop will run against both the test and the implementation file, this is to ensure that the cops run against the test files as well. Removing <test> from the retest command only runs it against one file instead of two.

retest 'bin/rails test <test> && bundle exec rubocop <test> <changed>'

@AlexB52
Copy link
Owner

AlexB52 commented Oct 19, 2021

Awesome thanks @nickhammond
Changing file to changed seems like a good idea. I'll create an issue for this.
Cheers

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 a pull request may close this issue.

2 participants