intridea/grape — pull request #667 by mattsnyder (2014-06-30 14:46:54+00:00)
Title: Added spec demonstrating issue #665 (References not getting garbage collected)

This PR contains failing specs that demonstrate scenarios when references `Grape::Endpoint` are not collected when running the tests. In writing these specs I noticed that adding a second call to a spec that produces a 404 seems to clear out the bad reference. A second call in the same spec that produces a 200 does not.

Also note that in each scenario references to `Regexp` were either getting collected or not.

```
Failures:

1) Grape::API when performing a single call against the endpoint is adding an uncollectable reference to Grape::Endpoint
Failure/Error: expect(post_test_counts).to eql pre_test_counts

expected: {"Grape::Endpoint"=>48, "Grape::Util::HashStack"=>64, "Regexp"=>2164}
got: {"Grape::Endpoint"=>49, "Grape::Util::HashStack"=>64, "Regexp"=>2166}

(compared using eql?)

Diff:

@@ -1,4 +1,4 @@
-"Grape::Endpoint" => 48,
+"Grape::Endpoint" => 49,
"Grape::Util::HashStack" => 64,
-"Regexp" => 2164
+"Regexp" => 2166

# ./spec/grape/garabge_collection_spec.rb:53:in `block (3 levels) in '

2) Grape::API when performing multiple calls against the endpoint is dropping that extra reference to Grape::Endpoint
Failure/Error: expect(post_test_counts).to eql pre_test_counts

expected: {"Grape::Endpoint"=>48, "Grape::Util::HashStack"=>64, "Regexp"=>2166}
got: {"Grape::Endpoint"=>48, "Grape::Util::HashStack"=>64, "Regexp"=>2173}

(compared using eql?)

Diff:
@@ -1,4 +1,4 @@
"Grape::Endpoint" => 48,
"Grape::Util::HashStack" => 64,
-"Regexp" => 2166
+"Regexp" => 2173

# ./spec/grape/garabge_collection_spec.rb:70:in `block (3 levels) in '

3) Grape::API when performing multiple calls against the endpoint is not dropping that extra reference to Grape::Endpoint
Failure/Error: expect(post_test_counts).to eql pre_test_counts

expected: {"Grape::Endpoint"=>48, "Grape::Util::HashStack"=>64, "Regexp"=>2173}
got: {"Grape::Endpoint"=>49, "Grape::Util::HashStack"=>64, "Regexp"=>2173}

(compared using eql?)

Diff:
@@ -1,4 +1,4 @@
-"Grape::Endpoint" => 48,
+"Grape::Endpoint" => 49,
"Grape::Util::HashStack" => 64,
"Regexp" => 2173
# ./spec/grape/garabge_collection_spec.rb:85:in `block (3 levels) in '

Finished in 4.13 seconds
754 examples, 3 failures
```