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 6779041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:20:16+00:00 2026-05-26T16:20:16+00:00

Just wondering if there’s a way to access local variables in rspec without turning

  • 0

Just wondering if there’s a way to access local variables in rspec without turning them into instance variables? To explain my issue:

I have the following action:

  def queue_due_mail
    payments = Payment.due_soon.where(:send_reminder => true)
    payments.each do |p|
      PaymentMailer.delay.reminder_email(p)
      p.send_reminder = false
      p.save
    end
    redirect_to root_path
  end

And, in my spec, I want to run something like this:

it "should assign nearly due payments to payments" do
  Payment.stub_chain(:due_soon, :where) { [mock_payment] }
  get :queue_due_mail
  assigns[:payments].should eq([mock_payment])
end

The problem is that the assigns[:payments] call only works if I turn the local variable ‘payments’ into ‘@payments’. This isn’t a major problem, but I’d rather not have my rspec tests influence by actual code.

So, is there a way to reference local variables in rspec assigns?

Cheers…

  • 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-26T16:20:16+00:00Added an answer on May 26, 2026 at 4:20 pm

    basically no. Think of it as black-box testing. rspec tests what goes into or out of a method (a controller action is a method). Any local variables should be thrown away at the end of the method – therefore can’t be tested when the method-call is over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just wondering if there is a quick way to echo undefined variables without
Just wondering if there is any way to access the serial port directly in
Just wondering whether there is a way to insert a bulk text message into
Just wondering if there's a way to run Rails tests without dropping the database.
Just wondering if there is any way to get the NS records in C#.
Just wondering if there is a way in Spring to have a parent controller:
Just wondering if there is a way to do a conditional callback in Rails.
Just wondering if there was a way i could print out a number to
Just wondering if there is a way to enable spell checking in Xcode. Maybe
just wondering if there is a simple way in java to display the contents

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.