To increase reduce complexity for my code As a multi-variable
programmer I want to inline a variable on its scope
Scenario: Invalid Selection
Given a text "dirname = File.dirname '/tmp/file.txt'; puts dirname; dirname + 'my_other_file.txt'"
And I selected "irname"
When I ask for refactoring options
Then I should not be able to "Inline Variable"
Scenario: Valid Selection
Given a text "dirname = File.dirname '/tmp/file.txt'; puts dirname; dirname + 'my_other_file.txt'"
And I selected "dirname"
When I ask for refactoring options
Then I should be able to "Inline Variable"
Scenario: Inlining a variable once
Given a text "dirname = File.dirname '/tmp/file.txt'; puts dirname; File.dirname('/tmp/file.txt') + 'my_other_file.txt'"
And I selected "dirname"
When I run "Inline Variable"
Then I should get "puts File.dirname '/tmp/file.txt'; File.dirname('/tmp/file.txt') + 'my_other_file.txt'"
Scenario: Inlining a variable more than once equally
Given a text "dirname = File.dirname '/tmp/file.txt'; puts dirname; dirname"
And I selected "dirname"
When I run "Inline Variable"
Then I should get "puts File.dirname '/tmp/file.txt'; File.dirname '/tmp/file.txt'"
Scenario: Inlining a variable more than once keeping code sexy
Given a text "dirname = File.dirname '/tmp/file.txt'; puts dirname; dirname + '/other_file.txt'"
And I selected "dirname"
When I run "Inline Variable"
Then I should get "puts File.dirname '/tmp/file.txt'; File.dirname('/tmp/file.txt') + '/other_file.txt'"
Scenario: Inlining a variable more according to scope (not invading smaller scope)
Given a text "dirname = File.dirname '/tmp/file.txt'; variable = lambda {|dirname| puts dirname}; dirname + '/other_file.txt'"
And I selected "dirname"
When I run "Inline Variable"
Then I should get "variable = lambda {|dirname| puts dirname}; File.dirname('/tmp/file.txt') + '/other_file.txt'"
Scenario: Inlining a variable more according to scope (not invading bigger scope)
Given a text "def method\ndirname = File.dirname '/tmp/file.txt'; puts dirname; dirname + '/other_file.txt'\nend\ndef other_method\ndirname = 'a'\nend"
And I selected "dirname"
When I run "Inline Variable"
Given a text "def method\n puts File.dirname '/tmp/file.txt'; File.dirname('/tmp/file.txt') + '/other_file.txt'\nend\ndef other_method\ndirname = 'a'\nend"