I'm testing a model in rails, and I'd like to assert that one of the associations has an n items. I've found that the assert_pattern matcher is a pretty good way to do it:
assert_pattern do author.books.to_a => [Book, Book, Book, Book, Book]end
However, I've also found that having a big list of items like that can be difficult to read. I've tried expanding the array the way I usually would in ruby:
assert_pattern do author.books.to_a => [Book]*5end
However, within a pattern matcher, that's a syntax error:
test/models/book_test.rb:39: syntax error, unexpected '*', expecting `end' or dummy end (SyntaxError) author.books.to_a => [Book]*5 ^
Is there a concise way to make a pattern that's a function of length?