bcardarella / valid_attribute

Minimalist validation BDD for ActiveModel specs
178 stars 18 forks source link

What am I missing? #18

Closed bryanrite closed 12 years ago

bryanrite commented 12 years ago

I'm not sure if this is a bug, but I have the following issue:

I have a very basic setup:

class Book < ActiveRecord::Base
  belongs_to :customer
  validates :customer_id, presence: true
end

And in my RSpec file:

subject { Book.new, :customer_id => 2 }

it "works" do
  subject.customer_id = nil
  subject.should_not have_valid(:customer_id)
end

But the following doesn't work:

it { should_not have_valid(:customer_id).when(nil) }

I get the error:

expected Book#customer_id to reject the value: nil

As I understand it, they should be the same? Am I missing something?

Thanks in advance!

bcardarella commented 12 years ago

Is this the exact model you have? I just tried to recreate this issue and (I hate when people say this) it works for me. Clearly, it's not working for you. Can you provide more information, or even better, an example app demonstrating the problem?

bryanrite commented 12 years ago

Hi Brian, what I provided here does work, but the same code within the project does not, so there is a conflict with the project somewhere, on first glance it might be another testing gem. I'm going to try and isolate what is causing the issue and I will let you know or submit a pull request.

bcardarella commented 12 years ago

Yes, please let me know if you discover a conflict. Thank-you

bcardarella commented 12 years ago

In the mean time I'm going to close this issue. Please open another if you discover the source of the conflict.