ecomba/vim-ruby-refactoring — pull request #36 by tobyoconnell (2011-12-05 07:46:39+00:00)
Title: Added pre/post-conditional toggle

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.)

1. 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.

2. 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
# => do_something if condition

3. 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
- do_something
-end
endo_something
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/shared_steps.rb:10:in `/^I should see:$/'
features/post_conditional.feature:18:in `Then I should see:'

expected: "do_something if condition"
got: "if condition\n do_something\n" (using ==)
Diff:
@@ -1,2 +1,3 @@
-do_something if condition
+if condition
+ do_something
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/shared_steps.rb:10:in `/^I should see:$/'
features/post_conditional.feature:36:in `Then I should see:'

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