#2 new
Hugo Corbucci

Inline variable

Reported by Hugo Corbucci | March 26th, 2009 @ 04:27 PM

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"

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Common refactorings for Ruby code, written in Ruby. This project aims to be integrated with several editors (mainly TextMate), to provide simple refactorings.

People watching this ticket

Pages