1

I am trying to run multiple tests in parallel and I need to obtain independent responses for each request made through MockServer.

I am using the gem https://github.com/jamesdbloom/mockserver-client-ruby for the following request:

def mock_successful_transaction_request(successful = true)
    client = initialize_mock
    expectation = expectation do |e|
      e.request do |request|
        request.method = 'POST'
        request.path = '/transactions'
        request.cookies << cookie('sessionId', SecureRandom.hex)
      end

      dummy_response = mock_tb_response(successful)

      e.response do |response|
        response.status_code = 201
        response.body = dummy_response.to_json
      end
    end

    # puts expectation.to_yaml
    client.register(expectation)
 end

def initialize_mock
    client = MockServerClient.new(MOCK_SERVER[:host], MOCK_SERVER[:port])
    client.logger = Logger.new("mockserver_logs.log")
    client
  end

def mock_tb_response(successful)
    tb_id = Faker::Number.between(1, 1_000_000)
    successful ? { id: tb_id, v: '2.0.0' } : {}
  end

When I add the request.cookies << cookie("sessionId", SecureRandom.hex) part, I can't seem to get a response and my request fails with HTTP 500. If I remove it, the response comes as expected.

What am I doing wrong?

Thank you.

1 Answers1

0

Try: request.cookies[:sessionId] = cookie('sessionId', SecureRandom.hex)

Or: request.cookies[:sessionId] = SecureRandom.hex

UPDATE

Try:

request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]

If this works try replacing '2By8LOhBmaW5nZXJwcmludCIlMDAzMW' with SecureRandom.hex

  • This does not help. Request don't get finalized, but receive only 500 even with what you suggested @JollyProgrammer – Adela Tuduce Mar 28 '18 at 14:31