Basic Controller Rspecs

MyWayOnRails

Suppose the following method is there in the controller

def new
  @post = Post.new
end

For this the corresponding spec will be as follows

describe "GET #new" do
  it "creates new instance of post" do
    get :new
    assigns(:post).should be_a_new(Post)
  end
end

In the above code “get :new” line will get the new path of the controller and execute the corresponding method described in the controller. So that particular statement is very important for execution of the method and comparison of the output in the test.

View original post 458 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: