1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
require 'yaml'
require 'nenv/environment/loader'
RSpec.describe Nenv::Environment::Loader do
context 'with no block' do
subject { described_class.setup(meth).(value) }
context 'with a normal method' do
let(:meth) { :foo }
context "with \"abc\"" do
let(:value) { 'abc' }
it { is_expected.to eq('abc') }
end
end
context 'with a bool method' do
let(:meth) { :foo? }
%w(1 true y yes TRUE YES foobar).each do |data|
context "with #{data.inspect}" do
let(:value) { data }
it { is_expected.to eq(true) }
end
end
%w(0 false n no FALSE NO).each do |data|
context "with #{data.inspect}" do
let(:value) { data }
it { is_expected.to eq(false) }
end
end
context 'with nil' do
let(:value) { nil }
it { is_expected.to eq(nil) }
end
context 'when empty string' do
let(:value) { '' }
it do
expect { subject }.to raise_error(
ArgumentError, /Can't convert empty string into Bool/
)
end
end
end
end
context 'with a block' do
subject do
described_class.setup(:foo) { |data| YAML.load(data) }.(value)
end
context 'with a yaml string' do
let(:value) { "--- foo\n...\n" }
it { is_expected.to eq('foo') }
end
end
end
|