-
-
Save pdlug/356879 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
@payload = {:payload => ['nanite', 'eventmachine', 'rabbitmq']} | |
end | |
describe 'final results' do | |
before do | |
@response = mock("Response") | |
@response.should_receive(:token).and_return("test_token") | |
@response.should_receive(:results).exactly(2).times.and_return() | |
result_handler = lambda {} | |
@fanout.stub!(:fanout) | |
@instance.pending_requests["test_token"] = {:result_handler => Proc.new{ @response.results} } | |
@instance.request('/welcome/aboard', 'iZac',{}, &result_handler) | |
end | |
it "should return the provided payload through the result handler" do | |
@instance.handle_result(@response).should == @payload | |
end | |
end | |
describe 'intermediate results' do | |
before 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) | |
end | |
it "should return the provided payload through the intermediate result handler" do | |
@instance.handle_intermediate_result(@response).should be_kind_of(Hash) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment