提取 RSpec 'let'
提取 RSpec 'let' 重构允许您将指定的代码片段提取到一个带有记忆功能的辅助方法中。 为此,请执行以下步骤:
在 spec 文件中,选择所需的代码片段,然后从主菜单中选择 ⌘ ⇧ L。
指定辅助方法的所需名称,然后按 Enter。
如果找到多个代码片段的出现,RubyMine 将建议用辅助方法调用替换这些出现。

单击 是 以替换找到的出现。 如果您只想替换选定的出现,请单击 否。
示例
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
最后修改日期: 2025年 9月 26日