Skip to content

Commit a3fc4ce

Browse files
committed
Try to handle browser JSON responses more robustly
Sticking to Capybara's API for getting document text should (in theory) make this less likely to break in the event of a browser changing how it renders plain text/JSON responses.
1 parent 7fbd8da commit a3fc4ce

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

test/system/alpha/action_menu_test.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ def test_single_select_form_submission
404404

405405
find("input[type=submit]").click
406406

407-
# for some reason the JSON response is wrapped in HTML, I have no idea why
408-
response = JSON.parse(find("pre").text)
407+
response = JSON.parse(page.document.text)
409408
assert_equal "fast_forward", response["value"]
410409
end
411410

@@ -417,8 +416,7 @@ def test_single_select_form_uses_label_if_no_value_provided
417416

418417
find("input[type=submit]").click
419418

420-
# for some reason the JSON response is wrapped in HTML, I have no idea why
421-
response = JSON.parse(find("pre").text)
419+
response = JSON.parse(page.document.text)
422420
assert_equal "Resolve", response["value"]
423421
end
424422

@@ -434,8 +432,7 @@ def test_multiple_select_form_submission
434432

435433
find("input[type=submit]").click
436434

437-
# for some reason the JSON response is wrapped in HTML, I have no idea why
438-
response = JSON.parse(find("pre").text)
435+
response = JSON.parse(page.document.text)
439436

440437
# "ours" is pre-selected
441438
assert_equal %w[fast_forward recursive ours], response["value"]
@@ -453,8 +450,7 @@ def test_multiple_select_form_uses_label_if_no_value_provided
453450

454451
find("input[type=submit]").click
455452

456-
# for some reason the JSON response is wrapped in HTML, I have no idea why
457-
response = JSON.parse(find("pre").text)
453+
response = JSON.parse(page.document.text)
458454

459455
# "ours" is pre-selected
460456
assert_equal %w[fast_forward ours Resolve], response["value"]
@@ -471,7 +467,7 @@ def test_individual_items_can_submit_post_requests_via_forms
471467
click_on_invoker_button
472468
click_on_fourth_item
473469

474-
response = JSON.parse(find("pre").text)
470+
response = JSON.parse(page.document.text)
475471
assert_equal "bar", response["value"]
476472
end
477473

@@ -481,8 +477,7 @@ def test_single_select_items_can_submit_forms
481477
click_on_invoker_button
482478
click_on_first_item
483479

484-
# for some reason the JSON response is wrapped in HTML, I have no idea why
485-
response = JSON.parse(find("pre").text)
480+
response = JSON.parse(page.document.text)
486481
assert_equal "group-by-repository", response["value"]
487482
end
488483

@@ -494,8 +489,7 @@ def test_single_select_items_can_submit_forms_on_enter
494489
# "click" first item
495490
keyboard.type(:enter)
496491

497-
# for some reason the JSON response is wrapped in HTML, I have no idea why
498-
response = JSON.parse(find("pre").text)
492+
response = JSON.parse(page.document.text)
499493
assert_equal "group-by-repository", response["value"]
500494
end
501495

@@ -507,8 +501,7 @@ def test_single_select_items_can_submit_forms_on_keydown_space
507501
# "click" first item
508502
keyboard.type(:space)
509503

510-
# for some reason the JSON response is wrapped in HTML, I have no idea why
511-
response = JSON.parse(find("pre").text)
504+
response = JSON.parse(page.document.text)
512505
assert_equal "group-by-repository", response["value"]
513506
end
514507

@@ -518,8 +511,7 @@ def test_single_select_items_can_submit_forms_with_multiple_fields
518511
click_on_invoker_button
519512
click_on_first_item
520513

521-
# for some reason the JSON response is wrapped in HTML, I have no idea why
522-
response = JSON.parse(find("pre").text)
514+
response = JSON.parse(page.document.text)
523515
assert_equal "query", response.dig("other_params", "query")
524516
end
525517

test/system/alpha/select_panel_test.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,7 @@ def test_single_select_form
12211221

12221222
click_on "Submit"
12231223

1224-
# for some reason the JSON response is wrapped in HTML, I have no idea why
1225-
response = JSON.parse(find("pre").text)
1224+
response = JSON.parse(page.document.text)
12261225
assert_equal "item2", response.dig(*%w(form_params item))
12271226
end
12281227

@@ -1232,8 +1231,7 @@ def test_single_select_form_submits_pre_selected_item
12321231
# the first item has been pre-selected, so there's no need to select any items
12331232
click_on "Submit"
12341233

1235-
# for some reason the JSON response is wrapped in HTML, I have no idea why
1236-
response = JSON.parse(find("pre").text)
1234+
response = JSON.parse(page.document.text)
12371235
assert_equal "item1", response.dig(*%w(form_params item))
12381236
end
12391237

@@ -1246,8 +1244,7 @@ def test_multi_select_form
12461244

12471245
click_on "Submit"
12481246

1249-
# for some reason the JSON response is wrapped in HTML, I have no idea why
1250-
response = JSON.parse(find("pre").text)
1247+
response = JSON.parse(page.document.text)
12511248

12521249
# first item is pre-selected
12531250
assert_equal ["item1", "item2"], response.dig(*%w(form_params item))

0 commit comments

Comments
 (0)