· 7 years ago · Aug 15, 2018, 03:52 PM
1How do you mock a method with a block using RR (double ruby) on Rails 3
2@graph = Koala::Facebook::API.new(oauth_token)
3 @graph.batch do |batch_api|
4 #... do stuff here
5 end
6
7oauth_token= "Sometoken"
8batch_api_mock = nil
9graph_mock = mock(Koala::Facebook::API).new(oauth_token).mock!
10graph_mock.batch.returns do
11 yield batch_api_mock if block_given?
12end
13
14oauth_token= "Sometoken"
15batch_api_mock = nil
16graph_mock = mock(Koala::Facebook::API).new(oauth_token).mock!
17
18#The block is passed in as a proc as the first argument to the returns block.
19graph_mock.batch.returns do |proc_as_block|
20 proc_as_block.call
21end