ecomba / vim-ruby-refactoring

Refactoring tool for Ruby in vim!
520 stars 52 forks source link

Added pre/post-conditional toggle #36

Closed tobyoconnell closed 12 years ago

tobyoconnell commented 12 years ago

(Pardon the silly markdown formatting)

Added pre/post-conditional toggle and removed stray whitespace at end of statement. (Fails cucumber tests, but test failed before my change. Line ending mismatch or other test shortcoming.)

The original RConvertPostConditional was leaving an undesired space at the end of the statement:

if condition do_something end

That space is now gone from the function and from the corresponding Cucumber test expectation.

Now, when the RConvertPostConditional command is executed (on the line containing the "if") on a pre-conditional expression, the expression will be converted to post-conditional style. Thus, we can toggle between conditional styles. If the block ("do_something") contains more than one line, it will not be toggled.

if condition do_something end

to: do_something if condition

I created a new test, however both fail for me. I hate to send a pull request for failing tests, but I think they might pass for you. The existing test (post-to-pre) failed for me before I altered the code and the new test (pre-to-post) might have failed due to the VimBot cursor being on the wrong line but I'm not sure. My results follow. If you get the same failing results, then I can take a further look.


rake /home/toby/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec cucumber Using the default profile... ......................................................................F..F........

(::) failed steps (::)

expected: "if condition\n do_something\nend" got: "if condition\r do_something\rend\r" (using ==) Diff: @@ -1,4 +1,2 @@ -if condition

expected: "do_something if condition" got: "if condition\n do_something\n" (using ==) Diff: @@ -1,2 +1,3 @@ -do_something if condition +if condition

Failing Scenarios: cucumber features/post_conditional.feature:9 # Scenario: Convert a simple if post-conditional expression cucumber features/post_conditional.feature:25 # Scenario: Convert a simple if pre-conditional expression

23 scenarios (2 failed, 21 passed) 82 steps (2 failed, 80 passed) 0m11.332s