【问题标题】:how to transform old rspec-syntax "it { should_not be_valid }" to rspec2?如何将旧的 rspec 语法“it { should_not be_valid }”转换为 rspec2?
【发布时间】:2015-01-08 13:43:01
【问题描述】:

从旧的 rspec 语法转换为新的语法:

旧:

 describe "when password is not present" do
    before { @user.password = @user.password_confirmation = " " }

    it { should_not be_valid }
  end

使用较新的 expect-syntax 时,it 部分应该是什么样子?

【问题讨论】:

    标签: rspec rspec2


    【解决方案1】:

    使用期望语法,测试将是:

    it { is_expected.not_to be_valid }
    

    请注意,对于单行语法,仍然支持 should-syntax(即没有弃用警告),因此您不必进行任何更改。来自Relish page on RSpec Core 3.1

    • is_expected 被简单地定义为 expect(subject) 并且设计用于当您使用 rspec-expectations 及其较新的基于期望的 语法。
    • should 是在 rspec-expectations 仅具有基于 should 的语法时设计的。但是,它仍然可用并正常工作 即使 :should 语法被禁用(因为这只是删除 Object#should 但这是 RSpec::Core::ExampleGroup#should)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多