Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:32:28+00:00 2026-05-23T07:32:28+00:00

Can someone please explain the difference between the following methods to me? it should

  • 0

Can someone please explain the difference between the following methods to me?

it "should create a user" do
    lambda do
        post :create, :user => @attr
    end.should change(User, :count).by(1)
end

That is the method as it currently stands. Could this also be achieved with the method below?

it "should create a user" do
    post :create, :user => @attr
    response.should change(User, :count).by(1)
end

Are these effectively the same? Or does the second not work? Because the tutorial I’m following seems to use response whenever possible, yet did not do it in the above case. Can someone please explain the difference between the two above methods, how lambda and RSpec’s response work? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:32:29+00:00Added an answer on May 23, 2026 at 7:32 am

    The lambda form is equivalent to doing this, if the test database is empty:

    User.count.should == 0
    post :create, :user => @attr
    User.count.should == 1
    

    I believe that calling change without supplying a block, as you show in the second example, will generate an error.

    The lambda form is used to wrap a section of code which can be used for setting an expectation in a more convenient way then testing with before and after conditions. In more recent versions of RSpec you’ll also see this done with expect:

    expect {
      post :create, :user => @attr
    }.to change(User, :count).by(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain the difference between the protected and protected internal modifiers in
can someone please explain the difference between these 2 pieces of code: var temp
Can someone please explain the difference between ViewState and Session? More specifically, I'd like
Can someone please explain the difference between IE8 browser mode and document mode in
Can someone please explain me what's the difference between Swing and AWT? Are there
Can someone please explain to me the difference between the AppSettings and ApplicationSettings sections
Can someone please explain what is the main difference between SQL Server Compact Edition
Can someone please explain me the following code snippet? value struct ValueStruct { int
Can someone please explain this to me? I have the following code: <form action=<?php
Can someone please explain what a Tagged PDF is, and how it differs from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.