Skip to content

Commit

Permalink
Merge pull request #1112 from Shopify/show-full-result-when-output-do…
Browse files Browse the repository at this point in the history
…esnt-match

Show full result when failing to match output in tests
  • Loading branch information
dirceu authored Aug 15, 2022
2 parents 55fdade + f447eb2 commit 16c8c74
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 82 deletions.
10 changes: 10 additions & 0 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ def refute_success_status(result)
refute(result.status)
end

sig { params(result: MockProject::ExecResult, snippet: String).void }
def assert_stdout_includes(result, snippet)
assert_includes(result.out, snippet, result.to_s)
end

sig { params(result: MockProject::ExecResult, snippet: String).void }
def assert_stderr_includes(result, snippet)
assert_includes(result.err, snippet, result.to_s)
end

private

sig { returns(String) }
Expand Down
32 changes: 16 additions & 16 deletions spec/tapioca/cli/annotations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class AnnotationsTest < SpecWithProject

result = @project.tapioca("annotations --sources #{repo.path}")

assert_includes(result.out, "remove sorbet/rbi/annotations/bar.rbi")
assert_includes(result.out, "remove sorbet/rbi/annotations/foo.rbi")
assert_stdout_includes(result, "remove sorbet/rbi/annotations/bar.rbi")
assert_stdout_includes(result, "remove sorbet/rbi/annotations/foo.rbi")
refute_includes(result.out, "remove sorbet/rbi/annotations/rbi.rbi")

assert_success_status(result)
Expand Down Expand Up @@ -70,8 +70,8 @@ class AnnotationForFoo; end

result = @project.tapioca("annotations --sources #{repo.path}")

assert_includes(result.out, "create sorbet/rbi/annotations/rbi.rbi")
assert_includes(result.out, "create sorbet/rbi/annotations/spoom.rbi")
assert_stdout_includes(result, "create sorbet/rbi/annotations/rbi.rbi")
assert_stdout_includes(result, "create sorbet/rbi/annotations/spoom.rbi")
refute_includes(result.out, "create sorbet/rbi/annotations/foo.rbi")

assert_project_annotation_equal("sorbet/rbi/annotations/rbi.rbi", <<~RBI)
Expand Down Expand Up @@ -103,16 +103,16 @@ class AnnotationForSpoom; end
it "gets index from the central repo using the default source" do
result = @project.tapioca("annotations")

assert_includes(result.out, "Retrieving index from central repository... Done")
assert_stdout_includes(result, "Retrieving index from central repository... Done")
assert_success_status(result)
end

it "recovers from a bad source" do
result = @project.tapioca("annotations --sources #{Tapioca::CENTRAL_REPO_ROOT_URI} https://bad-source")

assert_includes(result.out, "Retrieving index from central repository #1... Done")
assert_includes(result.err, "Can't fetch file `index.json` from https://bad-source")
assert_includes(result.err, <<~ERROR)
assert_stdout_includes(result, "Retrieving index from central repository #1... Done")
assert_stderr_includes(result, "Can't fetch file `index.json` from https://bad-source")
assert_stderr_includes(result, <<~ERROR)
Tapioca can't access the annotations at https://bad-source.
Are you trying to access a private repository?
Expand All @@ -126,8 +126,8 @@ class AnnotationForSpoom; end
it "errors without a valid source" do
result = @project.tapioca("annotations --sources https://bad-source")

assert_includes(result.err, "Can't fetch file `index.json` from https://bad-source")
assert_includes(result.err, "Can't fetch annotations without sources (no index fetched)")
assert_stderr_includes(result, "Can't fetch file `index.json` from https://bad-source")
assert_stderr_includes(result, "Can't fetch annotations without sources (no index fetched)")
refute_success_status(result)
end

Expand All @@ -142,7 +142,7 @@ class AnnotationForSpoom

result = @project.tapioca("annotations --sources #{repo.path}")

assert_includes(result.err, <<~ERR)
assert_stderr_includes(result, <<~ERR)
Can't import RBI file for `spoom` as it contains errors:
Error: unexpected token $end (-:4:0-4:0)
ERR
Expand Down Expand Up @@ -172,8 +172,8 @@ class AnnotationForSpoom; end

result = @project.tapioca("annotations --sources #{repo1.path} #{repo2.path}")

assert_includes(result.out, "create sorbet/rbi/annotations/rbi.rbi")
assert_includes(result.out, "create sorbet/rbi/annotations/spoom.rbi")
assert_stdout_includes(result, "create sorbet/rbi/annotations/rbi.rbi")
assert_stdout_includes(result, "create sorbet/rbi/annotations/spoom.rbi")

assert_project_annotation_equal("sorbet/rbi/annotations/rbi.rbi", <<~RBI)
# typed: true
Expand Down Expand Up @@ -226,7 +226,7 @@ def baz; end

result = @project.tapioca("annotations --sources #{repo1.path} #{repo2.path}")

