As the title suggest I am trying to test a custom validator with Rspec. I get an error and I don't understand why... If you can shed some light I would really appreciate it. Here we go:
Validator spec
require 'spec_helper'
describe GraphDateValidator do
it "should not validate activity with empty start time" do
expect { Graph.new( {start_time: ''}).valid? }.to eq(false)
end
end
If I print Graph.new( {start_time: ''}).valid?
it prints false
However when it goes through the spec it returns a Proc object:
expected: false
got: #<Proc:0x007fe5853fdd48@/Users/MLP/...
Can anybody tell me why I am getting that proc object? Thank you!
By using {} in your expect, then you really aren't executing the expect method --- instead you're sending expect a block. So rename to
it "should not validate activity with empty start time" do
expect( Graph.new( {start_time: ''}).valid? ).to eq(false)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With