spec/dsc_spec.rb in dsc-0.0.1 vs spec/dsc_spec.rb in dsc-0.1.0
- old
+ new
@@ -7,25 +7,29 @@
File.open(config_file, 'w') do |file|
file.puts <<EOF
production:
host: 'http://www.wimdu.com'
awesome: true
+ some_inline_erb: <%= ENV['works_too'] %>
development:
host: 'http://example.com'
stable: false
number: 42
array: [1, 2, 3]
subconfig:
works: 'aswell'
EOF
end
+
+ ENV['works_too'] = "yep, it works"
end
- subject(:dsc) { Dsc.load_file(config_file, env: env) }
+ subject(:dsc) { Dsc.load_file(config_file, env: env, optional: optional) }
let(:config_file) { File.expand_path(__FILE__ + '/../../tmp/config.yml') }
let(:env) { 'development' }
+ let(:optional) { [] }
it 'works' do
expect(dsc).to have_attributes(
host: 'http://example.com',
stable: false,
@@ -42,16 +46,45 @@
Dsc::UndefinedAttribute,
/awesome is not defined/
)
end
+ context "when there are optional attributes" do
+ let(:optional) { %i(awesome) }
+
+ it "does not raise error when trying to access undefined but optional attribute" do
+ expect(dsc.awesome).to eq(nil)
+ end
+ end
+
context 'with env production' do
let(:env) { 'production' }
it 'provides the production stuff' do
expect(dsc).to have_attributes(
host: 'http://www.wimdu.com',
awesome: true
+ )
+ end
+
+ context "when there are optional attributes" do
+ let(:optional) { %i(awesome) }
+
+ it "provides these attributes properly" do
+ expect(dsc).to have_attributes(
+ host: 'http://www.wimdu.com',
+ awesome: true
+ )
+ end
+ end
+ end
+
+ describe 'ERB parsing' do
+ let(:env) { 'production' }
+
+ it 'works' do
+ expect(dsc).to have_attributes(
+ some_inline_erb: 'yep, it works'
)
end
end
end
end