提交 b068db42 编写于 作者: M Mislav Marohnić

Add isolated tests for Context#git_editor method

上级 13954a4b
require 'helper'
class ContextTest < Test::Unit::TestCase
class Context
include Hub::Context
def initialize(&block)
@git_reader = Hub::Context::GitReader.new('git', &block)
end
public :git_editor
end
attr_reader :context
def setup
super
@stubs = {}
@context = Context.new do |_, cmd|
@stubs.fetch(cmd)
end
end
def test_editor
stub_command_output 'var GIT_EDITOR', 'vim'
assert_equal %w'vim', context.git_editor
end
def test_editor_with_argument
stub_command_output 'var GIT_EDITOR', 'subl -w'
assert_equal %w'subl -w', context.git_editor
end
def test_editor_with_spaces
stub_command_output 'var GIT_EDITOR', '"my editor" -w arg2'
assert_equal %w'my\ editor -w arg2', context.git_editor
end
def test_editor_with_tilde
stub_command_output 'var GIT_EDITOR', '~/bin/vi'
with_env('HOME', '/home/mislav') do
assert_equal %w'/home/mislav/bin/vi', context.git_editor
end
end
def test_editor_with_env_variable
stub_command_output 'var GIT_EDITOR', '$EDITOR'
with_env('EDITOR', 'subl -w') do
assert_equal %w'subl -w', context.git_editor
end
end
private
def stub_command_output(cmd, value)
@stubs[cmd] = value.nil? ? nil : value.to_s
end
def with_env(name, value)
dir, ENV[name] = ENV[name], value
yield
ensure
ENV[name] = dir
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册