Reputation: 10035
My specs work fine validating login and in that validation I have access to some_array
but in the validation for some_array
it fails because I don't have access to it. Is there some special thing I need to do to test for arrays?
model
validates_presence_of :login, :some_array
rspec
it { should validate_presence_of(:login) }
it { should validate_presence_of(:some_array) }
Upvotes: 1
Views: 894
Reputation: 1973
Not much info to go on so...
What you need to think is how is the array getting set in the first place?
With each of those it { } blocks a brand new WhateverModel
is created.
Is Whatever.some_array
populated on creation?
it { expect(WhateverModel.some_array).to_not eq([]) }
it { expect(WhateverModel.some_array).to be }
it { expect(WhateverModel.some_array).to be_kind_of Array }
If your "array" is some kind of model relation then there are other matchers for that.
There are tons of matchers you might see something more useful in the docs: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
Upvotes: 1