Sha256: ece680e27979a757ad23d1ebf7b44c73a2ab25ef8862af46f7169c5563489e0d
Contents?: true
Size: 1.98 KB
Versions: 6
Compression:
Stored size: 1.98 KB
Contents
require_relative 'spec_helper' describe "Mutations::IntegerFilter" do it "allows integers" do f = Mutations::IntegerFilter.new filtered, errors = f.filter(3) assert_equal 3, filtered assert_equal nil, errors end it "allows strings that start with a digit" do f = Mutations::IntegerFilter.new filtered, errors = f.filter("3") assert_equal 3, filtered assert_equal nil, errors end it "allows negative strings" do f = Mutations::IntegerFilter.new filtered, errors = f.filter("-3") assert_equal -3, filtered assert_equal nil, errors end it "doesnt't allow other strings, nor does it allow random objects or symbols" do f = Mutations::IntegerFilter.new ["zero","a1", {}, [], Object.new, :d].each do |thing| filtered, errors = f.filter(thing) assert_equal :integer, errors end end it "considers nil to be invalid" do f = Mutations::IntegerFilter.new(nils: false) filtered, errors = f.filter(nil) assert_equal nil, filtered assert_equal :nils, errors end it "considers nil to be valid" do f = Mutations::IntegerFilter.new(nils: true) filtered, errors = f.filter(nil) assert_equal nil, filtered assert_equal nil, errors end it "considers low numbers invalid" do f = Mutations::IntegerFilter.new(min: 10) filtered, errors = f.filter(3) assert_equal 3, filtered assert_equal :min, errors end it "considers low numbers valid" do f = Mutations::IntegerFilter.new(min: 10) filtered, errors = f.filter(31) assert_equal 31, filtered assert_equal nil, errors end it "considers high numbers invalid" do f = Mutations::IntegerFilter.new(max: 10) filtered, errors = f.filter(31) assert_equal 31, filtered assert_equal :max, errors end it "considers high numbers vaild" do f = Mutations::IntegerFilter.new(max: 10) filtered, errors = f.filter(3) assert_equal 3, filtered assert_equal nil, errors end end
Version data entries
6 entries across 6 versions & 1 rubygems