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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RSpec::StubbedEnv::TestHelpers do
describe 'stub_env' do
context 'control without stubbing' do
subject { FooByEnv.new }
it 'is test env' do
expect(subject.env).to eq('test')
end
it 'has 2 localhost settings' do
expect(subject.array.grep(/localhost:\d{3}\Z/).length).to eq(2)
end
it 'has size 2' do
expect(subject.size).to eq(2)
end
end
context 'hash signature' do
context 'development environment' do
include_context 'with stubbed env'
let(:environment) { 'development' }
before do
stub_env(
'MEDIUM_1' => 'datastore-01.example.org',
'MEDIUM_2' => 'datastore-02.example.org',
'IRRELEVANT_3' => 'datastore-03.example.org',
)
allow(Rails).to receive(:env).and_return(environment)
end
subject { FooByEnv.new }
it 'is development env' do
expect(subject.env).to eq(environment)
end
it 'has 2 example.org settings' do
expect(subject.array.grep(/datastore-\d{2}\.example\.org\Z/).length).to eq(2)
end
it 'has size 2' do
expect(subject.size).to eq(2)
end
end
context 'production environment' do
include_context 'with stubbed env'
let(:environment) { 'production' }
before do
stub_env(
'BIG_1' => 'datastore-01.example.org',
'BIG_2' => 'datastore-02.example.org',
'BIG_3' => 'datastore-03.example.org',
'BIG_4' => 'datastore-04.example.org',
'IRRELEVANT_5' => 'datastore-03.example.org',
)
allow(Rails).to receive(:env).and_return(environment)
end
subject { FooByEnv.new }
it 'is production env' do
expect(subject.env).to eq(environment)
end
it 'has 4 example.org settings' do
expect(subject.array.grep(/datastore-\d{2}\.example\.org\Z/).length).to eq(4)
end
it 'has size 4' do
expect(subject.size).to eq(4)
end
end
end
context 'key, value signature' do
context 'development environment' do
include_context 'with stubbed env'
let(:environment) { 'development' }
before do
stub_env('MEDIUM_1', 'datastore-01.example.org')
stub_env('MEDIUM_2', 'datastore-02.example.org')
stub_env('IRRELEVANT_3', 'datastore-03.example.org')
allow(Rails).to receive(:env).and_return(environment)
end
subject { FooByEnv.new }
it 'is development env' do
expect(subject.env).to eq(environment)
end
it 'has 2 example.org settings' do
expect(subject.array.grep(/datastore-\d{2}\.example\.org\Z/).length).to eq(2)
end
it 'has size 2' do
expect(subject.size).to eq(2)
end
end
context 'production environment' do
include_context 'with stubbed env'
let(:environment) { 'production' }
before do
stub_env('BIG_1', 'datastore-01.example.org')
stub_env('BIG_2', 'datastore-02.example.org')
stub_env('BIG_3', 'datastore-03.example.org')
stub_env('BIG_4', 'datastore-04.example.org')
stub_env('IRRELEVANT_5', 'datastore-05.example.org')
allow(Rails).to receive(:env).and_return(environment)
end
subject { FooByEnv.new }
it 'is production env' do
expect(subject.env).to eq(environment)
end
it 'has 4 example.org settings' do
expect(subject.array.grep(/datastore-\d{2}\.example\.org\Z/).length).to eq(4)
end
it 'has size 4' do
expect(subject.size).to eq(4)
end
end
end
end
end
|