Permalink
Browse files

Use temp files for yaml file specs.

  • Loading branch information...
1 parent 8d216ab commit 83641e657cc2febf584034ad7767013e139ef3ef @spraints committed Nov 18, 2011
View
@@ -5,6 +5,5 @@ guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
- watch(%r{(spec/.+_spec\.rb)\.*}) { |m| m[1] }
end
@@ -1,34 +1,50 @@
require 'spec_helper'
require 'static_config/reader/yaml_file'
+require 'tempfile'
describe StaticConfig::Reader::YamlFile do
let(:subject) { described_class.read(opts) }
- def opts ; { :file => "#{__FILE__}.yml" } ; end
- it('loads the yaml') { should == { 'dev' => { 'key' => 'value' } } }
+ let(:file) { Tempfile.new('static_config_specs').tap { |f| f.write(yaml) ; f.close } }
+ let(:base_opts) { { :file => file.path } }
+
+ let(:opts) { base_opts }
+ let(:yaml) { BASIC_YAML }
+ it('loads the yaml') { should == { 'key' => 'value' } }
context 'with section' do
- def opts ; super.merge :section => 'dev' ; end
+ let(:yaml) { YAML_WITH_DEV }
+ let(:opts) { base_opts.merge :section => 'dev' }
it('uses the section') { should == { 'key' => 'value' } }
end
context 'with a section that does not exist' do
- def opts ; super.merge :section => 'bad' ; end
+ let(:yaml) { YAML_WITH_DEV }
+ let(:opts) { base_opts.merge :section => 'notthere' }
it('is empty') { should == {} }
end
context 'with an empty file' do
- def opts ; { :file => "#{__FILE__}.empty" } ; end
+ let(:yaml) { '' }
it('is empty') { should == {} }
context 'and a section' do
- def opts ; super.merge :section => 'section' ; end
+ let(:opts) { base_opts.merge :section => 'section' }
it('is empty') { should == {} }
end
end
context 'with a file that does not exist' do
- def opts ; { :file => "#{__FILE__}.does.not.exist" } ; end
+ let(:opts) { { :file => "/does/not/exist" } }
it('is empty') { should == {} }
end
+
+ BASIC_YAML = <<END_BASIC_YAML
+key: value
+END_BASIC_YAML
+
+ YAML_WITH_DEV = <<END_YAML_WITH_DEV
+dev:
+ key: value
+END_YAML_WITH_DEV
end
@@ -1,2 +0,0 @@
-dev:
- key: value

0 comments on commit 83641e6

Please sign in to comment.