diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/publics_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/helper_methods.rb | 6 | ||||
-rw-r--r-- | spec/lib/em-webfinger_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/message_handler_spec.rb | 117 | ||||
-rw-r--r-- | spec/models/user/user_friending_spec.rb | 8 | ||||
-rw-r--r-- | spec/spec_helper.rb | 14 |
6 files changed, 81 insertions, 73 deletions
diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 4255cd884..c72d290e7 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -22,6 +22,10 @@ describe PublicsController do end describe '#receive' do + before do + EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success)) + end + context 'success cases' do it 'should 200 on successful receipt of a request' do EM::run { diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index 6c159d0b0..e60b39535 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -16,6 +16,12 @@ module HelperMethods models end + def stub_user_message_handle_methods(user) + user.stub!(:push_to_people) + user.stub!(:push_to_hub) + user.stub!(:push_to_person) + end + def message_queue User::QUEUE end diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index da60dabc2..9c6d384a2 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -67,7 +67,7 @@ describe EMWebfinger do n = EMWebfinger.new("foo@example.com") n.on_person{|person| - person.should == "webfinger does not seem to be enabled for #{fake_account}" + person.should == "webfinger does not seem to be enabled for #{fake_account}'s host" } end end @@ -107,8 +107,7 @@ describe EMWebfinger do context 'webfingering local people' do it 'should return a person from the database if it matches its handle' do - person - EventMachine::HttpRequest.should_not_receive(:new) + person.save EM.run do finger.on_person { |p| p.should == person diff --git a/spec/lib/message_handler_spec.rb b/spec/lib/message_handler_spec.rb index 7be38567f..4cd0494c7 100644 --- a/spec/lib/message_handler_spec.rb +++ b/spec/lib/message_handler_spec.rb @@ -5,57 +5,54 @@ require 'spec_helper' describe MessageHandler do - before do - unstub_mocha_stubs - end - after do - MessageHandler.any_instance.stubs(:add_post_request) - end + + let(:handler) {MessageHandler.new()} + let(:message_body) {"I want to pump you up"} + let(:message_urls) {["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]} + let(:success) {FakeHttpRequest.new(:success)} + let(:failure) {FakeHttpRequest.new(:failure)} before do - @handler = MessageHandler.new - @message_body = "I want to pump you up" - @message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"] + handler.clear_queue + end + after(:all) do + handler.clear_queue end describe 'GET messages' do describe 'creating a GET query' do it 'should be able to add a GET query to the queue with required destinations' do EventMachine.run{ - @handler.add_get_request(@message_urls) - @handler.size.should == @message_urls.size + handler.add_get_request(message_urls) + handler.size.should == message_urls.size EventMachine.stop } end - end describe 'processing a GET query' do it 'should remove sucessful http requests from the queue' do - request = FakeHttpRequest.new(:success) - request.should_receive(:get).and_return(request) - EventMachine::HttpRequest.stub!(:new).and_return(request) + EventMachine::HttpRequest.stub!(:new).and_return(success) EventMachine.run { - @handler.add_get_request("http://www.google.com/") - @handler.size.should == 1 - @handler.process - @handler.size.should == 0 + handler.add_get_request("http://www.google.com/") + handler.size.should == 1 + handler.process + handler.size.should == 0 EventMachine.stop } end it 'should only retry a bad request the correct number of times' do - request = FakeHttpRequest.new(:failure) - request.should_receive(:get).exactly(MessageHandler::NUM_TRIES).times.and_return(request) - EventMachine::HttpRequest.stub!(:new).and_return(request) + failure.should_receive(:get).exactly(MessageHandler::NUM_TRIES).times.and_return(failure) + EventMachine::HttpRequest.stub!(:new).and_return(failure) EventMachine.run { - @handler.add_get_request("http://asdfsdajfsdfbasdj.com/") - @handler.size.should == 1 - @handler.process - @handler.size.should == 0 + handler.add_get_request("http://asdfsdajfsdfbasdj.com/") + handler.size.should == 1 + handler.process + handler.size.should == 0 EventMachine.stop } @@ -65,34 +62,37 @@ describe MessageHandler do describe 'POST messages' do it 'should be able to add a post message to the queue' do + EventMachine::HttpRequest.stub!(:new).and_return(success) + EventMachine.run { - @handler.size.should ==0 - @handler.add_post_request(@message_urls.first, @message_body) - @handler.size.should == 1 + handler.size.should ==0 + handler.add_post_request(message_urls.first, message_body) + handler.size.should == 1 EventMachine.stop } end it 'should be able to insert many posts into the queue' do + EventMachine::HttpRequest.stub!(:new).and_return(success) + EventMachine.run { - @handler.size.should == 0 - @handler.add_post_request(@message_urls, @message_body) - @handler.size.should == @message_urls.size + handler.size.should == 0 + handler.add_post_request(message_urls, message_body) + handler.size.should == message_urls.size EventMachine.stop } end it 'should post a single message to a given URL' do - request = FakeHttpRequest.new(:success) - request.should_receive(:post).and_return(request) - EventMachine::HttpRequest.stub!(:new).and_return(request) - EventMachine.run{ + success.should_receive(:post).and_return(success) + EventMachine::HttpRequest.stub!(:new).and_return(success) - @handler.add_post_request(@message_urls.first, @message_body) - @handler.size.should == 1 - @handler.process - @handler.size.should == 0 + EventMachine.run{ + handler.add_post_request(message_urls.first, message_body) + handler.size.should == 1 + handler.process + handler.size.should == 0 EventMachine.stop @@ -109,8 +109,8 @@ describe MessageHandler do feed_location = "http://google.com/" EventMachine.run { - @handler.add_hub_notification(destination, feed_location) - q = @handler.instance_variable_get(:@queue) + handler.add_hub_notification(destination, feed_location) + q = handler.instance_variable_get(:@queue) message = "" q.pop{|m| message = m} @@ -126,35 +126,33 @@ describe MessageHandler do describe "Mixed Queries" do it 'should process both POST and GET requests in the same queue' do - request = FakeHttpRequest.new(:success) - request.should_receive(:get).exactly(3).times.and_return(request) - request.should_receive(:post).exactly(3).times.and_return(request) - EventMachine::HttpRequest.stub!(:new).and_return(request) + success.should_receive(:get).exactly(3).times.and_return(success) + success.should_receive(:post).exactly(3).times.and_return(success) + EventMachine::HttpRequest.stub!(:new).and_return(success) EventMachine.run{ - @handler.add_post_request(@message_urls,@message_body) - @handler.size.should == 3 - @handler.add_get_request(@message_urls) - @handler.size.should == 6 - @handler.process + handler.add_post_request(message_urls, message_body) + handler.size.should == 3 + handler.add_get_request(message_urls) + handler.size.should == 6 + handler.process timer = EventMachine::Timer.new(1) do - @handler.size.should == 0 + handler.size.should == 0 EventMachine.stop end } end it 'should be able to have seperate POST and GET have different callbacks' do - request = FakeHttpRequest.new(:success) - request.should_receive(:get).exactly(1).times.and_return(request) - request.should_receive(:post).exactly(1).times.and_return(request) + success.should_receive(:get).exactly(1).times.and_return(success) + success.should_receive(:post).exactly(1).times.and_return(success) - EventMachine::HttpRequest.stub!(:new).and_return(request) + EventMachine::HttpRequest.stub!(:new).and_return(success) EventMachine.run{ - @handler.add_post_request(@message_urls.first,@message_body) - @handler.add_get_request(@message_urls.first) - @handler.process + handler.add_post_request(message_urls.first, message_body) + handler.add_get_request(message_urls.first) + handler.process EventMachine.stop } @@ -162,4 +160,3 @@ describe MessageHandler do end end end - diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 1edd73993..5ec769da8 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -25,14 +25,6 @@ describe Diaspora::UserModules::Friending do Notifier.stub!(:request_accepted).and_return(deliverable) end - before :all do - User.any_instance.stubs(:push_to_people) - end - - after :all do - unstub_mocha_stubs - end - describe '#contact_for' do it 'returns a contact' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 37bde3f92..0c582b65f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,9 @@ RSpec.configure do |config| DatabaseCleaner.orm = "mongo_mapper" config.before(:each) do - MessageHandler.any_instance.stubs(:add_post_request) + EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success)) + EventMachine::HttpRequest.any_instance.stubs(:post) + EventMachine::HttpRequest.any_instance.stubs(:get) DatabaseCleaner.clean UserFixer.load_user_fixtures end @@ -51,10 +53,18 @@ class FakeHttpRequest @callbacks.pop unless @callbacks.nil? || @callbacks.empty? end + def response_header + self + end + + def method_missing(method) + self + end + def post(opts = nil); self end - + def get(opts = nil) self end |