|
6 | 6 | module SyntaxTree
|
7 | 7 | module Rake
|
8 | 8 | class CheckTaskTest < Minitest::Test
|
9 |
| - Invoke = Struct.new(:args) |
| 9 | + Invocation = Struct.new(:args) |
10 | 10 |
|
11 | 11 | def test_check_task
|
12 | 12 | source_files = "{app,config,lib}/**/*.rb"
|
13 | 13 | CheckTask.new { |t| t.source_files = source_files }
|
14 | 14 |
|
15 |
| - invoke = nil |
16 |
| - SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do |
17 |
| - ::Rake::Task["stree:check"].invoke |
18 |
| - end |
19 |
| - |
20 |
| - assert_equal(["check", source_files], invoke.args) |
| 15 | + invocation = invoke("stree:check") |
| 16 | + assert_equal(["check", source_files], invocation.args) |
21 | 17 | end
|
22 | 18 |
|
23 | 19 | def test_write_task
|
24 | 20 | source_files = "{app,config,lib}/**/*.rb"
|
25 | 21 | WriteTask.new { |t| t.source_files = source_files }
|
26 | 22 |
|
27 |
| - invoke = nil |
28 |
| - SyntaxTree::CLI.stub(:run, ->(args) { invoke = Invoke.new(args) }) do |
29 |
| - ::Rake::Task["stree:write"].invoke |
30 |
| - end |
| 23 | + invocation = invoke("stree:write") |
| 24 | + assert_equal(["write", source_files], invocation.args) |
| 25 | + end |
31 | 26 |
|
32 |
| - assert_equal(["write", source_files], invoke.args) |
| 27 | + private |
| 28 | + |
| 29 | + def invoke(task_name) |
| 30 | + invocation = nil |
| 31 | + stub = ->(args) { invocation = Invocation.new(args) } |
| 32 | + |
| 33 | + begin |
| 34 | + SyntaxTree::CLI.stub(:run, stub) { ::Rake::Task[task_name].invoke } |
| 35 | + flunk |
| 36 | + rescue SystemExit |
| 37 | + invocation |
| 38 | + end |
33 | 39 | end
|
34 | 40 | end
|
35 | 41 | end
|
|
0 commit comments