From 805cae1c9b1c4ebf7239fb07cf7bf8b445683b7d Mon Sep 17 00:00:00 2001 From: Yoshiori SHOJI Date: Mon, 22 Mar 2021 14:45:45 +0900 Subject: [PATCH 1/4] add rspec plugin --- launchable/test_runners/rspec.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 launchable/test_runners/rspec.py diff --git a/launchable/test_runners/rspec.py b/launchable/test_runners/rspec.py new file mode 100644 index 000000000..b45f9e5a0 --- /dev/null +++ b/launchable/test_runners/rspec.py @@ -0,0 +1,35 @@ +import click +import os +import sys +from . import launchable + + +@click.argument('files', required=True, nargs=-1) +@launchable.subset +def subset(client, files): + def parse(fname: str): + ''' + Scan a file, directory full of *.rb, or @FILE + ''' + if os.path.isdir(fname): + client.scan(fname, '**/*_spec.rb') + elif fname == '@-': + # read stdin + for l in sys.stdin: + parse(l) + elif fname.startswith('@'): + # read response file + with open(fname[1:]) as f: + for l in f: + parse(l) + else: + # assume it's a file + client.test_path(fname) + + for f in files: + parse(f) + + client.run() + + +record_tests = launchable.CommonRecordTestImpls(__name__).report_files() From fcc22f105756ebe12b0625ddfd16d0589c4660b1 Mon Sep 17 00:00:00 2001 From: Yoshiori SHOJI Date: Mon, 22 Mar 2021 15:42:33 +0900 Subject: [PATCH 2/4] Add rspec plugin test --- tests/data/rspec/record_test_result.json | 372 +++++++++++++++++++++++ tests/data/rspec/rspec.xml | 22 ++ tests/test_runners/test_rspec.py | 20 ++ 3 files changed, 414 insertions(+) create mode 100644 tests/data/rspec/record_test_result.json create mode 100644 tests/data/rspec/rspec.xml create mode 100644 tests/test_runners/test_rspec.py diff --git a/tests/data/rspec/record_test_result.json b/tests/data/rspec/record_test_result.json new file mode 100644 index 000000000..5775b8291 --- /dev/null +++ b/tests/data/rspec/record_test_result.json @@ -0,0 +1,372 @@ +{ + "events": [ + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/models/article_spec.rb" + }, + { + "type": "class", + "name": "spec.models.article_spec" + }, + { + "type": "testcase", + "name": "Article validation is invalid without a title" + } + ], + "duration": 0.004651, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/models/article_spec.rb" + }, + { + "type": "class", + "name": "spec.models.article_spec" + }, + { + "type": "testcase", + "name": "Article validation is invalid without a body" + } + ], + "duration": 0.000582, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/models/comment_spec.rb" + }, + { + "type": "class", + "name": "spec.models.comment_spec" + }, + { + "type": "testcase", + "name": "Comment validation is invalid without a name" + } + ], + "duration": 0.014728, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/models/comment_spec.rb" + }, + { + "type": "class", + "name": "spec.models.comment_spec" + }, + { + "type": "testcase", + "name": "Comment validation is invalid without a body" + } + ], + "duration": 0.002774, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /index success request" + } + ], + "duration": 0.10244, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /index show titles" + } + ], + "duration": 0.01104, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /show success request" + } + ], + "duration": 0.022874, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /show show titles and body" + } + ], + "duration": 0.009366, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /show has comments show comments" + } + ], + "duration": 0.011478, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles GET /new success request" + } + ], + "duration": 0.009679, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles POST #create success request" + } + ], + "duration": 0.008267, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles POST #create create new record" + } + ], + "duration": 0.006611, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/articles_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.articles_spec" + }, + { + "type": "testcase", + "name": "Articles POST #create redirect to created article page" + } + ], + "duration": 0.005609, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/comments_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.comments_spec" + }, + { + "type": "testcase", + "name": "comments POST #create success request" + } + ], + "duration": 0.007504, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/comments_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.comments_spec" + }, + { + "type": "testcase", + "name": "comments POST #create create new record" + } + ], + "duration": 0.006596, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + }, + { + "type": "case", + "testPath": [ + { + "type": "file", + "name": "spec/requests/comments_spec.rb" + }, + { + "type": "class", + "name": "spec.requests.comments_spec" + }, + { + "type": "testcase", + "name": "comments POST #create redirect to parent article page" + } + ], + "duration": 0.006482, + "status": 1, + "stdout": "", + "stderr": "", + "created_at": "2021-03-22T14:06:25+09:00", + "data": null + } + ] +} diff --git a/tests/data/rspec/rspec.xml b/tests/data/rspec/rspec.xml new file mode 100644 index 000000000..367f82bd9 --- /dev/null +++ b/tests/data/rspec/rspec.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_runners/test_rspec.py b/tests/test_runners/test_rspec.py new file mode 100644 index 000000000..df0d24145 --- /dev/null +++ b/tests/test_runners/test_rspec.py @@ -0,0 +1,20 @@ +from pathlib import Path +import responses # type: ignore +import json +import gzip +import sys +from tests.cli_test_case import CliTestCase + + +class RspecTest(CliTestCase): + test_files_dir = Path(__file__).parent.joinpath('../data/rspec/').resolve() + result_file_path = test_files_dir.joinpath('record_test_result.json') + + @responses.activate + def test_record_test_rspec(self): + result = self.cli('record', 'tests', '--session', self.session, 'rspec', str(self.test_files_dir.joinpath("rspec.xml"))) + self.assertEqual(result.exit_code, 0) + payload = json.loads(gzip.decompress( + b''.join(responses.calls[0].request.body)).decode()) + expected = self.load_json_from_file(self.result_file_path) + self.assert_json_orderless_equal(expected, payload) From a24fc07df48ca55b5a90279b09cc0d1d51059c43 Mon Sep 17 00:00:00 2001 From: Yoshiori SHOJI Date: Mon, 22 Mar 2021 15:46:10 +0900 Subject: [PATCH 3/4] Fix minitest plugin bug. The method name was wrong. --- launchable/test_runners/minitest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launchable/test_runners/minitest.py b/launchable/test_runners/minitest.py index 4764456f3..46053a900 100644 --- a/launchable/test_runners/minitest.py +++ b/launchable/test_runners/minitest.py @@ -24,7 +24,7 @@ def parse(fname: str): parse(l) else: # assume it's a file - client.test(fname) + client.test_path(fname) for f in files: parse(f) From 27517ac2cc65e9225155b96d2079fb146d6d3ac3 Mon Sep 17 00:00:00 2001 From: Yoshiori SHOJI Date: Mon, 22 Mar 2021 16:42:00 +0900 Subject: [PATCH 4/4] Add ignore_warnings to gradle test --- tests/test_runners/test_gradle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_runners/test_gradle.py b/tests/test_runners/test_gradle.py index cd0b3658d..26d4d53ad 100644 --- a/tests/test_runners/test_gradle.py +++ b/tests/test_runners/test_gradle.py @@ -14,6 +14,7 @@ class GradleTest(CliTestCase): '../data/gradle/').resolve() result_file_path = test_files_dir.joinpath('recursion/expected.json') + @ignore_warnings @responses.activate def test_subset_without_session(self): responses.replace(responses.POST, "{}/intake/organizations/{}/workspaces/{}/subset".format(get_base_url(), self.organization, self.workspace),