X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Funit%2Fvalidator_spec.rb;fp=spec%2Funit%2Fvalidator_spec.rb;h=73c1bf5c3028dbbf0a69392f7fe1331c45ee8529;hb=b87d2f4e68281062df1913440ca5753ae63314a9;hp=0000000000000000000000000000000000000000;hpb=ab0ea530b8ac956091f17b104ab2311336cfc250;p=packages%2Fprecise%2Fmcollective.git diff --git a/spec/unit/validator_spec.rb b/spec/unit/validator_spec.rb new file mode 100644 index 0000000..73c1bf5 --- /dev/null +++ b/spec/unit/validator_spec.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env rspec + +require 'spec_helper' +require File.dirname(__FILE__) + '/../../plugins/mcollective/validator/array_validator.rb' + +module MCollective + module Validator + describe "#load_validators" do + it "should not reload the plugins if the plugin cache has not expired" do + Validator.instance_variable_set(:@last_load, nil) + PluginManager.expects(:find_and_load).with("validator").once + Validator.load_validators + Validator.load_validators + end + end + + describe "#[]" do + before do + Validator.load_validators + end + + it "should return the correct class if klass is given as klass" do + result = Validator["array"] + result.should == ArrayValidator + end + it "should return the correct class if klass is given as KlassValidator" do + result = Validator["ArrayValidator"] + result.should == ArrayValidator + end + it "should return the correct class if klass is given as :klass" do + result = Validator[:array] + result.should == ArrayValidator + end + end + + describe "#method_missing" do + it "should load a plugin if a validator method is called and the plugin exists" do + ArrayValidator.expects(:validate).with(2, [1,2,3]) + result = Validator.array(2,[1,2,3]) + end + + it "should call super if a validator method is called and the plugin does not exist" do + expect{ + Validator.rspec(1,2,3) + }.to raise_error(ValidatorError) + end + end + + describe "#validator_class" do + it "should return the correct string for a given validator plugin name" do + result = Validator.validator_class("test") + result.should == "TestValidator" + end + end + + describe "#has_validator?" do + it "should return true if the validator has been loaded" do + Validator.const_set(:TestValidator, Class) + Validator.has_validator?("test").should == true + end + + it "should return false if the validator has not been loaded" do + Validator.has_validator?("test2").should == false + end + end + end +end