spec/rake/funnel/tasks/environments_spec.rb in rake-funnel-0.0.6.pre vs spec/rake/funnel/tasks/environments_spec.rb in rake-funnel-0.1.0.pre
- old
+ new
@@ -1,16 +1,24 @@
include Rake
-include Rake::Funnel::Support
+include Rake::Funnel::Support::Environments
include Rake::Funnel::Tasks
describe Rake::Funnel::Tasks::Environments do
include Rake::DSL
before {
Task.clear
}
+ before {
+ module Kernel
+ def configatron
+ OpenStruct.new(name: 'fake configatron singleton')
+ end
+ end
+ }
+
let(:files) { [] }
before {
allow(Dir).to receive(:[]).and_return(files)
}
@@ -26,25 +34,28 @@
its(:base_dir) { should == 'config' }
its(:default_env) { should be_nil }
its(:default_config) { should == 'default' }
its(:local_config) { should == 'local' }
+ its(:customizer) { should be_nil }
describe 'overriding defaults' do
subject {
described_class.new do |t|
t.base_dir = 'custom base_dir'
t.default_env = 'custom default_env'
t.default_config = 'custom default_config'
t.local_config = 'custom local_config'
+ t.customizer = Proc.new {}
end
}
its(:base_dir) { should == subject.base_dir }
its(:default_env) { should == subject.default_env }
its(:default_config) { should == subject.default_config }
its(:local_config) { should == subject.local_config }
+ its(:customizer) { should be_instance_of(Proc) }
end
end
describe 'definition' do
before {
@@ -77,11 +88,11 @@
let(:files) {
%w(config/dev.yaml)
}
before {
- allow(EnvironmentsSupport::Loader).to receive(:load_configuration)
+ allow(Loader).to receive(:load_configuration)
}
before {
allow(File).to receive(:exists?).and_return(true)
allow(File).to receive(:exists?).with(optional).and_return(false)
@@ -99,50 +110,95 @@
context 'default and local config files exist' do
let(:optional) { nil }
it 'should load all files' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml config/local.yaml) }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml config/local.yaml) }), any_args)
end
end
context 'default config file does not exist' do
let(:optional) { 'config/default.yaml' }
it 'should load environment file and local file' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/dev.yaml config/local.yaml) }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/dev.yaml config/local.yaml) }), any_args)
end
end
context 'local config file does not exist' do
let(:optional) { 'config/local.yaml' }
it 'should load default file and environment file' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml) }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ config_files: %w(config/default.yaml config/dev.yaml) }), any_args)
end
end
end
+ describe 'store' do
+ let(:files) {
+ %w(config/dev.yaml)
+ }
+
+ before {
+ allow(Loader).to receive(:load_configuration)
+ }
+
+ before {
+ expect(subject).to be
+ Task['dev'].invoke
+ }
+
+ it 'should store configuration in configatron singleton' do
+ expect(Loader).to have_received(:load_configuration).with(anything, configatron, any_args)
+ end
+ end
+
+ describe 'customization' do
+ let(:customizer) { Proc.new {} }
+ let(:files) {
+ %w(config/dev.yaml)
+ }
+
+ subject {
+ described_class.new do |t|
+ t.customizer = customizer
+ end
+ }
+
+ before {
+ allow(Loader).to receive(:load_configuration)
+ }
+
+ before {
+ expect(subject).to be
+ Task['dev'].invoke
+ }
+
+ it 'should pass customizer to loader' do
+ expect(Loader).to have_received(:load_configuration).with(anything, anything, customizer)
+ end
+ end
+
describe 'automatic environment setup' do
let(:files) {
%w(config/dev.yaml config/production.yaml)
}
before {
- allow(EnvironmentsSupport::Loader).to receive(:load_configuration)
+ allow(Loader).to receive(:load_configuration)
}
context 'no default environment configured' do
before {
expect(subject).to be
}
it 'should not invoke environment tasks' do
- expect(EnvironmentsSupport::Loader).not_to have_received(:load_configuration)
+ expect(Loader).not_to have_received(:load_configuration)
end
end
context 'default environment configured' do
subject {
@@ -161,31 +217,31 @@
context 'no user-defined environment' do
let(:user_defined_task) { %w(foo) }
it 'should invoke default environment task' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ name: 'dev' }), any_args)
end
it 'should not invoke other environment tasks' do
- expect(EnvironmentsSupport::Loader)
- .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }))
+ expect(Loader)
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }), any_args)
end
end
context 'user-defined environment' do
let(:user_defined_task) { %w(foo production) }
it 'should invoke user-defined environment task' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ name: 'production' }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ name: 'production' }), any_args)
end
it 'should not invoke other environment tasks' do
- expect(EnvironmentsSupport::Loader)
- .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
+ expect(Loader)
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }), any_args)
end
end
context 'environment task defined in Rake namespace' do
subject {
@@ -205,30 +261,30 @@
context 'no user-defined environment' do
let(:user_defined_task) { %w(foo) }
it 'should invoke default environment task' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ name: 'dev' }), any_args)
end
it 'should not invoke other environment tasks' do
- expect(EnvironmentsSupport::Loader)
- .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }))
+ expect(Loader)
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'production' }), any_args)
end
end
context 'user-defined environment' do
let(:user_defined_task) { %w(foo foo:bar:production) }
it 'should invoke user-defined environment task' do
- expect(EnvironmentsSupport::Loader)
- .to have_received(:load_configuration).with(hash_including({ name: 'production' }))
+ expect(Loader)
+ .to have_received(:load_configuration).with(hash_including({ name: 'production' }), any_args)
end
it 'should not invoke other environment tasks' do
- expect(EnvironmentsSupport::Loader)
- .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }))
+ expect(Loader)
+ .not_to have_received(:load_configuration).with(hash_including({ name: 'dev' }), any_args)
end
end
end
end
end