RSpec 'let'
On this page:
Basics
RubyMine implements extracting let
as follows:
- Introduces the initialization of
let
insiderspec
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 .
- On the context menu of the selection, choose .
- 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" do
it "memorizes the value 2" do
# selection starts here #
count = 1
count1 = count
# selection ends here #
expect(count).to eq(1)
expect(count1).to eq(1)
end
end | RSpec.describe "let" do
let(:name) do
count = 1
count1 = count
return count, count1
end
it "memorizes the value 2" do
count, count1 = name
expect(count).to eq(1)
expect(count1).to eq(1)
end
end |
RSpec.describe "let" do
it "memorizes the value" do
count = 1
count.should == 1
end
end | RSpec.describe "let" do
let(:count) do
count = 1
end
it "memorizes the value" do
count.should == 1
end
end |
RSpec.describe "let" do
it "memorizes the value" do
count = 1
count.should == 1
end
it "memorizes the value" do
count = 1
count.should == 1
end
it "memorizes the value" do
count = 1
count.should == 1
end
end | RSpec.describe "let" do
let(:count) do
count = 1
end
it "memorizes the value" do
count.should == 1
end
it "memorizes the value" do
count.should == 1
end
it "memorizes the value" do
count.should == 1
end
end |
Last modified: 1 August 2018