Skip to content

Commit 594a1dc

Browse files
committed
Add tests for ScriptRunner
1 parent 1728cf8 commit 594a1dc

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/script_runner_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
defmodule ElixirScript.ScriptRunnerTest do
2+
use ExUnit.Case, async: true
3+
4+
import Mox
5+
6+
alias ElixirScript.ScriptRunner
7+
alias Test.Fixtures.GitHubWorkflowRun
8+
9+
setup do
10+
stub(SystemEnvBehaviourMock, :get_env, fn varname, default ->
11+
GitHubWorkflowRun.env()[varname] || default
12+
end)
13+
14+
:ok
15+
end
16+
17+
test "run executes script in a given context and returns its output" do
18+
script = """
19+
"Hello, " <> context.actor
20+
"""
21+
22+
assert ScriptRunner.run(script) == "Hello, gaggle"
23+
end
24+
25+
test "run raises if the script raises an error" do
26+
script = """
27+
raise "error!"
28+
"""
29+
30+
assert_raise RuntimeError, "error!", fn ->
31+
ScriptRunner.run(script)
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)