Skip to content

Commit

Permalink
Ensure env variables are forwarded to the editor command
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Sep 21, 2020
1 parent 13a449b commit 6a49b4a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/tty/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ def initialize(command: nil, raise_on_failure: false, show_menu: true,

# Read or update environment vars
#
# @return [Hash]
#
# @api public
def env(value = (not_set = true))
return @env if not_set

@env = value
end

Expand Down
30 changes: 30 additions & 0 deletions spec/unit/env_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

RSpec.describe TTY::Editor, "#env" do
it "configures ENV variables via initializer" do
allow(described_class).to receive(:available).and_return(["vim"])
editor = described_class.new(env: {"FOO" => "bar"})

expect(editor.env).to eq({"FOO" => "bar"})
end

it "configures ENV variables via accessor" do
allow(described_class).to receive(:available).and_return(["vim"])
editor = described_class.new

editor.env "FOO" => "bar"

expect(editor.env).to eq({"FOO" => "bar"})
end

it "forwards env variables to command" do
allow(described_class).to receive(:available).and_return(["vim"])
file = fixtures_path("content.txt")
editor = described_class.new(env: {"FOO" => "bar"})
allow(editor).to receive(:system).and_return(true)

editor.open(file)

expect(editor).to have_received(:system).with({"FOO" => "bar"}, "vim", file)
end
end

0 comments on commit 6a49b4a

Please sign in to comment.