4 require File.dirname(__FILE__) + '/../../plugins/mcollective/validator/array_validator.rb'
8 describe "#load_validators" do
9 it "should not reload the plugins if the plugin cache has not expired" do
10 Validator.instance_variable_set(:@last_load, nil)
11 PluginManager.expects(:find_and_load).with("validator").once
12 Validator.load_validators
13 Validator.load_validators
19 Validator.load_validators
22 it "should return the correct class if klass is given as klass" do
23 result = Validator["array"]
24 result.should == ArrayValidator
26 it "should return the correct class if klass is given as KlassValidator" do
27 result = Validator["ArrayValidator"]
28 result.should == ArrayValidator
30 it "should return the correct class if klass is given as :klass" do
31 result = Validator[:array]
32 result.should == ArrayValidator
36 describe "#method_missing" do
37 it "should load a plugin if a validator method is called and the plugin exists" do
38 ArrayValidator.expects(:validate).with(2, [1,2,3])
39 result = Validator.array(2,[1,2,3])
42 it "should call super if a validator method is called and the plugin does not exist" do
44 Validator.rspec(1,2,3)
45 }.to raise_error(ValidatorError)
49 describe "#validator_class" do
50 it "should return the correct string for a given validator plugin name" do
51 result = Validator.validator_class("test")
52 result.should == "TestValidator"
56 describe "#has_validator?" do
57 it "should return true if the validator has been loaded" do
58 Validator.const_set(:TestValidator, Class)
59 Validator.has_validator?("test").should == true
62 it "should return false if the validator has not been loaded" do
63 Validator.has_validator?("test2").should == false