jdliss / shoulda-callback-matchers

Test existence of your Rails callbacks without having to call them
MIT License
134 stars 18 forks source link

With Condition Not Working #16

Closed andreasarnol02 closed 8 years ago

andreasarnol02 commented 8 years ago

Hi

I tried this code and its not working

 it { is_expected.to validate_presence_of(:shorten).on(:create).if(:custom) }

It throwed this error "undefined method `if' for Shoulda::Matchers::ActiveModel::AllowValueMatcher:0x00000005d7dd40"

My gem

Is there something wrong with my code?

Thanks!

beatrichartz commented 8 years ago

validate_presence_of is a method on the shoulda-matchers gem, this is the shoulda-callback-matchers gem, which only deals with testing callback existence.

andreasarnol02 commented 8 years ago

No i mean the condition (if or unless) are methods on shoulda matchers callback right? I use shoulda matchers too.

I mean from the (if) or the condition is throwing me that error

beatrichartz commented 8 years ago

Yes, so shoulda-matchers does not have a chainable if or unless, so when you're using shoulda-matchers test matchers like validate_presence_of or other validation test matchers, if and unless won't be available since shoulda-matchers does not expose tests for conditions directly.

This gem only exposes the callback chainable matcher - that means it provides only the matchers you write which begin with

it { is_expected.to callback(:some_method) }