diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-12 09:17:39 -0800 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-08-11 12:03:37 +0100 |
commit | a56dd9b0d45cc78edcf813835e43b8433851ac42 (patch) | |
tree | 89210f041eb3efe7d49596462310b3377f4fe84e | |
parent | 05db78c270ef91d17cd79e347502a021805a43ed (diff) | |
download | mixlib-config-a56dd9b0d45cc78edcf813835e43b8433851ac42.tar.gz |
chefstyle fixes
-rw-r--r-- | Rakefile | 18 | ||||
-rw-r--r-- | features/steps/config_steps.rb | 23 | ||||
-rw-r--r-- | features/support/config_it.rb | 12 | ||||
-rw-r--r-- | features/support/env.rb | 14 | ||||
-rw-r--r-- | lib/mixlib/config.rb | 16 | ||||
-rw-r--r-- | mixlib-config.gemspec | 15 | ||||
-rw-r--r-- | spec/mixlib/config_spec.rb | 74 | ||||
-rw-r--r-- | spec/spec_helper.rb | 8 |
8 files changed, 89 insertions, 91 deletions
@@ -1,8 +1,8 @@ -require 'bundler' -require 'rubygems' -require 'rubygems/package_task' -require 'rdoc/task' -require 'rspec/core/rake_task' +require "bundler" +require "rubygems" +require "rubygems/package_task" +require "rdoc/task" +require "rspec/core/rake_task" Bundler::GemHelper.install_tasks @@ -10,14 +10,14 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = 'spec/**/*_spec.rb' + spec.pattern = "spec/**/*_spec.rb" end gem_spec = eval(File.read("mixlib-config.gemspec")) RDoc::Task.new do |rdoc| - rdoc.rdoc_dir = 'rdoc' + rdoc.rdoc_dir = "rdoc" rdoc.title = "mixlib-config #{gem_spec.version}" - rdoc.rdoc_files.include('README*') - rdoc.rdoc_files.include('lib/**/*.rb') + rdoc.rdoc_files.include("README*") + rdoc.rdoc_files.include("lib/**/*.rb") end diff --git a/features/steps/config_steps.rb b/features/steps/config_steps.rb index 0785af3..4fece40 100644 --- a/features/steps/config_steps.rb +++ b/features/steps/config_steps.rb @@ -6,9 +6,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,13 +22,13 @@ end When /^I set '(.+)' to '(.+)' in configuration class '(.+)'$/ do |key, value, classname| #ConfigIt[key.to_sym] = value - if classname == 'ConfigIt' + if classname == "ConfigIt" ConfigIt[key.to_sym] = value - elsif classname == 'ConfigItToo' + elsif classname == "ConfigItToo" ConfigItToo[key.to_sym] = value else raise ArgumentError, "configuration class must be ConfigIt or ConfigItToo" - end + end end Then /^config option '(.+)' is '(.+)'$/ do |key, value| @@ -36,19 +36,19 @@ Then /^config option '(.+)' is '(.+)'$/ do |key, value| end Then /^in configuration class '(.+)' config option '(.+)' is '(.+)'$/ do |classname, key, value| - if classname == 'ConfigIt' - ConfigIt[key.to_sym].should == value - elsif classname == 'ConfigItToo' - ConfigItToo[key.to_sym].should == value + if classname == "ConfigIt" + ConfigIt[key.to_sym].should == value + elsif classname == "ConfigItToo" + ConfigItToo[key.to_sym].should == value else raise ArgumentError, "configuration class must be ConfigIt or ConfigItToo" - end + end end When /^I set '(.+)' to:$/ do |key, foo_table| ConfigIt[key.to_sym] = Array.new foo_table.hashes.each do |hash| - ConfigIt[key.to_sym] << hash['key'] + ConfigIt[key.to_sym] << hash["key"] end end @@ -63,4 +63,3 @@ end When /^I load the configuration$/ do ConfigIt.from_file(@config_file) end - diff --git a/features/support/config_it.rb b/features/support/config_it.rb index c872e33..37b692a 100644 --- a/features/support/config_it.rb +++ b/features/support/config_it.rb @@ -6,9 +6,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,13 +16,13 @@ # limitations under the License. # -$: << File.join(File.dirname(__FILE__), '..', '..', 'lib') -require 'mixlib/config' +$: << File.join(File.dirname(__FILE__), "..", "..", "lib") +require "mixlib/config" class ConfigIt - extend Mixlib::Config + extend Mixlib::Config end class ConfigItToo extend Mixlib::Config -end
\ No newline at end of file +end diff --git a/features/support/env.rb b/features/support/env.rb index a49da26..b51308d 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -6,9 +6,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,12 +16,12 @@ # limitations under the License. # -$: << File.join(File.dirname(__FILE__), '..', '..', 'lib') +$: << File.join(File.dirname(__FILE__), "..", "..", "lib") -require 'rspec/expectations' -require 'mixlib/config' -require 'tmpdir' -require 'stringio' +require "rspec/expectations" +require "mixlib/config" +require "tmpdir" +require "stringio" class MyWorld end diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index 07e9809..d58ed9f 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -18,11 +18,11 @@ # limitations under the License. # -require 'mixlib/config/version' -require 'mixlib/config/configurable' -require 'mixlib/config/unknown_config_option_error' -require 'mixlib/config/reopened_config_context_with_configurable_error' -require 'mixlib/config/reopened_configurable_with_config_context_error' +require "mixlib/config/version" +require "mixlib/config/configurable" +require "mixlib/config/unknown_config_option_error" +require "mixlib/config/reopened_config_context_with_configurable_error" +require "mixlib/config/reopened_configurable_with_config_context_error" module Mixlib module Config @@ -408,7 +408,7 @@ module Mixlib # symbol<Symbol>:: Name of the method (variable setter) # value<Object>:: Value to be set in config hash # - def internal_set(symbol,value) + def internal_set(symbol, value) if configurables.has_key?(symbol) configurables[symbol].set(self.configuration, value) elsif config_contexts.has_key?(symbol) @@ -438,7 +438,7 @@ module Mixlib end end - def internal_get_or_set(symbol,*args) + def internal_get_or_set(symbol, *args) num_args = args.length # Setting if num_args > 0 @@ -453,7 +453,7 @@ module Mixlib # When Ruby 1.8.7 is no longer supported, this stuff can be done with define_singleton_method! meta = class << self; self; end # Setter - meta.send :define_method, "#{symbol.to_s}=".to_sym do |value| + meta.send :define_method, "#{symbol}=".to_sym do |value| internal_set(symbol, value) end # Getter diff --git a/mixlib-config.gemspec b/mixlib-config.gemspec index c1a2cfa..339f0dd 100644 --- a/mixlib-config.gemspec +++ b/mixlib-config.gemspec @@ -1,8 +1,7 @@ # -*- encoding: utf-8 -*- -$:.unshift(File.dirname(__FILE__) + '/lib') -require 'mixlib/config/version' - +$:.unshift(File.dirname(__FILE__) + "/lib") +require "mixlib/config/version" Gem::Specification.new do |s| s.name = "mixlib-config" @@ -12,10 +11,10 @@ Gem::Specification.new do |s| s.email = "legal@chef.io" s.extra_rdoc_files = [ "LICENSE", - "README.md" + "README.md", ] s.files = [ "LICENSE", "NOTICE", "README.md", "Gemfile", "Rakefile" ] + Dir.glob("*.gemspec") + - Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } + Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) } s.homepage = "http://www.chef.io" s.require_paths = ["lib"] s.rubygems_version = "1.8.23" @@ -23,7 +22,7 @@ Gem::Specification.new do |s| s.description = s.summary s.license = "Apache-2.0" - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec', '~> 2.99' - s.add_development_dependency 'rdoc' + s.add_development_dependency "rake" + s.add_development_dependency "rspec", "~> 2.99" + s.add_development_dependency "rdoc" end diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb index 9f9e320..4b287d1 100644 --- a/spec/mixlib/config_spec.rb +++ b/spec/mixlib/config_spec.rb @@ -21,7 +21,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) describe Mixlib::Config do before(:each) do ConfigIt.configure do |c| - c[:alpha] = 'omega' + c[:alpha] = "omega" c[:foo] = nil end end @@ -29,9 +29,9 @@ describe Mixlib::Config do it "should load a config file" do File.stub(:exists?).and_return(true) File.stub(:readable?).and_return(true) - IO.stub(:read).with('config.rb').and_return("alpha = 'omega'\nfoo = 'bar'") + IO.stub(:read).with("config.rb").and_return("alpha = 'omega'\nfoo = 'bar'") lambda { - ConfigIt.from_file('config.rb') + ConfigIt.from_file("config.rb") }.should_not raise_error end @@ -48,18 +48,18 @@ describe Mixlib::Config do end it "should allow the error to bubble up when it's anything other than IOError" do - IO.stub(:read).with('config.rb').and_return("@#asdf") + IO.stub(:read).with("config.rb").and_return("@#asdf") lambda { - ConfigIt.from_file('config.rb') + ConfigIt.from_file("config.rb") }.should raise_error(SyntaxError) end it "should allow you to reference a value by index" do - ConfigIt[:alpha].should == 'omega' + ConfigIt[:alpha].should == "omega" end it "should allow you to reference a value by string index" do - ConfigIt['alpha'].should == 'omega' + ConfigIt["alpha"].should == "omega" end it "should allow you to set a value by index" do @@ -68,7 +68,7 @@ describe Mixlib::Config do end it "should allow you to set a value by string index" do - ConfigIt['alpha'] = "one" + ConfigIt["alpha"] = "one" ConfigIt[:alpha].should == "one" end @@ -122,7 +122,7 @@ describe Mixlib::Config do ConfigIt.configure { |c| c[:cookbook_path] = "monkey_rabbit"; c[:otherthing] = "boo" } end - {:cookbook_path => "monkey_rabbit", :otherthing => "boo"}.each do |k,v| + { :cookbook_path => "monkey_rabbit", :otherthing => "boo" }.each do |k, v| it "should allow you to retrieve the config value for #{k} via []" do ConfigIt[k].should == v end @@ -169,8 +169,8 @@ describe Mixlib::Config do end it "should multiply an integer by 1000 via from-file, too" do - IO.stub(:read).with('config.rb').and_return("test_method 99") - @klass.from_file('config.rb') + IO.stub(:read).with("config.rb").and_return("test_method 99") + @klass.from_file("config.rb") @klass.test_method.should == 99000 end @@ -226,18 +226,18 @@ describe Mixlib::Config do Object.send :remove_method, :'daemonizeme=' end - it 'Normal classes call the extra method' do + it "Normal classes call the extra method" do normal_class = Class.new normal_class.extend(::Mixlib::Config) lambda { normal_class.daemonizeme }.should raise_error(NopeError) end - it 'Configurables with the same name as the extra method can be set' do + it "Configurables with the same name as the extra method can be set" do @klass.daemonizeme = 10 @klass[:daemonizeme].should == 10 end - it 'Configurables with the same name as the extra method can be retrieved' do + it "Configurables with the same name as the extra method can be retrieved" do @klass[:daemonizeme] = 10 @klass.daemonizeme.should == 10 end @@ -309,7 +309,7 @@ describe Mixlib::Config do @klass.extend(::Mixlib::Config) @klass.class_eval do default :x, 4 - default(:attr) { x*2 } + default(:attr) { x * 2 } end end @@ -379,8 +379,8 @@ describe Mixlib::Config do end it "reset clears it to its default" do - @klass.attr << 'x' - @klass.attr.should == [ 'x' ] + @klass.attr << "x" + @klass.attr.should == [ "x" ] @klass.reset @klass.attr.should == [] end @@ -394,12 +394,12 @@ describe Mixlib::Config do end it "save should save the new value if it gets set" do - @klass.attr << 'x' - (saved = @klass.save).should == { :attr => [ 'x' ] } + @klass.attr << "x" + (saved = @klass.save).should == { :attr => [ "x" ] } @klass.reset @klass.attr.should == [] @klass.restore(saved) - @klass.attr.should == [ 'x' ] + @klass.attr.should == [ "x" ] end it "save should save the new value even if it is set to its default value" do @@ -435,12 +435,12 @@ describe Mixlib::Config do end it "save should save the new value if it gets set" do - @klass.attr[:hi] = 'lo' - (saved = @klass.save).should == { :attr => { :hi => 'lo' } } + @klass.attr[:hi] = "lo" + (saved = @klass.save).should == { :attr => { :hi => "lo" } } @klass.reset @klass.attr.should == {} @klass.restore(saved) - @klass.save.should == { :attr => { :hi => 'lo' } } + @klass.save.should == { :attr => { :hi => "lo" } } end it "save should save the new value even if it is set to its default value" do @@ -457,14 +457,14 @@ describe Mixlib::Config do before :each do @klass = Class.new @klass.extend(::Mixlib::Config) - @klass.class_eval { default :attr, 'hello' } + @klass.class_eval { default :attr, "hello" } end it "reset clears it to its default" do - @klass.attr << ' world' - @klass.attr.should == 'hello world' + @klass.attr << " world" + @klass.attr.should == "hello world" @klass.reset - @klass.attr.should == 'hello' + @klass.attr.should == "hello" end it "save should not save anything for it" do @@ -472,25 +472,25 @@ describe Mixlib::Config do end it "save with include_defaults should save all defaults" do - @klass.save(true).should == { :attr => 'hello' } + @klass.save(true).should == { :attr => "hello" } end it "save should save the new value if it gets set" do - @klass.attr << ' world' - (saved = @klass.save).should == { :attr => 'hello world' } + @klass.attr << " world" + (saved = @klass.save).should == { :attr => "hello world" } @klass.reset - @klass.attr.should == 'hello' + @klass.attr.should == "hello" @klass.restore(saved) - @klass.attr.should == 'hello world' + @klass.attr.should == "hello world" end it "save should save the new value even if it is set to its default value" do - @klass.attr 'hello world' - (saved = @klass.save).should == { :attr => 'hello world' } + @klass.attr "hello world" + (saved = @klass.save).should == { :attr => "hello world" } @klass.reset @klass.save.should == {} @klass.restore(saved) - @klass.save.should == { :attr => 'hello world' } + @klass.save.should == { :attr => "hello world" } end end @@ -563,7 +563,7 @@ describe Mixlib::Config do @klass.class_eval do configurable(:attr) do |c| c.defaults_to(4) - c.writes_value { |value| value*2 } + c.writes_value { |value| value * 2 } end end end @@ -638,7 +638,7 @@ describe Mixlib::Config do @klass = Class.new @klass.extend(::Mixlib::Config) @klass.class_eval do - configurable(:attr).defaults_to(4).writes_value { |value| value*2 } + configurable(:attr).defaults_to(4).writes_value { |value| value * 2 } end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 94f59ab..bbe80e0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,8 @@ -$TESTING=true -$:.push File.join(File.dirname(__FILE__), '..', 'lib') +$TESTING = true +$:.push File.join(File.dirname(__FILE__), "..", "lib") -require 'rspec' -require 'mixlib/config' +require "rspec" +require "mixlib/config" class ConfigIt extend Mixlib::Config |