2
2
require 'fileutils'
3
3
require 'minitar'
4
4
require 'test/unit'
5
+ require 'mocha/test_unit'
5
6
require 'tmpdir'
6
7
7
8
require "git"
@@ -148,6 +149,7 @@ def with_custom_env_variables(&block)
148
149
# @param expected_command_line [Array<String>] The expected arguments to be sent to Git::Lib#command
149
150
# @param git_cmd [Symbol] the method to be called on the Git::Base object
150
151
# @param git_cmd_args [Array<Object>] The arguments to be sent to the git_cmd method
152
+ # @param git_output [String] The output to be returned by the Git::Lib#command method
151
153
#
152
154
# @yield [git] An initialization block
153
155
# The initialization block is called after a test project is created with Git.init.
@@ -157,9 +159,11 @@ def with_custom_env_variables(&block)
157
159
#
158
160
# @return [void]
159
161
#
160
- def assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
162
+ def assert_command_line ( expected_command_line , git_cmd , git_cmd_args , git_output = nil )
161
163
actual_command_line = nil
162
164
165
+ command_output = ''
166
+
163
167
in_temp_dir do |path |
164
168
git = Git . init ( 'test_project' )
165
169
@@ -169,17 +173,26 @@ def assert_command_line(expected_command_line, git_cmd, git_cmd_args)
169
173
# Mock the Git::Lib#command method to capture the actual command line args
170
174
git . lib . define_singleton_method ( :command ) do |cmd , *opts , &block |
171
175
actual_command_line = [ cmd , *opts . flatten ]
176
+ git_output
172
177
end
173
178
174
- git . send ( git_cmd , *git_cmd_args )
179
+ command_output = git . send ( git_cmd , *git_cmd_args )
175
180
end
176
181
end
177
182
178
183
assert_equal ( expected_command_line , actual_command_line )
184
+
185
+ command_output
179
186
end
180
187
181
188
def assert_child_process_success ( &block )
182
189
yield
183
190
assert_equal 0 , $CHILD_STATUS. exitstatus , "Child process failed with exitstatus #{ $CHILD_STATUS. exitstatus } "
184
191
end
192
+
193
+ def windows_platform?
194
+ # Check if on Windows via RUBY_PLATFORM (CRuby) and RUBY_DESCRIPTION (JRuby)
195
+ win_platform_regex = /mingw|mswin/
196
+ RUBY_PLATFORM =~ win_platform_regex || RUBY_DESCRIPTION =~ win_platform_regex
197
+ end
185
198
end
0 commit comments