Extract RSpec 'let'
Refactor | Extract/Introduce | 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:
In a spec file, select a required code fragment and select Refactor | Extract/Introduce | RSpec 'let' from the main menu.
Specify the desired name of a helper method and press Enter.
If more than one occurrence of the code fragment is found, RubyMine will suggest replacing these occurrences with a helper method call.
Click Yes to replace the found occurrences. If you want to replace the selected occurrence only, click No.
note
If you click Yes, RubyMine suggests replacing the found occurrences one by one or all at a time.
Before
describe "GetTime" do it "gets the same time" do puts Time.now sleep(3) puts Time.now endend
After
describe "GetTime" do let(:current_time) { Time.now } it "gets the same time" do puts current_time sleep(3) puts current_time endend
Thanks for your feedback!
Was this page helpful?