paul
paul

Reputation: 4487

difference between describe, it and def in ruby, rspec

I am new to rspec. Going through tutorials, where I am stuck in beginning of it. When I was working with WATIR, cucumber framework I never saw describe and it.

So whats the difference? What to use when?

Upvotes: 2

Views: 6852

Answers (1)

Gavin Miller
Gavin Miller

Reputation: 43825

Describe is used to explain what is being worked on. Typically you're going to describe a class and it's going to surround all of the it calls. it is the test case(s) that is/are executed within the describe block:

describe Foo do
  it "will return true" do
    expect(Foo.bar).to eq(true)
  end

  it "will return false" do
    expect(Foo.baz).to eq(false)
  end
end

# When run, rspec output is:
Foo
  will return true
  will return false

In the above case, the it method is describing how bar and baz will function on the Foo class. A good read is the rspec documentation on this.

Upvotes: 5

Related Questions