Skip to content

Instantly share code, notes, and snippets.

@akeem
Created April 5, 2010 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akeem/356874 to your computer and use it in GitHub Desktop.
Save akeem/356874 to your computer and use it in GitHub Desktop.
describe "when handling results" do
before(:each) do
AMQP.stub!(:connect)
MQ.stub!(:new)
Nanite::MapperProxy.new('mapperproxy', {})
@instance = Nanite::MapperProxy.instance
@fanout = stub(:fanout, :publish => true)
@instance.amqp.stub!(:fanout).and_return(@fanout)
end
it "should provide a Hash for final results" do
@response = mock("Response")
@response.should_receive(:token).and_return("test_token")
@response.should_receive(:results).exactly(2).times.and_return({:payload => ['nanite', 'eventmachine', 'rabbitmq']})
result_handler = lambda {}
@fanout.stub!(:fanout)
@instance.pending_requests["test_token"] = {:result_handler => Proc.new{ @response.results} }
@instance.request('/welcome/aboard', 'iZac',{}, &result_handler)
@instance.handle_result(@response).should be_kind_of(Hash)
end
it "should provide a Hash for intermediate results" do
@response = mock("Response")
@response.should_receive(:token).and_return("test_token_2")
@response.should_receive(:results).exactly(2).times.and_return({:payload => ['nanite', 'eventmachine', 'rabbitmq']})
result_handler = lambda {}
@fanout.stub!(:fanout)
int_handler = Proc.new{ @response.results.merge(:time => Time.now)}
@instance.pending_requests["test_token_2"] = {:result_handler => Proc.new{ @response.results},
:intermediate_handler => int_handler}
@instance.request('/welcome/aboard', 'iZac', :intermediate_handler => int_handler, &result_handler)
@instance.handle_intermediate_result(@response).should be_kind_of(Hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment