spec/egi_spec.rb in egi-0.0.2 vs spec/egi_spec.rb in egi-0.0.3
- old
+ new
@@ -12,124 +12,131 @@
end
diffable
end
+shared_examples_for :sample_environments do
+ context 'makes env1' do
+ subject { described_class[:env1] }
+
+ it { should have_item(:a, :hoge => :fuga) }
+ it { should have_item(:b, :fuga => :ugu) }
+ end
+
+ context 'makes env_group' do
+ subject { described_class[:env_group] }
+ it { should have_item(:a, :hoge => :fuga, :tags => [ :hoge ]) }
+ it { should have_item(:b, :tags => [ :hoge, :fuga ]) }
+ end
+
+ context 'makes env2' do
+ subject { described_class[:env2] }
+
+ it { should have_item(:a, :hoge => :ugu) }
+ its(:b) { should be_nil }
+ end
+
+ context 'makes loaded_env1 which loads env1' do
+ subject { described_class[:loaded_env1] }
+
+ it { should have_item(:a, :hoge => :ugu) }
+ it { should have_item(:b, :fuga => :ugu) }
+ end
+
+ context 'makes env with default' do
+ subject { described_class[:env_with_default] }
+
+ it { should have_item(:a, :hoge => :ugu) }
+ it { should have_item(:b, :hoge => :fuga) }
+ it { should have_item(:c, :hoge => :piyo, :tags => []) }
+ it { should have_item(:d, :hoge => :puyo, :tags => []) }
+ end
+
+ context 'does not make env3' do
+ subject { described_class[:env3] }
+ it { should be_nil }
+ end
+end
+
describe klass, '.load environments:' do
environments = <<-EOS
env(:env1) {
- item :a, { :hoge => :fuga }
- item :b, { :fuga => :ugu }
+ item :a, :hoge => :fuga
+ item :b, :fuga => :ugu
}
+env(:env_group) {
+ group(:hoge) {
+ item :a, :hoge => :fuga
+ item :b, :tags => [ :fuga ]
+ }
+}
+
env(:env2) {
- item :a, { :hoge => :ugu }
+ item :a, :hoge => :ugu
}
-env(:env_group) {
- group(:hoge) {
- item :a, { :hoge => :fuga }
- item :b, { :tags => [ :fuga ] }
+env(:loaded_env1, :load => :env1) {
+ item :a, :hoge => :ugu
+}
+
+env(:env_with_default) {
+ set :hoge => :ugu
+
+ item :a
+ item :b, :hoge => :fuga
+
+ group {
+ set :hoge => :piyo
+
+ item :c
+ item :d, :hoge => :puyo
}
}
EOS
context "\n#{environments}" do
before(:all) { described_class.load(environments) }
after(:all) { described_class.reset }
- context 'makes env1' do
- subject { described_class[:env1] }
-
- it { should have_item(:a, :hoge => :fuga) }
- it { should have_item(:b, :fuga => :ugu) }
- end
-
- context 'makes env2' do
- subject { described_class[:env2] }
-
- it { should have_item(:a, :hoge => :ugu) }
- its(:b) { should be_nil }
- end
-
- context 'makes env_group' do
- subject { described_class[:env_group] }
- it { should have_item(:a, :hoge => :fuga, :tags => [ :hoge ]) }
- it { should have_item(:b, :tags => [ :hoge, :fuga ]) }
- end
-
- context 'does not make env3' do
- subject { described_class[:env3] }
- it { should be_nil }
- end
+ it_should_behave_like :sample_environments
end
end
-describe klass, '.load environments:' do
+describe klass, '.load flat environments:' do
environments = <<-EOS
env :env1
-item :a, { :hoge => :fuga }
-item :b, { :fuga => :ugu }
+item :a, :hoge => :fuga
+item :b, :fuga => :ugu
+env :env_group
+group(:hoge) {
+ item :a, :hoge => :fuga
+ item :b, :tags => [ :fuga ]
+}
+
env :env2
-item :a, { :hoge => :ugu }
- EOS
+item :a, :hoge => :ugu
- context "\n#{environments}" do
- before(:all) { described_class.load(environments) }
- after(:all) { described_class.reset }
-
- context 'makes env1' do
- subject { described_class[:env1] }
-
- it { should have_item(:a, :hoge => :fuga) }
- it { should have_item(:b, :fuga => :ugu) }
- end
+env :loaded_env1, :load => :env1
+item :a, :hoge => :ugu
- context 'makes env2' do
- subject { described_class[:env2] }
+env :env_with_default
+set :hoge => :ugu
- it { should have_item(:a, :hoge => :ugu) }
- its(:b) { should be_nil }
- end
+item :a
+item :b, :hoge => :fuga
+group {
+ set :hoge => :piyo
- context 'does not make env3' do
- subject { described_class[:env3] }
- it { should be_nil }
- end
- end
-end
-
-describe klass, '.load environments using load to inherit default:' do
- environments = <<-EOS
-env :env1
-item :a, { :hoge => :fuga }
-item :b, { :fuga => :ugu }
-
-env :env2, :load => :env1
-item :a, { :hoge => :ugu }
+ item :c
+ item :d, :hoge => :puyo
+}
EOS
context "\n#{environments}" do
before(:all) { described_class.load(environments) }
after(:all) { described_class.reset }
- context 'makes env1' do
- subject { described_class[:env1] }
-
- it { should have_item(:a, :hoge => :fuga) }
- it { should have_item(:b, :fuga => :ugu) }
- end
-
- context 'makes env2' do
- subject { described_class[:env2] }
-
- it { should have_item(:a, :hoge => :ugu) }
- it { should have_item(:b, :fuga => :ugu) }
- end
-
- context 'does not make env3' do
- subject { described_class[:env3] }
- it { should be_nil }
- end
+ it_should_behave_like :sample_environments
end
end