Skip to content

Commit c8b8462

Browse files
committed
🐛 Fix Ruby SDK E2E tests for both TDD and cloud modes
- Add cloud_mode? helper to detect when running with VIZZLY_TOKEN - Add assert_screenshot_success helper for mode-aware assertions - TDD mode: asserts status is 'new' or 'match' - Cloud mode: asserts success is true (no local comparison)
1 parent e30998d commit c8b8462

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

clients/ruby/test/integration_test.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ def stop_server
5151
@server_pid = nil
5252
end
5353

54+
# Check if running in cloud mode (vizzly run) vs TDD mode (vizzly tdd run)
55+
# Cloud mode returns { success: true } without a status field
56+
# TDD mode returns comparison results with status field
57+
def cloud_mode?
58+
# In cloud mode, VIZZLY_TOKEN is typically set
59+
token = ENV.fetch('VIZZLY_TOKEN', nil)
60+
token && !token.empty?
61+
end
62+
63+
# Assert that a screenshot result indicates success
64+
# In TDD mode: expects 'new' or 'match' status
65+
# In cloud mode: expects 'success' to be true
66+
def assert_screenshot_success(result)
67+
if cloud_mode?
68+
assert result['success'], "Expected success to be true in cloud mode, got: #{result.inspect}"
69+
else
70+
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
71+
end
72+
end
73+
5474
# Create a minimal valid PNG (1x1 red pixel)
5575
def create_test_png
5676
[
@@ -118,7 +138,7 @@ def test_basic_screenshot
118138
result = Vizzly.screenshot('basic-screenshot', image_data)
119139

120140
assert result, 'Expected result to be non-nil'
121-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
141+
assert_screenshot_success(result)
122142
end
123143

124144
def test_screenshot_with_properties
@@ -133,7 +153,7 @@ def test_screenshot_with_properties
133153
})
134154

135155
assert result, 'Expected result to be non-nil'
136-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
156+
assert_screenshot_success(result)
137157
end
138158

139159
def test_screenshot_with_threshold
@@ -143,7 +163,7 @@ def test_screenshot_with_threshold
143163
result = Vizzly.screenshot('screenshot-threshold', image_data, threshold: 5)
144164

145165
assert result, 'Expected result to be non-nil'
146-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
166+
assert_screenshot_success(result)
147167
end
148168

149169
def test_screenshot_with_full_page
@@ -153,7 +173,7 @@ def test_screenshot_with_full_page
153173
result = Vizzly.screenshot('screenshot-fullpage', image_data, full_page: true)
154174

155175
assert result, 'Expected result to be non-nil'
156-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
176+
assert_screenshot_success(result)
157177
end
158178

159179
def test_screenshot_with_all_options
@@ -170,7 +190,7 @@ def test_screenshot_with_all_options
170190
full_page: false)
171191

172192
assert result, 'Expected result to be non-nil'
173-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
193+
assert_screenshot_success(result)
174194
end
175195

176196
# ===========================================================================
@@ -195,7 +215,7 @@ def test_auto_discovery_via_server_json
195215
result = client.screenshot('auto-discovered', image_data)
196216

197217
assert result, 'Expected result to be non-nil'
198-
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
218+
assert_screenshot_success(result)
199219
end
200220

201221
# ===========================================================================

0 commit comments

Comments
 (0)