You need to tie the position of the shape layer to the position of the Text layer and compensate for paragraph styles by using sourceRectAtTime().left and baseline shift using soruceRectAtTime().top.
You also have to tie the Rectangle/Position to the size of the rectangle with an expression. Roland gave you the format for doing that with Anchor Point, but I prefer to keep it all in the Contents/Rectangle section of a shape layer.
This is how I do it. Because the text layer is always above the shape layer rectangle, I use (index - 1) instead of the text layer name, and I have a bunch of animation presets I saved, so I don't have to enter the expressions by hand. I have also added horizontal and vertical padding sliders and a roundness slider.
If you want to use a text animator to reveal the line or lines of text, you also need to add a time something like this: sourceRectAtTime(thisLayer.inPoint + .5) so that the size of the shape layer background is taken after the text has been revealed. You can also use the half-second (.5) if the text animates in from the left side.
I also always compensate for text layer scale. Here are the expressions:
// Rectangle/Size
src=thisComp.layer(index - 1);
ref = sRc.sourceRectAtTime();
refScale = sRc.scale * .01;
pad = 20; // ten pixel padding
x = ref.width + pad;
y = ref.height + pad;
[x * refScale[0], y * refScale[1]]
// Rectangle/Position Compensates for paragraph justification and baseline shift
src=thisComp.layer(index - 1);
box = src.sourceRectAtTime();
refScale = src.scale * .01;
x = box.width / 2;
y = box.height / 2;
t = box.top;
l = box.left;
[(x + l) * refScale[0], (y + t) * refScale[1]]
// Rectangle/Roundness - adds curved edges
src=thisComp.layer(index - 1);
maxR = sRc.sourceRectAtTime().height / 2;
rndRatio = .5;
rVal = maxR * rndRatio;
//Shape Layer/Transform/Position - ties the rectangle to the text layer.
src=thisComp.layer(index - 1);
sRc.position;
You can't really do what you are trying to do with just one expression. I always use at least 3. If there are text animators, you'll need to add a time value for sourceRectAtTime(thisLayer.inPoint + time in seconds)
This is a screenshot from an upcoming tutorial series I am working on showing all of the modified properties of the shape layer. I've added Offset Paths, sliders to control things, and even background and stroke color controls.

I hope this helps.