Please review pull request #724: Cleanup some dumb tests in settings specs opened by (cprice-puppet)

Description:

Patrick found a few things in the settings_spec tests that
weren't really testing what they claimed to be. Minor
fixes to account for those.

  • Opened: Thu Apr 26 21:59:33 UTC 2012
  • Based on: puppetlabs:master (d63ca26332d3f93e7cdd1b357e1e246755b21bff)
  • Requested merge: cprice-puppet:cleanup/master/bad-settings-specs (79561e19d6f311d1ab19e86683840fd1610db1e5)

Diff follows:

diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index 5558cf8..669edb1 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -646,7 +646,7 @@ def set_value(param, value, type, options = {})
 
     value = setting.munge(value) if setting.respond_to?(:munge)
     setting.handle(value) if setting.respond_to?(:handle) and not options[:dont_trigger_handles]
-    if ReadOnly.include? param and type != :application_defaults
+    if read_only_settings.include? param and type != :application_defaults
       raise ArgumentError,
         "You're attempting to set configuration parameter $#{param}, which is read-only."
     end
@@ -971,6 +971,11 @@ def readwritelock(default, *args, &bloc)
 
   private
 
+  # This is just here to simplify testing.  This method can be stubbed easily.  Constants can't.
+  def read_only_settings()
+    ReadOnly
+  end
+
   def get_config_file_default(default)
     obj = nil
     unless obj = @config[default]
diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb
index 57f94f4..1a9b0b8 100755
--- a/spec/unit/util/settings_spec.rb
+++ b/spec/unit/util/settings_spec.rb
@@ -264,8 +264,19 @@
       @settings[:myval] = "memarg"
     end
 
-    it "should raise an error if we try to set 'run_mode'" do
-      lambda{ @settings[:run_mode] = "foo" }.should raise_error(ArgumentError)
+    it "should raise an error if we try to set a setting that hasn't been defined'" do
+      lambda{
+        @settings[:why_so_serious] = "foo"
+      }.should raise_error(ArgumentError, /unknown configuration parameter/)
+    end
+
+    it "should raise an error if we try to set a setting that is read-only (which, really, all of our settings probably should be)" do
+      @settings.define_settings(:section, :_one_ => { :default => "test", :desc => "a" })
+      @settings.expects(:read_only_settings).returns([:one])
+
+      lambda{
+        @settings[:one] = "foo"
+      }.should raise_error(ArgumentError, /read-only/)
     end
 
     it "should warn and use [master] if we ask for [puppetmasterd]" do

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to