RubyMine 2025.2 Help

提取 RSpec 'let'

提取 RSpec 'let' 重构允许您将指定的代码片段提取到一个带有记忆功能的辅助方法中。 为此,请执行以下步骤:

  1. 在 spec 文件中,选择所需的代码片段,然后从主菜单中选择 重构 | 提取/引入 | RSpec 'let' ⌘ ⇧ L

  2. 指定辅助方法的所需名称,然后按 Enter

  3. 如果找到多个代码片段的出现,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日