I have one model class as listed here:
class Post < ActiveRecord::Base
has_many :comments
def tags
comments.map(&:tag).uniq.sort
end
end
and below is the best rspec as per my understanding:
context 'tags' do
let(:post) { Post.find_by_code('TX') }
it 'returns sorted alphabetically list of available tags' do
expect(post.tags).to eq(post.comments.map(&:tag).uniq.sort)
end
end
Do we any better way to test it or even it is nor require to test.
tags
method and compare to a hardcoded ordered result pre processed based on the input you gave it. Now it's not testing anything, it's will always be true since you have basically the same code on both sides of the expectation. \$\endgroup\$