Change your example as below:
it 'adds upvote to article' do
user.upvote(article)
expect(article.reload.upvotes.size).to eq 1
end
The reason why your given example failed was that the spec was holding the article
object which was created via FactoryGirl
using FactoryGirl.create(:article)
and it does not know that there was a change made in the database. You will need to reload
the article so that the change gets reflected.
In other passing test,i.e.,
expect{ user.upvote(article) }.to change{ article.upvotes.size }.by 1
your example passes because an implicit reload happens because of change
method.