Difference between an it block and a specify block in RSpec

Ruby on-RailsRubyRspec

Ruby on-Rails Problem Overview


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.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbashepsView Question on Stackoverflow
Solution 1 - Ruby on-RailsMichelle TilleyView Answer on Stackoverflow