Skip to content

Require outer script reference in Mock._init to remove class name dependency - #11

Open
ChrisCrossCrash wants to merge 1 commit into
mainfrom
mock-class_name-simplification
Open

Require outer script reference in Mock._init to remove class name dependency#11
ChrisCrossCrash wants to merge 1 commit into
mainfrom
mock-class_name-simplification

Conversation

@ChrisCrossCrash

Copy link
Copy Markdown
Owner

Summary

Mock.install() and Mock.uninstall() previously referenced the C3Http identifier directly. This breaks when class_name C3Http is commented out to avoid global scope pollution — a common pattern for addon authors who want to prevent the class from appearing in every project that includes the addon.

Mock now accepts the outer GDScript reference in _init and stores it, so install/uninstall use _outer._impl instead of C3Http._impl. With this change, commenting out class_name C3Http in the addon file requires no further changes to the file.

Breaking change: Mock.new()Mock.new(C3Http). All internal call sites are updated.

Usage

When class_name C3Http is active (the default):

mock = C3Http.Mock.new(C3Http)
mock.install()

When class_name C3Http is commented out, load the script into a local constant and pass it through:

const C3Http := preload("res://addons/c3-http-request/c3_http_request/c3_http_request.gd")

mock = C3Http.Mock.new(C3Http)
mock.install()

install() and uninstall() remain argument-free — the reference is captured once at construction.

Test plan

  • All 286 GUT tests pass (godot --headless --path . -s addons/gut/gut_cmdln.gd -gdir=res://tests -ginclude_subdirs -gexit)
  • Manually verify that commenting out class_name C3Http and using the preload pattern produces no GDScript errors

Mock.install() and Mock.uninstall() previously referenced the C3Http identifier directly, which breaks when class_name C3Http is commented out to avoid global scope pollution (a common addon pattern). Mock now accepts the outer GDScript reference in _init and stores it, so install/uninstall use _outer._impl instead. Commenting out class_name C3Http in the addon file requires no further changes to the file. Call sites update from Mock.new() to Mock.new(C3Http). Docs and tests updated to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant