diff options
author | Dan Bode <dan@puppetlabs.com> | 2013-04-01 17:27:10 -0700 |
---|---|---|
committer | Dan Bode <dan@puppetlabs.com> | 2013-04-01 17:27:10 -0700 |
commit | f48cae87a091ef5c8759a6c0006686bda539ece1 (patch) | |
tree | 3f20433323eb6bd52458335c32cc41c244db63d2 | |
parent | 5fdca54f6e96c861502d6fcff85a563be9d36fa0 (diff) | |
download | puppet-inifile-f48cae87a091ef5c8759a6c0006686bda539ece1.tar.gz puppet-inifile-f48cae87a091ef5c8759a6c0006686bda539ece1.tar.bz2 |
fix unit test failures
the previous tests were stubbing global class instances
in a way that was causing other tests to fail.
This commit updates the tests, and introdcuces child classes which
can safely be stubbed (and more closely test the real behavior intended to
be tested here)
-rw-r--r-- | spec/unit/puppet/provider/ini_setting/ruby_spec.rb | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 7204f88..2ad64b8 100644 --- a/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -36,19 +36,28 @@ describe provider_class do it 'should fail when file path is not set' do expect { - described_class.instances + provider_class.instances }.to raise_error(Puppet::Error, 'Ini_settings only support collecting instances when a file path is hard coded') end - context 'when file path is set' do + context 'when file path is set by a child class' do it 'should return [] when file is empty' do - provider_class.stubs(:file_path).returns(emptyfile) - provider_class.instances.should == [] + child_one = Class.new(provider_class) do + def self.file_path + emptyfile + end + end + child_one.stubs(:file_path).returns(emptyfile) + child_one.instances.should == [] end it 'should override the provider instances file_path' do - provider_class.stubs(:file_path).returns('/some/file/path') + child_two = Class.new(provider_class) do + def self.file_path + '/some/file/path' + end + end resource = Puppet::Type::Ini_setting.new(common_params) - provider = provider_class.new(resource) + provider = child_two.new(resource) provider.file_path.should == '/some/file/path' end context 'when file has contecnts' do @@ -74,8 +83,13 @@ subby=bar } it 'should be able to parse the results' do - provider_class.stubs(:file_path).returns(tmpfile) - provider_class.instances.size == 7 + child_three = Class.new(provider_class) do + def self.file_path + '/some/file/path' + end + end + child_three.stubs(:file_path).returns(tmpfile) + child_three.instances.size == 7 expected_array = [ {:name => 'section1/foo', :value => 'foovalue' }, {:name => 'section1/bar', :value => 'barvalue' }, @@ -87,14 +101,12 @@ subby=bar ] real_array = [] ensure_array = [] - provider_class.instances.each do |x| + child_three.instances.each do |x| prop_hash = x.instance_variable_get(:@property_hash) ensure_value = prop_hash.delete(:ensure) ensure_array.push(ensure_value) real_array.push(prop_hash) end - puts ensure_array.inspect - puts real_array.inspect ensure_array.uniq.should == [:present] ((real_array - expected_array) && (expected_array - real_array)).should == [] |