Is the test flexible?  describe self.sort do    before(:each) do      @tee = FactoryGirl.create :author, nickname: tee jia hen, user: FactoryGirl.create(:user)      @jon = FactoryGirl.create :author, nickname: jon, user: FactoryGirl.create(:user)      @tee_article1 = FactoryGirl.create :article, author: @tee, title: 3diablo      @tee_article2 = FactoryGirl.create :article, author: @tee, title: 1people      @jon_article = FactoryGirl.create :article, author:@jon, title: 2game    end    it , it should sort articles base on title do      Article.sort(title, asc).should == [@tee_article2, @jon_article, @tee_article1]    end  end
Comparing an active record result with an array of object in a rspec test
ruby;ruby on rails;rspec
Provided you sort the active record results (as you have done), comparing to an array works fine.  I'm not sure what you mean by 'flexible', but the test you've written looks pretty good (without knowing the internals of your 'sort' function).I'd only suggest adding some more tests to cover reverse sorting, sorting by author.nickname (if that's part of the default scope, or pulled in via delegation), and passing invalid values to the sort function.Being a little pedantic, you don't need to repeat the word it in the spec declaration.The word it will be prepended to the message in the case of failures.  describe self.sort do    before(:each) do      @tee = FactoryGirl.create :author, nickname: tee jia hen, user: FactoryGirl.create(:user)      @jon = FactoryGirl.create :author, nickname: jon, user: FactoryGirl.create(:user)      @tee_article1 = FactoryGirl.create :article, author: @tee, title: 3diablo      @tee_article2 = FactoryGirl.create :article, author: @tee, title: 1people      @jon_article = FactoryGirl.create :article, author:@jon, title: 2game    end    it should sort articles base on title do      Article.sort(title, asc).should == [@tee_article2, @jon_article, @tee_article1]    end    it should reverse-sort articles base on title do      Article.sort(title, desc).should == [@tee_article1, @jon_article, @tee_article2]    end  end