Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between an it block and a specify block in RSpec

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.

like image 763
basheps Avatar asked Dec 13 '11 03:12

basheps


People also ask

What is let in RSpec?

let generates a method whose return value is memoized after the first call. This is known as lazy loading because the value is not loaded into memory until the method is called. Here is an example of how let is used within an RSpec test. let will generate a method called thing which returns a new instance of Thing .

What does RSpec describe do?

The word describe is an RSpec keyword. It is used to define an “Example Group”. You can think of an “Example Group” as a collection of tests. The describe keyword can take a class name and/or string argument.

What is RSpec rails gem?

rspec-rails is a testing framework for Rails 3. x and 4.

How do I run an RSpec test?

Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.


1 Answers

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 
like image 118
Michelle Tilley Avatar answered Sep 30 '22 15:09

Michelle Tilley