1

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) }
1
  • This is not enough information to go on. Can you post your model code and your spec file (without the parts that are clearly irrelevant)? Commented Jul 11, 2017 at 16:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.