Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie usage #4

Open
adelatuduce opened this issue Mar 21, 2018 · 0 comments
Open

Cookie usage #4

adelatuduce opened this issue Mar 21, 2018 · 0 comments

Comments

@adelatuduce
Copy link

adelatuduce commented Mar 21, 2018

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 with 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant