Skip to content

Commit

Permalink
Add basic tests for RSpec, although they don't work yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
connorshea committed Apr 9, 2021
1 parent 94b648a commit 0551434
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ jobs:
run: |
npm run build
npm run package
- name: Run test
- name: Run minitest tests
run: |
xvfb-run -a node ./out/test/runTest.js
xvfb-run -a node ./out/test/runMinitestTests.js
- name: Run rspec tests
run: |
xvfb-run -a node ./out/test/runRspecTests.js
- name: Run Ruby test
run: |
cd ruby && bundle exec rake
14 changes: 13 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/minitest/index",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/frameworks/minitest/index",
"${workspaceFolder}/test/fixtures/minitest"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"]
},
{
"name": "Run tests for RSpec",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/frameworks/rspec/index",
"${workspaceFolder}/test/fixtures/rspec"
],
"outFiles": ["${workspaceFolder}/out/test/**/**/*.js"]
}
]
}
5 changes: 5 additions & 0 deletions test/fixtures/rspec/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rubyTestExplorer": {
"testFramework": "rspec"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/rspec/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "rspec"
gem "rake"
28 changes: 28 additions & 0 deletions test/fixtures/rspec/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.4.4)
rake (13.0.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)

PLATFORMS
ruby

DEPENDENCIES
rake
rspec

BUNDLED WITH
2.2.13
Empty file added test/fixtures/rspec/Rakefile
Empty file.
10 changes: 10 additions & 0 deletions test/fixtures/rspec/lib/abs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Abs
def apply(n)
case
when n > 0
n
when n == 0
raise "Abs for zero is not supported"
end
end
end
5 changes: 5 additions & 0 deletions test/fixtures/rspec/lib/square.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Square
def apply(n)
n + n
end
end
17 changes: 17 additions & 0 deletions test/fixtures/rspec/spec/abs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "test_helper"

describe Abs do
it "finds the absolute value of 1" do
expect(Abs.new.apply(1)).to eq(1)
end

it "finds the absolute value of 0" do
expect(Abs.new.apply(0)).to eq(0)
end

it "finds the absolute value of -1" do
skip
expect(Abs.new.apply(-1)).to eq(1)
end
end

12 changes: 12 additions & 0 deletions test/fixtures/rspec/spec/square_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "test_helper"

describe Square do
it "finds the square of 2" do
expect(Square.new.apply(2)).to eq(4)
end

it "finds the square of 3" do
expect(Square.new.apply(3)).to eq(9)
end
end

5 changes: 5 additions & 0 deletions test/fixtures/rspec/spec/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$LOAD_PATH << File.join(__dir__, "../lib")

require "abs"
require "square"
require "rspec"
File renamed without changes.
32 changes: 32 additions & 0 deletions test/runRspecTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as path from 'path';
import * as cp from 'child_process';

import { runTests, downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath } from 'vscode-test';

async function main() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

const vscodeExecutablePath = await downloadAndUnzipVSCode('stable')

const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath)
cp.spawnSync(cliPath, ['--install-extension', 'hbenl.vscode-test-explorer'], {
encoding: 'utf-8',
stdio: 'inherit'
})

await runTests(
{
extensionDevelopmentPath,
extensionTestsPath: path.resolve(__dirname, './suite/frameworks/rspec/index'),
launchArgs: [path.resolve(extensionDevelopmentPath, 'test/fixtures/rspec')]
}
);
} catch (err) {
console.error(err);
console.error('Failed to run tests');
process.exit(1);
}
}

main();
34 changes: 34 additions & 0 deletions test/suite/frameworks/rspec/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});

return new Promise((c, e) => {
glob('**.test.js', { cwd: __dirname }, (err, files) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(__dirname, f)));

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
});
}
Loading

0 comments on commit 0551434

Please sign in to comment.