Skip to content

Commit

Permalink
Got some basic RSpec test cases working.
Browse files Browse the repository at this point in the history
  • Loading branch information
connorshea committed Apr 9, 2021
1 parent 0551434 commit 6c37868
Showing 1 changed file with 40 additions and 71 deletions.
111 changes: 40 additions & 71 deletions test/suite/frameworks/rspec/rspec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,51 @@ suite('Extension Test for RSpec', () => {
label: 'rspec RSpec',
children: [
{
file: path.resolve(dirPath, "test/abs_spec.rb"),
file: path.resolve(dirPath, "spec/abs_spec.rb"),
id: "./spec/abs_spec.rb",
label: "abs_spec.rb",
type: "suite",
children: [
{
file: path.resolve(dirPath, "test/abs_spec.rb"),
id: "./spec/abs_spec.rb[4]",
label: "abs positive",
file: path.resolve(dirPath, "spec/abs_spec.rb"),
id: "./spec/abs_spec.rb[1:1]",
label: "finds the absolute value of 1",
line: 3,
type: "test"
},
{
file: path.resolve(dirPath, "test/abs_spec.rb"),
id: "./spec/abs_spec.rb[8]",
label: "abs 0",
file: path.resolve(dirPath, "spec/abs_spec.rb"),
id: "./spec/abs_spec.rb[1:2]",
label: "finds the absolute value of 0",
line: 7,
type: "test"
},
{
file: path.resolve(dirPath, "test/abs_spec.rb"),
id: "./spec/abs_spec.rb[12]",
label: "abs negative",
file: path.resolve(dirPath, "spec/abs_spec.rb"),
id: "./spec/abs_spec.rb[1:3]",
label: "finds the absolute value of -1",
line: 11,
type: "test"
}
]
},
{
file: path.resolve(dirPath, "test/square_spec.rb"),
file: path.resolve(dirPath, "spec/square_spec.rb"),
id: "./spec/square_spec.rb",
label: "square_spec.rb",
type: "suite",
children: [
{
file: path.resolve(dirPath, "test/square_spec.rb"),
id: "./spec/square_spec.rb[4]",
label: "square 2",
file: path.resolve(dirPath, "spec/square_spec.rb"),
id: "./spec/square_spec.rb[1:1]",
label: "finds the square of 2",
line: 3,
type: "test"
},
{
file: path.resolve(dirPath, "test/square_spec.rb"),
id: "./spec/square_spec.rb[8]",
label: "square 3",
file: path.resolve(dirPath, "spec/square_spec.rb"),
id: "./spec/square_spec.rb[1:2]",
label: "finds the square of 3",
line: 7,
type: "test"
}
Expand All @@ -91,15 +91,13 @@ suite('Extension Test for RSpec', () => {
testHub.registerTestController(controller);

await controller.load()
await controller.runTest('./spec/square_spec.rb[4]')
await controller.runTest('./spec/square_spec.rb')

assert.deepStrictEqual(
controller.testEvents['./spec/square_spec.rb[4]'],
controller.testEvents['./spec/square_spec.rb[1:1]'],
[
{ state: "running", test: "./spec/square_spec.rb[4]", type: "test" },
{ state: "running", test: "./spec/square_spec.rb[4]", type: "test" },
{ state: "passed", test: "./spec/square_spec.rb[4]", type: "test" },
{ state: "passed", test: "./spec/square_spec.rb[4]", type: "test" }
{ state: "passed", test: "./spec/square_spec.rb[1:1]", type: "test" },
{ state: "passed", test: "./spec/square_spec.rb[1:1]", type: "test" }
]
)
})
Expand All @@ -113,36 +111,26 @@ suite('Extension Test for RSpec', () => {
testHub.registerTestController(controller);

await controller.load()
await controller.runTest('./spec/square_spec.rb[8]')
await controller.runTest('./spec/square_spec.rb')

assert.deepStrictEqual(
controller.testEvents['./spec/square_spec.rb[8]'][0],
{ state: "running", test: "./spec/square_spec.rb[8]", type: "test" }
controller.testEvents['./spec/square_spec.rb[1:2]'][0],
{ state: "failed", test: "./spec/square_spec.rb[1:2]", type: "test" }
)

assert.deepStrictEqual(
controller.testEvents['./spec/square_spec.rb[8]'][1],
{ state: "running", test: "./spec/square_spec.rb[8]", type: "test" }
)

assert.deepStrictEqual(
controller.testEvents['./spec/square_spec.rb[8]'][2],
{ state: "failed", test: "./spec/square_spec.rb[8]", type: "test" }
)

const lastEvent = controller.testEvents['./spec/square_spec.rb[8]'][3]
const lastEvent = controller.testEvents['./spec/square_spec.rb[1:2]'][1]
assert.strictEqual(lastEvent.state, "failed")
assert.strictEqual(lastEvent.line, undefined)
assert.strictEqual(lastEvent.tooltip, undefined)
assert.strictEqual(lastEvent.description, undefined)
assert.ok(lastEvent.message?.startsWith("Expected: 9\n Actual: 6\n"))
assert.ok(lastEvent.message?.startsWith("RSpec::Expectations::ExpectationNotMetError:\n expected: 9\n got: 6\n"))

assert.strictEqual(lastEvent.decorations!.length, 1)
const decoration = lastEvent.decorations![0]
assert.strictEqual(decoration.line, 8)
assert.strictEqual(decoration.file, undefined)
assert.strictEqual(decoration.hover, undefined)
assert.strictEqual(decoration.message, "Expected: 9\n Actual: 6")
assert.strictEqual(decoration.message, " expected: 9\n got: 6\n\n(compared using ==)\n")
})

test('run test error', async () => {
Expand All @@ -154,36 +142,31 @@ suite('Extension Test for RSpec', () => {
testHub.registerTestController(controller);

await controller.load()
await controller.runTest('./spec/abs_spec.rb[8]')

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[8]'][0],
{ state: "running", test: "./spec/abs_spec.rb[8]", type: "test" }
)
await controller.runTest('./spec/abs_spec.rb[1:2]')

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[8]'][1],
{ state: "running", test: "./spec/abs_spec.rb[8]", type: "test" }
controller.testEvents['./spec/abs_spec.rb[1:2]'][0],
{ state: "running", test: "./spec/abs_spec.rb[1:2]", type: "test" }
)

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[8]'][2],
{ state: "failed", test: "./spec/abs_spec.rb[8]", type: "test" }
controller.testEvents['./spec/abs_spec.rb[1:2]'][1],
{ state: "failed", test: "./spec/abs_spec.rb[1:2]", type: "test" }
)

const lastEvent = controller.testEvents['./spec/abs_spec.rb[8]'][3]
const lastEvent = controller.testEvents['./spec/abs_spec.rb[1:2]'][2]
assert.strictEqual(lastEvent.state, "failed")
assert.strictEqual(lastEvent.line, undefined)
assert.strictEqual(lastEvent.tooltip, undefined)
assert.strictEqual(lastEvent.description, undefined)
assert.ok(lastEvent.message?.startsWith("RuntimeError: Abs for zero is not supported\n"))
assert.ok(lastEvent.message?.startsWith("RuntimeError:\nAbs for zero is not supported"))

assert.strictEqual(lastEvent.decorations!.length, 1)
const decoration = lastEvent.decorations![0]
assert.strictEqual(decoration.line, 8)
assert.strictEqual(decoration.file, undefined)
assert.strictEqual(decoration.hover, undefined)
assert.ok(decoration.message?.startsWith("RuntimeError: Abs for zero is not supported\n"))
assert.ok(decoration.message?.startsWith("Abs for zero is not supported"))
})

test('run test skip', async () => {
Expand All @@ -195,30 +178,16 @@ suite('Extension Test for RSpec', () => {
testHub.registerTestController(controller);

await controller.load()
await controller.runTest('./spec/abs_spec.rb[12]')
await controller.runTest('./spec/abs_spec.rb[1:3]')

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[12]'][0],
{ state: "running", test: "./spec/abs_spec.rb[12]", type: "test" }
controller.testEvents['./spec/abs_spec.rb[1:3]'][0],
{ state: "running", test: "./spec/abs_spec.rb[1:3]", type: "test" }
)

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[12]'][1],
{ state: "running", test: "./spec/abs_spec.rb[12]", type: "test" }
controller.testEvents['./spec/abs_spec.rb[1:3]'][1],
{ state: "skipped", test: "./spec/abs_spec.rb[1:3]", type: "test" }
)

assert.deepStrictEqual(
controller.testEvents['./spec/abs_spec.rb[12]'][2],
{ state: "skipped", test: "./spec/abs_spec.rb[12]", type: "test" }
)

const lastEvent = controller.testEvents['./spec/abs_spec.rb[12]'][3]
assert.strictEqual(lastEvent.state, "skipped")
assert.strictEqual(lastEvent.line, undefined)
assert.strictEqual(lastEvent.tooltip, undefined)
assert.strictEqual(lastEvent.description, undefined)
assert.strictEqual(lastEvent.message, "Not implemented yet")

assert.strictEqual(lastEvent.decorations, undefined)
})
});

0 comments on commit 6c37868

Please sign in to comment.