Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:12+00:00 2026-06-03T07:23:12+00:00

This below app saves some data to the db and I want to test

  • 0

This below app saves some data to the db and I want to test that it saves properly.

require 'goliath'

class App < Goliath::API
  def response(env)
     db = EM::Mongo::Connection.new('localhost').db('hello')
     db.collection('coll').insert({'identifier => 1'})

    [204, {}, {}]
  end
end

require 'goliath/test_helper'    
Goliath.env = :test

describe App do
  include Goliath::TestHelper

  it do
    with_api(described_class) do
      get_request do |req|
        db = EM::Mongo::Connection.new('localhost').db('hello')
        db.collection('coll').first.callback do |rec|
          rec['identifier'].should == 100
        end
      end
    end
  end
end

The above spec passes since reactor ends before callback returns. I thought about manually starting a reactor like:

EM.run do
  db = EM::Mongo::Connection.new('localhost').db('hello')
  db.collection('coll').first.callback do |rec|
    rec['identifier'].should == 100

    EM.stop
  end
end

Though I’m not sure if starting the reactor for every spec is good practice. Help please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:23:14+00:00Added an answer on June 3, 2026 at 7:23 am

    The problem is that when the get_request is setup we add a callback on the request that stops the event loop. So, as soon as your block finishes (which will be before the connection is even created), it will stop the reactor.

    I’m not sure the best solution, but a crappy one would be to override:

    def hookup_request_callbacks(req, errback, &blk)
      req.callback &blk
      req.callback { stop }
    
      req.errback &errback if errback
      req.errback { stop }
    end
    

    in your test class after you include Goliath::TestHelper. Then, I think, you should be able to write your own that just has something like:

    def hookup_request_callbacks(req, errback, &blk)
      req.callback &blk
    
      req.errback &errback if errback
      req.errback { stop }
    end
    

    You’ll just have to make sure you call stop in your callback from Mongo.

    I haven’t actually tested this, so let me know if something doesn’t work and I can dig in further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to capture the access_token returned by this url(below) https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_REDIRECT_URI&client_secret=YOUR_APP_SECRET&code=CODE_GENERATED_BY_FACEBOOK But if I
I use the line below in my C# winform app, this works great but
I have a code like this below, which gives me a $link that equals
I have a large number of csv files that look like this below: xxxxxxxx
I have an Android app that saves a text file directly onto the phone,
I have an app that takes a screenshot and the shares this with the
i have a single powerpoint slide that we use for reporting. This slidehas some
Introduction I have a app that has multiple tables, some with and some without
I am porting some of our app from c# to java. Some data objects
I have an MVC/Nhibernate app that is giving me the below. [WrongClassException: Object with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.