Daniel Daniel - 6 months ago 8
Ruby Question

what does the "it" keyword do in RSpec?

I'm following the rails3tutorial and I don't understand the meaning of the "it" keyword when doing some testing as follows:

require 'spec_helper'

describe UsersController do
render_views

describe "GET 'new'" do
it "should be successful" do
get 'new'
response.should be_success
end

it "should have the right title" do
get 'new'
response.should have_selector("title", :content => "Sign up")
end
end
end


code fragment comes from: http://ruby.railstutorial.org/chapters/filling-in-the-layout#top listing 5.26

Answer

It's not a Ruby keyword, it's part of the Rspec framework.

it contains the code examples that illustrate the facet of behavior being defined. It is comprised of two main parts: the description string and the code example, in the do/end block.