On 5/02/14 10:40 PM, siva wrote:
Hi Xavier
Thanks for your reply.
I want assert whether `calculate` has been called no. of times that
loop has been iterated with the same parameters every time.
And on class `InterestAmount` initializer I set the parameters in
instance variables like as follows so that I can use same instance
variables across all methods in `InterestAmount` class.
class InterestAmount
def initialize(installment, date, project)
@installment = installment
@project = project
@date = date
end
end
If you do:
class InterestAmount
def self.calculate(*args); new(*args).calculate; end
#...
end
you hide the initializer, and subsequently your tests get much nicer.
(i.e. listening to the test leads to a nicer interface)
On Wednesday, 5 February 2014 10:42:44 UTC+5:30, Xavier Shay wrote:
On 4/02/14 1:05 AM, siva wrote:
>
>
> Hi all
>
> In my controller I have code as below:
>
> # app/controllers/bookings_controller.rb
>
> @booking.unit_installments.each do |i|
> InterestAmount.new(i, Date.today, project).calculate
> end
>
> I have seen `stub_chain` method but I didn't find how to stub
> chain methods with arguments and how to verify chain methods with
> arguments as well. Could you help me?
What are you trying to test/assert here?
At a first glance, I'd refactor InterestAmount to provide an
interface
`InterestAmount.calculate`, then you don't need to use stub_chain,
and
also hide your implementation.
Cheers,
Xavier
>
> Thanks in advance.
> --
> You received this message because you are subscribed to the Google
> Groups "rspec" group.
> To unsubscribe from this group and stop receiving emails from
it, send
> an email to [email protected] <javascript:>.
> To post to this group, send email to [email protected]
<javascript:>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/rspec/be2b852e-283d-4d80-99c3-c83604aa9513%40googlegroups.com
<https://groups.google.com/d/msgid/rspec/be2b852e-283d-4d80-99c3-c83604aa9513%40googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out
<https://groups.google.com/groups/opt_out>.
--
You received this message because you are subscribed to the Google
Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/444f7e07-369b-47bb-a920-5fce1a282907%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/52F45228.8070000%40xaviershay.com.
For more options, visit https://groups.google.com/groups/opt_out.