Extract common create and close context code

Before:

    context = Context.new
    ...
    context.close

After:

    create_context do |context|
      ...
    end