Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing custom validators with rspec. Why do I get Proc?

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!

like image 303
Marius Pop Avatar asked Nov 17 '12 18:11

Marius Pop


1 Answers

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
like image 98
Jesse Wolgamott Avatar answered Oct 18 '22 00:10

Jesse Wolgamott