From f0e182a0e24bcc6b769619b70ea612e9a1315701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 25 Mar 2022 15:25:37 +0100 Subject: [PATCH] Fix assertions that fail on whitespace mismatch --- features/api.feature | 8 ++--- features/apply.feature | 1 - features/authentication.feature | 2 +- features/compare.feature | 4 +-- features/gist.feature | 14 ++++---- features/pr-list.feature | 1 + features/pr-show.feature | 4 +-- features/pull_request.feature | 2 +- features/release.feature | 2 +- features/support/rspec_matchers.rb | 53 ++++++++++++++++++++++++++++++ 10 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 features/support/rspec_matchers.rb diff --git a/features/api.feature b/features/api.feature index 362d2f9d..d947c2f0 100644 --- a/features/api.feature +++ b/features/api.feature @@ -231,7 +231,7 @@ Feature: hub api """ Then the output should contain exactly: """ - .query query {\n repository\n}\n + .query query {\\n repository\\n}\\n\n """ Scenario: POST body from file @@ -340,7 +340,7 @@ Feature: hub api """ Then the output should contain exactly: """ - .query repository(owner: "octocat", name: "Hello-World", nameWithOwner: "octocat/Hello-World")\n + .query repository(owner: "octocat", name: "Hello-World", nameWithOwner: "octocat/Hello-World")\\n\n """ Scenario: Cache response @@ -508,7 +508,7 @@ Feature: hub api """ {} Your access token may have insufficient scopes. Visit http://github.com/settings/tokens - to edit the 'hub' token and enable one of the following scopes: admin, repo + to edit the 'hub' token and enable one of the following scopes: admin, repo\n """ Scenario: Print the SSO challenge to stderr @@ -526,5 +526,5 @@ Feature: hub api """ You must authorize your token to access this organization: - http://example.com?auth=HASH + http://example.com?auth=HASH\n """ diff --git a/features/apply.feature b/features/apply.feature index c189641f..03ae0288 100644 --- a/features/apply.feature +++ b/features/apply.feature @@ -18,7 +18,6 @@ Feature: hub apply } """ When I successfully run `hub apply -3 https://github.com/mislav/dotfiles/pull/387` - Then the output should not contain anything Then a file named "README.md" should exist Scenario: Apply commits when TMPDIR is empty diff --git a/features/authentication.feature b/features/authentication.feature index 77dbc07d..a80f9440 100644 --- a/features/authentication.feature +++ b/features/authentication.feature @@ -536,5 +536,5 @@ Feature: OAuth authentication """ Error fetching releases: Forbidden (HTTP 403) You must authorize your token to access this organization: - http://example.com?auth=HASH + http://example.com?auth=HASH\n """ diff --git a/features/compare.feature b/features/compare.feature index 63c94574..cef62369 100644 --- a/features/compare.feature +++ b/features/compare.feature @@ -21,14 +21,14 @@ Feature: hub compare Scenario: No args, no upstream When I run `hub compare` Then the exit status should be 1 - And the stderr should contain exactly "the current branch 'master' doesn't seem pushed to a remote" + And the stderr should contain exactly "the current branch 'master' doesn't seem pushed to a remote\n" Scenario: Can't compare default branch to self Given the default branch for "origin" is "develop" And I am on the "develop" branch with upstream "origin/develop" When I run `hub compare` Then the exit status should be 1 - And the stderr should contain exactly "the branch to compare 'develop' is the default branch" + And the stderr should contain exactly "the branch to compare 'develop' is the default branch\n" Scenario: No args, has upstream branch Given I am on the "feature" branch with upstream "origin/experimental" diff --git a/features/gist.feature b/features/gist.feature index 8e33ab35..e2224d27 100644 --- a/features/gist.feature +++ b/features/gist.feature @@ -19,7 +19,7 @@ Feature: hub gist When I successfully run `hub gist show myhash` Then the output should contain exactly: """ - my content is here + my content is here\n """ Scenario: Fetch a gist with many files @@ -70,7 +70,7 @@ Feature: hub gist When I successfully run `hub gist show myhash hub_gist1.txt` Then the output should contain exactly: """ - my content is here + my content is here\n """ Scenario: Create a gist from file @@ -88,7 +88,7 @@ Feature: hub gist When I successfully run `hub gist create testfile.txt` Then the output should contain exactly: """ - http://gists.github.com/somehash + http://gists.github.com/somehash\n """ Scenario: Open the new gist in a browser @@ -130,7 +130,7 @@ Feature: hub gist When I successfully run `hub gist create testfile.txt testfile2.txt` Then the output should contain exactly: """ - http://gists.github.com/somehash + http://gists.github.com/somehash\n """ Scenario: Create a gist from stdin @@ -149,7 +149,7 @@ Feature: hub gist """ Then the output should contain exactly: """ - http://gists.github.com/somehash + http://gists.github.com/somehash\n """ Scenario: Insufficient OAuth scopes @@ -172,7 +172,7 @@ Feature: hub gist """ Error creating gist: Not Found (HTTP 404) Your access token may have insufficient scopes. Visit http://github.com/settings/tokens - to edit the 'hub' token and enable one of the following scopes: gist + to edit the 'hub' token and enable one of the following scopes: gist\n """ Scenario: Infer correct OAuth scopes for gist @@ -194,7 +194,7 @@ Feature: hub gist """ Error creating gist: Not Found (HTTP 404) Your access token may have insufficient scopes. Visit http://github.com/settings/tokens - to edit the 'hub' token and enable one of the following scopes: gist + to edit the 'hub' token and enable one of the following scopes: gist\n """ Scenario: Create error diff --git a/features/pr-list.feature b/features/pr-list.feature index 3b67d90a..64369496 100644 --- a/features/pr-list.feature +++ b/features/pr-list.feature @@ -112,6 +112,7 @@ Feature: hub pr list #102 luke, jyn\n """ + @keep-ansi-escape-sequences Scenario: List draft status Given the GitHub API server: """ diff --git a/features/pr-show.feature b/features/pr-show.feature index f62d1e33..94da85ba 100644 --- a/features/pr-show.feature +++ b/features/pr-show.feature @@ -69,7 +69,7 @@ Feature: hub pr show Then "open https://github.com/ashemesh/hub/pull/102" should not be run And the output should contain exactly: """ - #102 rey, github/troopers, github/cantina-band\n + #102 rey, github/troopers, github/cantina-band\n\n """ Scenario: Current branch in fork @@ -208,7 +208,7 @@ Feature: hub pr show Then "open https://github.com/ashemesh/hub/pull/102" should not be run And the output should contain exactly: """ - #102 rey, github/troopers, github/cantina-band\n + #102 rey, github/troopers, github/cantina-band\n\n """ Scenario: Show pull request by invalid number diff --git a/features/pull_request.feature b/features/pull_request.feature index b53120fd..fea1fc75 100644 --- a/features/pull_request.feature +++ b/features/pull_request.feature @@ -1241,7 +1241,7 @@ Feature: hub pull-request And stderr should contain exactly: """ Error creating pull request: Post https://api.github.com/repositories/12345/pulls: refusing to follow HTTP 301 redirect for a POST request - Have your site admin use HTTP 308 for this kind of redirect + Have your site admin use HTTP 308 for this kind of redirect\n """ Scenario: Default message with --push diff --git a/features/release.feature b/features/release.feature index aaee0830..360ab693 100644 --- a/features/release.feature +++ b/features/release.feature @@ -359,7 +359,7 @@ MARKDOWN ### Hello to my release Here is what's broken: - - everything\n + - everything\n\n """ Scenario: Show release no tag diff --git a/features/support/rspec_matchers.rb b/features/support/rspec_matchers.rb new file mode 100644 index 00000000..a4ced9a0 --- /dev/null +++ b/features/support/rspec_matchers.rb @@ -0,0 +1,53 @@ +# Avoids over-zealous sanitize_text +# https://github.com/cucumber/aruba/blob/v1.0.4/lib/aruba/matchers/string/output_string_eq.rb + +sanitize_text = ->(expected) { + expected.to_s. + # convert "\n" in expectations to literal newline, unless it is preceded by another backslash + gsub(/(?