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

  • Home
  • SEARCH
  • 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 7815983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:42:09+00:00 2026-06-02T05:42:09+00:00

I have the current spec: describe DELETE ‘destroy’ do let(:client) { create(:client) } #before(:each)

  • 0

I have the current spec:

describe "DELETE 'destroy'" do
  let(:client) { create(:client) }

  #before(:each) do
    #@client = create(:client)
  #end

  it "should delete a client" do
    expect {
      delete :destroy, :id => client
    }.to change(Client, :count).by(-1)
  end

  # ...

end

The example fails when I use let but works fine when I use before(:each).

Here is the implementation code:

def destroy
  client = Client.find(params[:id])
  if client.destroy
    flash[:success] = "Client deleted successfully"
    redirect_to kong_clients_url
  else
    flash[:error] = "Client not deleted for some reason"
    redirect_to kong_clients_url
  end
end

So why does the example fail when I use let?!

  • 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-06-02T05:42:10+00:00Added an answer on June 2, 2026 at 5:42 am

    let is lazy-evaluated, the record isn’t created until you access the client property inside the expect/lambda (+1), but then it’s immediately deleted (-1), so overall inside the expectation the count doesn’t change.

    You can use let! to force it to evaluate straight away:

    let!(:client) { create(:client) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spec in my current project that requires us to advise the
I have current a developed app which I am going to submit in just
I have a current system using IIS 6 and 7, written in ASP.NET with
I have a current 'staging' database in 'heroku' and would like to migrate it
I have a current issue where updates to my clickonce application are messing up
I have this current SP: ALTER PROCEDURE [dbo].[GetHighestDrop] @val1 AS FLOAT , @val2 AS
I have an current location annotation (blue dot) showing in mapkit. Annotation shows after
I have a current URI which filters my search results in the form of
I have the current rewrite rules. RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC] RewriteCond %{HTTP_HOST} !^www\. [NC]
I have my current location fixed via CoreLocation. Now I want to get those

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.