Module: Checkend::Testing
- Defined in:
- lib/checkend/testing.rb
Overview
Testing utilities for Checkend SDK.
Use this module in your test suite to capture and inspect notices without actually sending them to the server.
Defined Under Namespace
Classes: FakeClient
Class Method Summary collapse
-
.clear_notices! ⇒ void
Clear all captured notices.
-
.first_notice ⇒ Notice?
Get the first captured notice.
-
.last_notice ⇒ Notice?
Get the last captured notice.
-
.notice_count ⇒ Integer
Get the number of captured notices.
-
.notices ⇒ Array<Notice>
Get all captured notices.
-
.notices? ⇒ Boolean
Check if any notices were captured.
-
.setup! ⇒ void
Set up test mode - disables async sending and captures notices.
-
.teardown! ⇒ void
Tear down test mode - restores original configuration.
Class Method Details
.clear_notices! ⇒ void
This method returns an undefined value.
Clear all captured notices
112 113 114 |
# File 'lib/checkend/testing.rb', line 112 def clear_notices! @fake_client&.clear! end |
.first_notice ⇒ Notice?
Get the first captured notice
105 106 107 |
# File 'lib/checkend/testing.rb', line 105 def first_notice notices.first end |
.last_notice ⇒ Notice?
Get the last captured notice
98 99 100 |
# File 'lib/checkend/testing.rb', line 98 def last_notice notices.last end |
.notice_count ⇒ Integer
Get the number of captured notices
126 127 128 |
# File 'lib/checkend/testing.rb', line 126 def notice_count notices.size end |
.notices ⇒ Array<Notice>
Get all captured notices
89 90 91 92 93 |
# File 'lib/checkend/testing.rb', line 89 def notices return [] unless @fake_client @fake_client.notices end |
.notices? ⇒ Boolean
Check if any notices were captured
119 120 121 |
# File 'lib/checkend/testing.rb', line 119 def notices? !notices.empty? end |
.setup! ⇒ void
This method returns an undefined value.
Set up test mode - disables async sending and captures notices
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/checkend/testing.rb', line 48 def setup! @original_async = Checkend.configuration.async @original_client = Checkend.instance_variable_get(:@client) # Disable async to make tests deterministic Checkend.configuration.async = false # Replace client with fake client @fake_client = FakeClient.new Checkend.instance_variable_set(:@client, @fake_client) # Ensure SDK is started Checkend.instance_variable_set(:@started, true) # Clear any existing context Checkend.clear! end |
.teardown! ⇒ void
This method returns an undefined value.
Tear down test mode - restores original configuration
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/checkend/testing.rb', line 69 def teardown! # Restore original settings Checkend.configuration.async = @original_async if defined?(@original_async) Checkend.instance_variable_set(:@client, @original_client) if defined?(@original_client) # Clear captured notices clear_notices! # Clear context Checkend.clear! # Remove instance variables remove_instance_variable(:@original_async) if defined?(@original_async) remove_instance_variable(:@original_client) if defined?(@original_client) remove_instance_variable(:@fake_client) if defined?(@fake_client) end |