assert_includes(result.out, "create sorbet/rbi/annotations/rbi.rbi")
assert_stdout_includes(result, "create sorbet/rbi/annotations/rbi.rbi")

assert_project_annotation_equal("sorbet/rbi/annotations/rbi.rbi", <<~RBI)
# typed: true
Expand Down Expand Up @@ -275,7 +275,7 @@ def baz; end

result = @project.tapioca("annotations --sources #{repo1.path} #{repo2.path}")

assert_includes(result.err, <<~ERR)
assert_stderr_includes(result, <<~ERR)
Can't import RBI file for `spoom` as it contains conflicts:
Conflicting definitions for `::AnnotationForSpoom#foo(x, y)`
Conflicting definitions for `::AnnotationForSpoom#bar()`
Expand All @@ -291,7 +291,7 @@ def baz; end
it "errors if passing both --no-netrc and --netrc-file" do
result = @project.tapioca("annotations --no-netrc --netrc-file some_file")

assert_includes(result.err, <<~ERR)
assert_stderr_includes(result, <<~ERR)
Options `--no-netrc` and `--netrc-file` can't be used together
ERR

Expand Down
20 changes: 10 additions & 10 deletions spec/tapioca/cli/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ConfigureSpec < SpecWithProject
it "must create proper files" do
result = @project.tapioca("configure")

assert_includes(result.out, "create sorbet/config")
assert_includes(result.out, "create sorbet/tapioca/config.yml")
assert_includes(result.out, "create sorbet/tapioca/require.rb")
assert_includes(result.out, "create bin/tapioca")
assert_stdout_includes(result, "create sorbet/config")
assert_stdout_includes(result, "create sorbet/tapioca/config.yml")
assert_stdout_includes(result, "create sorbet/tapioca/require.rb")
assert_stdout_includes(result, "create bin/tapioca")

assert_equal(<<~CONFIG, @project.read("sorbet/config"))
--dir
Expand Down Expand Up @@ -57,10 +57,10 @@ class ConfigureSpec < SpecWithProject

result = @project.tapioca("configure")

assert_includes(result.out, "skip sorbet/config")
assert_includes(result.out, "skip sorbet/tapioca/config.yml")
assert_includes(result.out, "skip sorbet/tapioca/require.rb")
assert_includes(result.out, "force bin/tapioca")
assert_stdout_includes(result, "skip sorbet/config")
assert_stdout_includes(result, "skip sorbet/tapioca/config.yml")
assert_stdout_includes(result, "skip sorbet/tapioca/require.rb")
assert_stdout_includes(result, "force bin/tapioca")

assert_empty(@project.read("sorbet/config"))
assert_empty(@project.read("sorbet/tapioca/require.rb"))
Expand All @@ -71,15 +71,15 @@ class ConfigureSpec < SpecWithProject

it "creates the Tapioca config file in a custom location" do
result = @project.tapioca("configure --config sorbet/tapioca/custom_config.yml")
assert_includes(result.out, "create sorbet/tapioca/custom_config.yml")
assert_stdout_includes(result, "create sorbet/tapioca/custom_config.yml")
assert_project_file_exist("sorbet/tapioca/custom_config.yml")
assert_empty_stderr(result)
assert_success_status(result)
end

it "creates the Tapioca post-require file in a custom location" do
result = @project.tapioca("configure --postrequire sorbet/tapioca/custom_require.rb")
assert_includes(result.out, "create sorbet/tapioca/custom_require.rb")
assert_stdout_includes(result, "create sorbet/tapioca/custom_require.rb")
assert_project_file_exist("sorbet/tapioca/custom_require.rb")
assert_empty_stderr(result)
assert_success_status(result)
Expand Down
8 changes: 4 additions & 4 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@ def self.gather_constants
OUT

assert_includes(result.err, "Error: `PostCompilerThatRaises` failed to generate RBI for `Post`")
assert_includes(result.err, "Some unexpected error happened")
assert_stderr_includes(result, "Error: `PostCompilerThatRaises` failed to generate RBI for `Post`")
assert_stderr_includes(result, "Some unexpected error happened")

refute_project_file_exist("sorbet/rbi/dsl/post.rbi")
refute_success_status(result)
Expand Down Expand Up @@ -1313,7 +1313,7 @@ def perform(foo, bar)
@project.tapioca("dsl")
result = @project.tapioca("dsl --verify")

assert_includes(result.out, <<~OUT)
assert_stdout_includes(result, <<~OUT)
Nothing to do, all RBIs are up-to-date.
OUT

Expand Down Expand Up @@ -1463,7 +1463,7 @@ class Post

result = @project.tapioca("dsl Post")

assert_includes(result.out, <<~OUT)
assert_stdout_includes(result, <<~OUT)
Checking generated RBI files... Done
Changed strictness of sorbet/rbi/gems/bar@1.0.0.rbi to `typed: false` (conflicting with DSL files)
Expand Down
Loading

0 comments on commit 16c8c74

Please sign in to comment.