Well,

I think it's even better. If I can access @message_received at any time 
after defining the spy. I might change the matcher itself to iterate over 
the list directly. It match more with my objectives.

thank you

On Friday, November 20, 2020 at 8:32:50 PM UTC+1 [email protected] wrote:

> Luc,
>
> There's no way you can get this information using this syntax, since by 
> the moment `"#{??}"` is evaluated, `have_received`'s `matches?` has not yet 
> been called.
> expect(obj).to(
> have_received(:a).with(:arg_2).twice,
> "#{??}"
> )
>
> You may try passing a proc though 
> https://relishapp.com/rspec/rspec-expectations/v/3-9/docs/customized-message#customize-failure-message-with-a-proc
> There, you can use `::RSpec::Mocks.space.proxy_for(a)` and poke around its 
> `@messages_received`.
>
> So, for:
> ```
>   it {
>     a = double
>     allow(a).to receive(:foo)
>     a.foo(1)
>     expect(a).to have_received(:foo).twice, lambda {
>       puts 
> ::RSpec::Mocks.space.proxy_for(a).instance_variable_get(:@messages_received)
>     }
>   }
> ```
> you'll get:
> ```
> [[:foo, [1], nil]]
> ```
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/09b204c4-5392-4f74-8903-6e95ad57777bn%40googlegroups.com.

Reply via email to