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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With