Hello everyone,

I added a new instance method in Sequel::Plugins::ValidationHelpers and I 
am trying to have specs for it. I checked out it is done for the other 
methods in the specs of the Sequel project. Here's my code:

module Sequel::Plugins::ValidationHelpers
    module InstanceMethods
        # PARAMS (Integer, Symbol)
        def validates_greater_than(value, column)
            column = send(column)

            if column.is_a? Integer
                if column <= value
                    errors.add(column, "must be greater than #{value}")
                end
            else
                errors.add(column, "must be of type Integer to be validated"
)
            end
        end
    end
end


Then my specs:

spec_helper.rb

ENV["RACK_ENV"] = "test"

require "bundler"
Bundler.require :default, :test

require "rack/test"
require "minitest/autorun"

# TODO Check if the app lines are needed only for routes spec... then 
transfer them or not
# Load the Sinatra application
require_relative "../app.rb"

include Rack::Test::Methods

def app
    BDV_App
end


sequel_plugins_validationhelpers_spec.rb
require_relative "../spec_helper"

describe "Sequel::Plugins::ValidationHelpers" do
    before do
        @c = Class.new(Sequel::Model) do
                def self.set_validations(&block)
                    define_method(:validate, &block)
                end

                columns :value
             end
        @c.plugin :validation_helpers
        @m = @c.new
    end

    describe "#validates_greater_than" do
        describe "a column which is of type Integer" do
            describe "having a value smaller than the value received" do

            end

            describe "having a value equal to the value received" do

            end

            describe "having a value greater than the value received" do

            end
        end

        describe "a column which isn't of type Integer" do
            it "must not be valid" do

            end
        end
    end
end


My problem is that I keep getting an error when running my tests. This is 
the error I get:

Sequel::Plugins::ValidationHelpers::#validates_greater_than::a column which 
isn't of type Integer#test_0001_must not be valid:
ArgumentError: wrong number of arguments (1 for 0)
    /home/dany/.rvm/gems/ruby-2.2.1/gems/sequel-4.24.0/lib/sequel/model/base
.rb:135:in `columns'
    
/home/dany/projets/bdv/spec/lib/sequel_plugins_validationhelpers_spec.rb:10:in 
`block (3 levels) in <top (required)>'
    
/home/dany/projets/bdv/spec/lib/sequel_plugins_validationhelpers_spec.rb:5:in 
`initialize'
    /home/dany/projets/bdv/spec/lib/sequel_plugins_validationhelpers_spec.rb
:5:in `new'
    
/home/dany/projets/bdv/spec/lib/sequel_plugins_validationhelpers_spec.rb:5:in 
`block (2 levels) in <top (required)>'



What would be the best way to test my new instance method? Am I doing too 
much by trying to replicate the specs in the Sequel project?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to