Difference between an it block and a specify block in RSpec

前端 未结 1 1203
感动是毒
感动是毒 2020-12-23 15:55

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 { su         


        
相关标签:
1条回答
  • 2020-12-23 16:26

    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
    
    0 讨论(0)
提交回复
热议问题