I'm having a really weird issue trying to write a test around a rails controller.
The controller uses `RestClient` to get info from another server. If that 2nd server returns a bad response, I want to forward on that error message to the client.

The controller:

```
def callback_submit
  begin
    response = RestClient.post(...)
    render json: response
  rescue RestClient::BadRequest => e
    render status: :bad_request, json: { error: e.response.body }
  end
end

```

Then I have an rspec test for this:

```
  it 'returns a failure message' do
    stub_request( :post, 'http://...' ).to_return( status: 400, body: 'some error' )

    post :callback_submit

    expect(response.body).to eq({error: 'some error'}.to_json)
  end

```

---

Now the problem is that the rspec output is:

```
   expected: "{\"error\":\"some error\"}"
        got: "{\"error\":\"\"}"

```

---

Where it gets weird is that I can change my controller to `puts` some details...

```
  rescue RestClient::BadRequest => e
    error = e.response.body.to_s
    puts error.class
    puts error
    render status: :bad_request, json: { error: error }

```

Which outputs:

```
String
some error

   expected: "{\"error\":\"some error\"}"
        got: "{\"error\":\"\"}"

```

So the `error` variable seems to be a string and the correct value, but `render` turns it into an empty string.

---

Now it gets really weird... If I interpolate the string:

```
  rescue RestClient::BadRequest => e
    error = e.response.body.to_s
    puts error.class
    puts error
    render status: :bad_request, json: { error: "#{error}" }

```

Or just simply:

```
  rescue RestClient::BadRequest => e
    render status: :bad_request, json: { error: "#{e.response.body}" }

```

Then my test PASSES!

---

At first I thought `e.response.body` must not be a String, which is why I `puts` its `class` which prints "String" and also called `.to_s` on it, but that didn't seem to change anything.

Can anyone explain this weird behavior?