Skip to content

Commit 75ebbf4

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 75ebbf4

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

clients/ruby/test/integration_test.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ 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+
ENV['VIZZLY_TOKEN'] && !ENV['VIZZLY_TOKEN'].empty?
60+
end
61+
62+
# Assert that a screenshot result indicates success
63+
# In TDD mode: expects 'new' or 'match' status
64+
# In cloud mode: expects 'success' to be true
65+
def assert_screenshot_success(result)
66+
if cloud_mode?
67+
assert result['success'], "Expected success to be true in cloud mode, got: #{result.inspect}"
68+
else
69+
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
70+
end
71+
end
72+
5473
# Create a minimal valid PNG (1x1 red pixel)
5574
def create_test_png
5675
[
@@ -118,7 +137,7 @@ def test_basic_screenshot
118137
result = Vizzly.screenshot('basic-screenshot', image_data)
119138

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

124143
def test_screenshot_with_properties
@@ -133,7 +152,7 @@ def test_screenshot_with_properties
133152
})
134153

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

139158
def test_screenshot_with_threshold
@@ -143,7 +162,7 @@ def test_screenshot_with_threshold
143162
result = Vizzly.screenshot('screenshot-threshold', image_data, threshold: 5)
144163

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

149168
def test_screenshot_with_full_page
@@ -153,7 +172,7 @@ def test_screenshot_with_full_page
153172
result = Vizzly.screenshot('screenshot-fullpage', image_data, full_page: true)
154173

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

159178
def test_screenshot_with_all_options
@@ -170,7 +189,7 @@ def test_screenshot_with_all_options
170189
full_page: false)
171190

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

176195
# ===========================================================================
@@ -195,7 +214,7 @@ def test_auto_discovery_via_server_json
195214
result = client.screenshot('auto-discovered', image_data)
196215

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

201220
# ===========================================================================

0 commit comments

Comments
 (0)