Just went with a define_singleton_method.

Il giorno martedì 12 febbraio 2013 09:56:35 UTC+1, kain ha scritto:
>
> Hello,
> sorry for the bad title. I have this simple class:
>
> class Push
>   def self.fire(event, channel, payload = nil)
>     channel, event = channel.to_s, event.to_s
>     $redis.publish('dispatch', prepare_packet(channel, event, payload))
>   end
>   ...
>
> Before that I was using method_missing to do Push.fire_my_event(channel, 
> payload) and map the capture of fire_(.*) as the event, however in the 
> effort of reducing CPU time I decided to switch to a more traditional 
> approach that you see above: Push.fire(:event, 'channel', payload).
>
> Now, the problem is that it was easy for me to write in a single test 
> something like this:
>
>         it "should call correct methods for push engine" do
>           
> Push.should_receive(:fire_media_destroy).with(subject.account.private_comet_channel,
>  
> { media_file: subject.to_websocket }).once
>
> and automatically all the other Push calls would get ignored.
>
> Now if I write:
>
>         it "should call correct methods for push engine" do
>           Push.should_receive(:fire).with(:media_destroy, 
> subject.account.private_comet_channel, { media_file: subject.to_websocket 
> }).once
>
> it fails because the Push.fire is employed in many parts of the app, and 
> it's code that it's run well before the test, with other parameters.
>
> Can as_null_object help here without rewriting the whole test suite?
>
> Another small issue what I found is that rspec is swallowing exceptions. 
> For example the error:
>
> <Push (class)> received :fire with unexpected arguments
>
> is written only in the logs. Sometimes I see tests passes but if I look at 
> the logs the exception is there, this is especially dangerous when using 
> should_receive(:arg).never
>

-- 
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/msg/rspec/-/F7zUdGhR_UAJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to