Technical
Flatten And Sort

My friend once asked me how do you check whether 2 strings have the same charecters ie


 "a c b" == "b c a" 

I had the same thing in test where names would switch arround all the time because of using hash but it would not matter in the contest (“A3 A4 A5: Check NOX targets” or “A5 A3 A4 : Check NOX targets”)

So I wrote this quick stub to help my testers


class String #=>  cause I dont need it for anyting else
  def flatten_and_sort!
    self.gsub!(/(\n|\t)/,'') #remove new lines so code could be formated batter
    self.split(//).sort{|a,b| a <=> b}.delete_if{|str| str =~ / /}.join.downcase
  end
end

So you can do


assert_equal @expected_alert_message.flatten_and_sort!,testing_value.flatten_and_sort!

This method is also useful when you build strings from hash which, due to indiferent sort on hash, will always produce different results.