Permalink
Browse files

fix compatibility issues with Ruby 1.8.7

  • Loading branch information...
1 parent 683ada8 commit e0b22d01815b945466d661f4f036a9ce0ed5e69f @dcuddeback dcuddeback committed Nov 21, 2011
Showing with 13 additions and 7 deletions.
  1. +11 −4 lib/rspec/tag_matchers/has_tag.rb
  2. +2 −3 lib/rspec/tag_matchers/helpers/sentence_helper.rb
@@ -256,11 +256,18 @@ def attributes_description
grouped_attributes = @attributes.group_by { |key, value| !!value }
make_sentence(
- grouped_attributes.map do |group_key, attributes|
- if attributes.count > 0
- grouped_attributes_prefix(group_key, attributes.count > 1) +
+ # Yes, this is functionally equivalent to grouped_attributes.map, except this forces the
+ # keys to be evalutated in the order [true, false]. This is necessary to maintain
+ # compatibility with Ruby 1.8.7, because hashes in 1.8.7 aren't ordered.
+ [true, false].reduce([]) do |memo, group_key|
+ attributes = grouped_attributes[group_key]
+
+ if attributes
+ memo << grouped_attributes_prefix(group_key, attributes.count > 1) +
grouped_attributes_description(attributes)
end
+
+ memo
end
)
end
@@ -288,7 +295,7 @@ def grouped_attributes_prefix(value, plural)
# @return [String]
def grouped_attributes_description(attributes)
make_sentence(
- attributes.map do |key, value|
+ attributes.sort_by{ |key, value| key.to_s }.map do |key, value|
attribute_description(key, value)
end
)
@@ -18,9 +18,8 @@ module SentenceHelper
#
# @return [String]
def make_sentence(*strings)
- strings = strings.flatten.reject(&:empty?)
- options = strings.last.is_a?(Hash) ? strings.pop : {}
-
+ options = strings.last.is_a?(Hash) ? strings.pop : {}
+ strings = strings.flatten.map(&:to_s).reject(&:empty?)
conjunction = options[:conjunction] || "and"
case strings.count

0 comments on commit e0b22d0

Please sign in to comment.