RSpec 中 it 块和指定块之间的区别 [英] Difference between an it block and a specify block in RSpec
本文介绍了RSpec 中 it 块和指定块之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
RSpec 中的 it 块和指定块有什么区别?
What is the difference between an it block and a specify block in RSpec?
subject { MovieList.add_new(10) }
specify { subject.should have(10).items }
it { subject.track_number.should == 10}
他们似乎做同样的工作.只是检查以确保.
They seem to do the same job. Just checking to be sure.
推荐答案
方法是 相同;提供它们是为了根据您的测试主体使英文规范阅读得更好.考虑这两个:
The methods are the same; they are provided to make specs read in English nicer based on the body of your test. Consider these two:
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
这篇关于RSpec 中 it 块和指定块之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文