ChatGPT解决这个技术问题 Extra ChatGPT

RSpec 中的 it 块和指定块之间的区别

RSpec 中的 it 块和指定块有什么区别?

subject { MovieList.add_new(10) }

specify { subject.should have(10).items }
it { subject.track_number.should == 10}

他们似乎做同样的工作。只是检查确定。


M
Michelle Tilley

方法是the same;提供它们是为了根据您的测试主体使规范以英语阅读更好。考虑这两个:

describe Array do
  describe "with 3 items" do
    before { @arr = [1, 2, 3] }

    specify { @arr.should_not be_empty }
    specify { @arr.count.should eq(3) }
  end
end

describe Array do
  describe "with 3 items" do
    subject { [1, 2, 3] }

    it { should_not be_empty }
    its(:count) { should eq(3) }
  end
end

你是对的,Brandon,itspecify 是相同的方法。您可以查看它们的定义位置 here in the source
优秀的捕捉!您可以从阅读源代码中找到惊人的东西。 :) 我会更新答案。
以下是截至 2013 年 12 月的示例方法名称的要点:gist.github.com/Dorian/7893586(例如,它、指定、焦点……)
better rspec 建议不要使用 should,而支持 expect
更新来自@Jordan 的优秀链接:github.com/rspec/rspec-core/blob/master/lib/rspec/core/… 现在是找到它的地方。