logstash/spec/bootstrap/bundler_spec.rb
Colin Surprenant 12a5982da2 logstash-core & logstash-core-event extraction to support logstash-core-event-java impl, relates to #4191
fixed timezone issue

extracted logstash-core and reorganized specs

extracted logstash-core-event

extract java Event into logstash-core-event-java in a proper gem

remove obsolete jruby_event bootstrapping

fix require path

add java code bootstrap

use logstash-core-event/logstash-core-event.rb

remove obsolete files

basic instructions

LogStash::Json need to be initialized from event

update jruby and gradle versions

update compile:logstash-core-event-java rake task

WIP tasks refactor

fix gem.files

skip test if class is not defined

fix gem related tasks for new structure

add gem spec dirs in core tests

bootstrap java implementation when requiring timestamp

new Cloner class and Event clone impl

fix array fields assignments, see #4140

don't rely on json implementation ordering

fix skipped last iterpolation char

remove implementation specific unnecessary check

also require ruby classes

define error class in ruby

raise exception on invalid format

remove implementation specific tests and extract and put logger related test in pending

missing bits for having all core timestamp specs pass

run all core specs

remove leftover

comment regex

missing encoding header

revert to logstash-core-event by default

finished proper gemification

useless require

dynamically pick specs depending on logstash-core-event-* implementation

logstash root package version

missing file for proper gemification

do not build java event by default

always check for root logstash lib dir

fix concurrent-ruby version confict

fix rebase conflict

re-enable specs

user vars instead of constants

move non core code in bootstrap

document version files

move version file

remove useless code

use version in logstash-core

fix gem files list

put back concurrent-ruby version constrain as in master

add dependency on logstash-core-event

remove dependency on logstash-core to avoid circular dependency

fix rebase conflict

remove circular dependency

fix specs

update README
2015-11-16 17:16:10 -05:00

121 lines
3.8 KiB
Ruby

# encoding: utf-8
require "spec_helper"
require "bundler/cli"
describe LogStash::Bundler do
context "capture_stdout" do
it "should capture stdout from block" do
original_stdout = $stdout
output, exception = LogStash::Bundler.capture_stdout do
expect($stdout).not_to eq(original_stdout)
puts("foobar")
end
expect($stdout).to eq(original_stdout)
expect(output).to eq("foobar\n")
expect(exception).to eq(nil)
end
it "should capture stdout and report exception from block" do
output, exception = LogStash::Bundler.capture_stdout do
puts("foobar")
raise(StandardError, "baz")
end
expect(output).to eq("foobar\n")
expect(exception).to be_a(StandardError)
expect(exception.message).to eq("baz")
end
end
context 'when invoking bundler' do
original_stderr = $stderr
subject { LogStash::Bundler.invoke!(options) }
# by default we want to fail fast on the test
let(:options) { { :install => true, :max_tries => 0, :without => [:development]} }
let(:bundler_args) { LogStash::Bundler.bundler_arguments(options) }
before do
$stderr = StringIO.new
expect(::Bundler).to receive(:reset!).at_least(1)
end
after do
expect(::Bundler.settings[:path]).to eq(LogStash::Environment::BUNDLE_DIR)
expect(::Bundler.settings[:gemfile]).to eq(LogStash::Environment::GEMFILE_PATH)
expect(::Bundler.settings[:without]).to eq(options.fetch(:without, []).join(':'))
expect(ENV['GEM_PATH']).to eq(LogStash::Environment.logstash_gem_home)
$stderr = original_stderr
end
it 'should call Bundler::CLI.start with the correct arguments' do
expect(::Bundler::CLI).to receive(:start).with(bundler_args)
LogStash::Bundler.invoke!(options)
end
context 'abort with an exception' do
it 'gem conflict' do
allow(::Bundler::CLI).to receive(:start).with(bundler_args) { raise ::Bundler::VersionConflict.new('conflict') }
expect { subject }.to raise_error(::Bundler::VersionConflict)
end
it 'gem is not found' do
allow(::Bundler::CLI).to receive(:start).with(bundler_args) { raise ::Bundler::GemNotFound.new('conflict') }
expect { subject }.to raise_error(::Bundler::GemNotFound)
end
it 'on max retries' do
options.merge!({ :max_tries => 2 })
expect(::Bundler::CLI).to receive(:start).with(bundler_args).at_most(options[:max_tries] + 1) { raise RuntimeError }
expect { subject }.to raise_error(RuntimeError)
end
end
end
context 'when generating bundler arguments' do
subject { LogStash::Bundler.bundler_arguments(options) }
let(:options) { {} }
context 'when installing' do
let(:options) { { :install => true } }
it 'should call bundler install' do
expect(subject).to include('install')
end
context 'with the cleaning option' do
it 'should add the --clean arguments' do
options.merge!(:clean => true)
expect(subject).to include('install','--clean')
end
end
end
context "when updating" do
let(:options) { { :update => 'logstash-input-stdin' } }
context 'with a specific plugin' do
it 'should call `bundle update plugin-name`' do
expect(subject).to include('update', 'logstash-input-stdin')
end
end
context 'with the cleaning option' do
it 'should ignore the clean option' do
options.merge!(:clean => true)
expect(subject).not_to include('--clean')
end
end
end
context "when only specifying clean" do
let(:options) { { :clean => true } }
it 'should call the `bundle clean`' do
expect(subject).to include('clean')
end
end
end
end