diff --git a/spec/lib/puma/appsignal_spec.rb b/spec/lib/puma/appsignal_spec.rb
index <HASH>..<HASH> 100644
--- a/spec/lib/puma/appsignal_spec.rb
+++ b/spec/lib/puma/appsignal_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe "Puma plugin" do
     end
 
     def stop
-      @socket && @socket.close
+      defined?(@socket) && @socket && @socket.close
     ensure
       @socket = nil
     end
Fix undefined variable warning in spec

The specs would print the warning below. Fix this by checking if it's
defined rather than if it has a truthy value before calling the `close`
method on it.

```
/spec/lib/puma/appsignal_spec.rb:<I>: warning: instance variable @socket not initialized
```