Skip to content

Commit

Permalink
properly mock the environment where tested file is expected to run
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusreza committed Feb 7, 2019
1 parent c93505d commit 796bbfd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
9 changes: 1 addition & 8 deletions lib/docker-sync/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ def self.ensure_all_for_mac!(config)
Docker.ensure!
Unison.ensure! if config.unison_required?
Rsync.ensure! if config.rsync_required?
if config.fswatch_required?
unless Fswatch.available?
Fswatch.ensure!
puts "please restart docker sync so the installation of fswatch takes effect"
raise(UNSUPPORTED_OPERATING_SYSTEM)
end
end

Fswatch.ensure! if config.fswatch_required?
end

def self.ensure_all_for_linux!(_config)
Expand Down
9 changes: 6 additions & 3 deletions lib/docker-sync/dependencies/fswatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ def self.available?
end

def self.ensure!
raise 'Fswatch cannot be installed on other platforms then MacOS' unless Environment.mac?
PackageManager.install_package('fswatch') unless available?
end
return if available?

PackageManager.install_package('fswatch')
puts "please restart docker sync so the installation of fswatch takes effect"
exit(1)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/helpers/command_mocking_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module CommandExecutionMock
COMMAND_EXECUTORS = %i(system exec spawn `).freeze
COMMAND_EXECUTORS = %i(system exec exit spawn `).freeze

def self.included(_base)
define_custom_matchers
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/docker-sync/dependencies/fswatch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require 'spec_helper'

RSpec.describe DockerSync::Dependencies::Fswatch do
before do
allow(DockerSync::Environment).to receive(:mac?).and_return(true)
allow(described_class).to receive(:exit)
end

it_behaves_like 'a dependency'
it_behaves_like 'a binary-checking dependency', 'fswatch'
it_behaves_like 'a binary-installing dependency', 'fswatch'
Expand Down
17 changes: 11 additions & 6 deletions spec/lib/docker-sync/dependencies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

RSpec.describe DockerSync::Dependencies do
let(:config) { double(:config, unison_required?: false, rsync_required?: false, fswatch_required?: false) }
let(:linux?) { false }
let(:mac?) { false }

describe '.ensure_all!(config)' do
let(:mac?) { false }
let(:linux?) { false }
before do
allow(DockerSync::Environment).to receive(:linux?).and_return(linux?)
allow(DockerSync::Environment).to receive(:mac?).and_return(mac?)
end

describe '.ensure_all!(config)' do
before do
allow(DockerSync::Environment).to receive(:mac?).and_return(mac?)
allow(DockerSync::Environment).to receive(:linux?).and_return(linux?)
allow(described_class).to receive(:ensure_all_for_mac!)
allow(described_class).to receive(:ensure_all_for_linux!)
end
Expand Down Expand Up @@ -42,6 +44,8 @@
end

describe '.ensure_all_for_linux!(_config)' do
let(:linux?) { true }

before do
allow(described_class::Docker).to receive(:ensure!)
end
Expand All @@ -55,9 +59,10 @@
end

describe '.ensure_all_for_mac!(config)' do
let(:mac?) { true }

before do
allow(described_class::PackageManager).to receive(:ensure!)
#allow(DockerSync::Dependencies::Fswatch).to receive(:ensure!).and_return(true)
allow(described_class::Docker).to receive(:ensure!)
end

Expand Down

0 comments on commit 796bbfd

Please sign in to comment.