1

I am testing a random string generator that takes two arrays of words and then picks random ones from them. I need to be able to test that it actually is random. For instance:

FrostyMeadow.generate(:nouns => ["hello", "world"], :adjectives => ["hello","world"]

should generate one of the following strings:

["hello world", "world world", "world hello", "hello hello"]

Is there any way to give rspec that array and check if the generated string is in there?

1

1 Answer 1

5

Randomness is hard to test, but in your case you can achieve it this way:

word = FrostyMeadow.generate(:nouns => ["hello", "world"], :adjectives => ["hello","world"]
["hello world", "world world", "world hello", "hello hello"].should include(word)
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.