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

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

subject { MovieList.add_new(10) }


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

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

24693 次浏览

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