RubyMine 2019.2 Help

Extract RSpec 'let'

The Extract RSpec 'let' refactoring allows you to extract a specified code fragment into a memoized helper method. To do this, perform the following steps:

  1. In a spec file, select a required code fragment and select Refactor | Extract | RSpec 'let' N/A from the main menu.

  2. Specify the desired name of the helper method and press Enter.

  3. (Optional) If more than one occurrence of the code fragment is found, RubyMine will show the following dialog.

    Extract method

    Click Yes to replace the found occurrences with a helper method call. If you want to replace only the selected occurrence, click No.

  4. (Optional) If you clicked Yes in the previous step, RubyMine suggests you replace the found occurrences one by one or all at a time.

Example

Before

After

describe "GetTime" do it "gets the same time" do puts Time.now sleep(3) puts Time.now end end
describe "GetTime" do let(:current_time) { Time.now } it "gets the same time" do puts current_time sleep(3) puts current_time end end
Last modified: 5 September 2019