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.
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 .
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.
rspec-rails is a testing framework for Rails 3. x and 4.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With