Skip to content

Commit 50c0f9f

Browse files
authored
Merge pull request #2 from git-command/vs-fix-gh-workflows
Fix GitHub testing workflows
2 parents bba39e7 + 12b0792 commit 50c0f9f

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

.github/workflows/multi-ruby-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: true
1313
matrix:
1414
os: [ ubuntu-latest, macos-latest ]
15-
ruby: ['2.6.9', '2.7.5', '3.0.3', '3.1.0 ']
15+
ruby: ['2.7.5', '3.0.3', '3.1.0 ']
1616
runs-on: ${{ matrix.os }}
1717
steps:
1818
- uses: actions/checkout@v2

spec/features/register_commands_in_workflow_file_spec.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
FileUtils.cp "#{fixtures_dir}/hello_command.rb", "#{project_dir}/.git-commands/hello.rb"
4040

4141
run_system_call "#{git_cmd_path} help"
42-
expect(last_command.output).
43-
to include("faq, hello")
42+
expect(last_command.output).to include("faq")
43+
expect(last_command.output).to include("hello")
4444

4545
run_system_call "#{git_cmd_path} faq --help"
4646
expect(last_command.output).
@@ -55,7 +55,8 @@
5555
FileUtils.rm_rf "#{project_dir}/.git-commands"
5656
run_system_call "#{git_cmd_path} help"
5757

58-
expect(last_command.output).to_not include("hello, faq")
58+
expect(last_command.output).to_not include("faq")
59+
expect(last_command.output).to_not include("hello")
5960
end
6061
end
6162
end

spec/features/run_plugin_command_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
end
2323

2424
it "outputs the current changes" do
25-
run_system_call "#{git_cmd_path} git-helpers:current"
25+
run_system_call "cd #{project_dir} && #{git_cmd_path} git-helpers:current"
2626
expect(last_command.output).
2727
to include("Updated README")
2828
end

spec/fixtures/plugins/git_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
command :current do |cmd|
66
cmd.summary "Outputs all commits not on the base branch"
7-
cmd.argument :base_branch, default: "master"
7+
cmd.argument :base_branch, default: "main"
88

99
cmd.on_run do |options|
1010
current_branch = system.run "git rev-parse --abbrev-ref HEAD"

spec/lib/git_commander/command/loaders/raw_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
loader.load(raw_command_string)
127127

128-
expect(loader.result.errors.size).to be_zero
128+
expect(loader.result.errors).to_not be_any
129129
expect(loader.result.plugins.size).to eq 1
130130
expect(loader.result.commands.size).to eq 2
131131

spec/support/command_helpers.rb

+34-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
require "open3"
66

77
module CommandHelpers
8-
Command = Struct.new(:exit_status, :output, :error)
8+
class SystemCallFailure < StandardError; end
9+
Command = Struct.new(:exit_status, :output, :error) do
10+
def failed?
11+
exit_status != 0 && !error.to_s.empty?
12+
end
13+
14+
def error_message_with_exit_status
15+
"[exit status: #{exit_status}] #{error}"
16+
end
17+
end
918

1019
def fixtures_dir
1120
File.expand_path "#{Dir.pwd}/spec/fixtures"
@@ -31,6 +40,7 @@ def git_cmd_path
3140
def setup_environment
3241
setup_home_dir
3342
setup_project_dir
43+
initialize_git_user
3444
initialize_git_repo
3545
end
3646

@@ -48,21 +58,26 @@ def setup_project_dir
4858
FileUtils.mkdir_p project_dir
4959
end
5060

61+
def initialize_git_user
62+
run_system_call 'git config --global user.name "GitHub Actions Bot"', fail_on_error: true
63+
run_system_call 'git config --global user.email "<>"', fail_on_error: true
64+
end
65+
5166
def initialize_git_repo
52-
run_system_call "touch README.md"
53-
run_system_call "git init ."
54-
run_system_call "git add README.md"
55-
run_system_call 'git commit -am "Initial commit"'
67+
run_system_call "touch README.md", fail_on_error: true
68+
run_system_call "git init -b main .", fail_on_error: true
69+
run_system_call "git add README.md", fail_on_error: true
70+
run_system_call 'git commit -am "Initial commit"', fail_on_error: true
5671
end
5772

58-
def setup_working_branch(branch = "master")
59-
run_system_call "git checkout -b #{branch}"
73+
def setup_working_branch(branch = "main")
74+
run_system_call "git checkout -b #{branch}", fail_on_error: true
6075
end
6176

6277
def make_commit(message = "Changes")
63-
run_system_call 'echo "Changes" >> README.md'
64-
run_system_call "git add README.md"
65-
run_system_call "git commit -am \"#{message}\""
78+
run_system_call 'echo "Changes" >> README.md', fail_on_error: true
79+
run_system_call "git add README.md", fail_on_error: true
80+
run_system_call "git commit -am \"#{message}\"", fail_on_error: true
6681
end
6782

6883
def command_helpers_teardown
@@ -89,16 +104,20 @@ def capture_io
89104
$stderr = orig_stderr
90105
end
91106

92-
def run_system_call(command_string)
107+
def run_system_call(command_string, fail_on_error: false)
93108
last_command.output, last_command.error, last_command.exit_status = run_in_test_context do
94109
Open3.capture3(command_string)
95110
end
111+
112+
return unless fail_on_error && last_command.failed?
113+
114+
raise SystemCallFailure, <<~ERROR_MSG
115+
System call '#{command_string}' failed to run: #{last_command.error_message_with_exit_status}
116+
ERROR_MSG
96117
end
97118

98-
def run_in_test_context(&_block)
99-
Dir.chdir project_dir do
100-
yield
101-
end
119+
def run_in_test_context(&block)
120+
Dir.chdir(project_dir, &block)
102121
end
103122

104123
private

0 commit comments

Comments
 (0)