Navigation Menu

Skip to content

Commit

Permalink
fix compatibility issues with Ruby 1.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dcuddeback committed Nov 21, 2011
1 parent 683ada8 commit e0b22d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 11 additions & 4 deletions lib/rspec/tag_matchers/has_tag.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 2 additions & 3 deletions lib/rspec/tag_matchers/helpers/sentence_helper.rb
Expand Up @@ -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
Expand Down

0 comments on commit e0b22d0

Please sign in to comment.