Rspec test for Rails method to return alphabetically sorted list of tags I have one model class as listed here:

class Post &lt; ActiveRecord::Base
  has_many :comments

  def tags
    comments.map(&amp;: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(&amp;:tag).uniq.sort)
  end
end


Do we any better way to test it or even it is nor require to test.
Your test code is merely a copy of your model code, so you're not really testing anything.

Rather, your unit test should rely on fixtures, and the expected answer should be hard-coded in the test.