Introduces the initialization of let inside rspec describe/context block as the first statement.
Provides an editable template to insert the new name.
Searches for fragments in the scenarios and replaces them with the let calls.
If a fragment has been found in several scenarios(see example 3), suggests a confirmation dialog:
Performing refactoring
To perform the refactoring, follow these steps:
Open for editing an RSpec file in question.
Make the required selection.
Do one of the following:
On the main menu, choose Refactor | Extract | RSpec 'let'.
On the context menu of the selection, choose Refactor | Extract | RSpec 'let'.
Press Ctrl+Shift+Alt+R.
As a results, a new let block shows up in the current RSpec block.
Examples
Before
After
RSpec.describe"let"doit"memorizes the value 2"do# selection starts here #count=1count1=count# selection ends here #expect(count).toeq(1)expect(count1).toeq(1)endend
RSpec.describe"let"dolet(:name)docount=1count1=countreturncount,count1endit"memorizes the value 2"docount,count1=nameexpect(count).toeq(1)expect(count1).toeq(1)endend
RSpec.describe"let"doit"memorizes the value"docount=1count.should==1endend
RSpec.describe"let"dolet(:count)docount=1endit"memorizes the value"docount.should==1endend
RSpec.describe"let"doit"memorizes the value"docount=1count.should==1endit"memorizes the value"docount=1count.should==1endit"memorizes the value"docount=1count.should==1endend
RSpec.describe"let"dolet(:count)docount=1endit"memorizes the value"docount.should==1endit"memorizes the value"docount.should==1endit"memorizes the value"docount.should==1endend