Rails CollectionProxy #length vs #count
When testing a controller, it's not unreasonable to right a test something like this:
expect(post_to_endpoint).to change { some.objects.length }.from(0).to(1)
Because of the details of CollectionProxy, this will not work as expected. Instead, you need to write:
expect(post_to_endpoint).to change { some.objects.count }.from(0).to(1)
The length
method will evaluate to the same value, while the count
method will reflect changes to the underlying data since the last call.