Sha256: 2e05a1e7dea7962ff609e4c1fa44a92aa2c29b75b2520f516452b707d1e71780
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require "spec_helper" describe HungryForm::Validator do let(:resolver) { HungryForm::Resolver.new() } let(:group) { HungryForm::Group.new(:group, nil, resolver, {}) {} } let(:element_options) { {} } let(:element) { HungryForm::TextField.new(:element_name, group, resolver, element_options) {} } describe "required" do it "should return nil when the element's value is present" do element_options[:value] = "value" expect(HungryForm::Validator.required(element, true)).to be nil end it "should return error when the element's value is not present" do element_options[:value] = "" expect(HungryForm::Validator.required(element, true)).to eq "is required" end it "should return the result of the custom required validation" do element_options[:value] = "value" expect(HungryForm::Validator.required(element, ->(el) { "not ok" if el.value != "custom" })).to eq "not ok" end end describe "validation" do it "should return the result of the custom validation" do element_options[:value] = "value" expect(HungryForm::Validator.validation(element, ->(el) { "not ok" if el.value != "custom" })).to eq "not ok" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hungryform-0.0.2 | spec/validator_spec.rb |