Conversation
|
Being able to write tests in this way offers a few advantages:
To be clear, we see this as an addition to the existing testing format of the minitest file which is prettier'd and then run post-formatting. |
f70d746 to
df28311
Compare
|
Looks like |
|
Yeah they introduced a new node type yesterday https://bugs.ruby-lang.org/issues/4475. It looks like |
|
Okay I added support for that node type, so if you wouldn't mind rebasing it should work again. |
df28311 to
e54c18b
Compare
|
And rebased. @kddeisz |
Why: We would like to be able to have explicit tests that will allow to ensure that prettier-ruby behaves as intended. Ideally these tests can be run independently and could allow for TDD. This commit: introduces an assert_equal_and_valid method which takes an input string and an expected output string and will validate that prettier can be applied to the expected string by: writing the expected string to a Tempfile, 'prettier-ruby-test.rb', applying prettier-ruby to the Tempfile with the 'bin/print' executable, asserting with minitest that the resultant file is equal to the expected string, and executing the resultant file with Open3 to capture any stderr and status to validate that the formatted code can be run without throwing an error. Two example specs are provided in this commit to demonstrate the spec helpers usage Co-authored-by: christoomey <chris@thoughtbot.com> Co-authored-by: johnschoeman <johnschoeman1617@gmail.com>
Why:
Currently if a block is given just a parameter and no actual content the
formatter will return a block with an extra space, which is a rubocop
error: 'Layout/ExtraSpacing: Layout/ExtraSpacing: Unnecessary spacing
detected.'
for example: { |el| } -> { |el| }
This commit:
Updates the block node to not add an extra space if the block has no
contents.
Co-authored-by: christoomey <chris@thoughtbot.com>
Co-authored-by: johnschoeman <johnschoeman1617@gmail.com>
e54c18b to
115d545
Compare
|
Thank you thank you thank you for your work on this. Even though this isn't the direction I ended up going in for the tests, I really appreciate the contribution. |
Commit 1:
Introduce spec helpers …
Why:
We would like to be able to have explicit tests that will allow to
ensure that prettier-ruby behaves as intended. Ideally these tests can
be run independently from the test suite and could allow for TDD.
This commit:
introduces an assert_equal_and_valid method which takes an input string
and an expected output string and will validate that prettier can be
applied to the expected string by:
writing the expected string to a Tempfile, 'prettier-ruby-test.rb',
applying prettier-ruby to the Tempfile with the 'bin/print' executable,
asserting with minitest that the resultant file is equal to the expected
string,
and executing the resultant file with Open3 to capture any stderr and
status to validate that the formatted code can be run without throwing
an error.
Two example specs are provided in this commit to demonstrate the spec
helpers usage
Co-authored-by: christoomey chris@thoughtbot.com
Co-authored-by: johnschoeman johnschoeman1617@gmail.com
Commit 2:
Fix block spacing bug …
Why:
Currently if a block is given just a parameter and no actual content the
formatter will return a block with an extra space, which is a rubocop
error: 'Layout/ExtraSpacing: Layout/ExtraSpacing: Unnecessary spacing
detected.'
for example:
becomes
This commit:
Updates the block node to not add an extra space if the block has no
contents.
Co-authored-by: christoomey chris@thoughtbot.com
Co-authored-by: johnschoeman johnschoeman1617@gmail.com