248d29e0249fa40e4b5936298a19ca6dfa599da2
[packages/precise/mcollective.git] / spec / unit / plugins / mcollective / validator / typecheck_validator_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3 require File.dirname(__FILE__) + '/../../../../../plugins/mcollective/validator/typecheck_validator.rb'
4
5 module MCollective
6   module Validator
7     describe "#validate" do
8       it "should raise an exception if the given value is not of the supplied type" do
9         [[1, String], ['test', :integer], ['test', :float], ['test', :number], [1, :string], ['test', :boolean]].each do |val|
10           expect{
11             TypecheckValidator.validate(*val)
12           }.to raise_error(ValidatorError, "value should be a #{val[1].to_s}")
13         end
14       end
15
16       it "should not raise an exception if the given value is of the supplied type" do
17         [["test", String], [1, :integer], [1.2, :float], [1, :number], ["test", :string], [true, :boolean]].each do |val|
18           TypecheckValidator.validate(*val)
19         end
20       end
21     end
22   end
23 end