Permalink
Browse files

Merge pull request #523 from AlexKVal/meta

some cosmetics for Metadata class
  • Loading branch information...
2 parents 2be6788 + 31bc17d commit 45eb0d30afcc1ff07fe81ceb7d24dbc22b4b31be @dchelimsky dchelimsky committed Dec 5, 2011
Showing with 13 additions and 21 deletions.
  1. +13 −21 lib/rspec/core/metadata.rb
View
@@ -6,7 +6,7 @@ module Core
# @see ExampleGroup.metadata
class Metadata < Hash
- # @private
+ # @private
module MetadataHash
# @private
@@ -26,12 +26,12 @@ def [](key)
when :execution_result
store(:execution_result, {})
when :describes, :described_class
- klass = described_class_for(self)
+ klass = described_class
store(:described_class, klass)
# TODO (2011-11-07 DC) deprecate :describes as a key
store(:describes, klass)
when :full_description
- store(:full_description, full_description_for(self))
+ store(:full_description, full_description)
when :description
store(:description, build_description_from(*self[:description_args]))
else
@@ -54,12 +54,12 @@ def first_caller_from_outside_rspec
self[:caller].detect {|l| l !~ /\/lib\/rspec\/core/}
end
- def described_class_for(m)
- m[:example_group][:described_class]
+ def described_class
+ self[:example_group][:described_class]
end
- def full_description_for(m)
- build_description_from(m[:example_group][:full_description], *m[:description_args])
+ def full_description
+ build_description_from(self[:example_group][:full_description], *self[:description_args])
end
def build_description_from(*parts)
@@ -80,9 +80,9 @@ module ExampleMetadataHash
module GroupMetadataHash
include MetadataHash
- private
+ private
- def described_class_for(*)
+ def described_class
ancestors.each do |g|
# TODO remove describes
return g[:describes] if g.has_key?(:describes)
@@ -97,14 +97,10 @@ def described_class_for(*)
nil
end
- def full_description_for(*)
- build_description_from(*ancestors.reverse.map do |a|
- a[:description_args]
- end.flatten)
+ def full_description
+ build_description_from(*ancestors.reverse.map {|a| a[:description_args]}.flatten)
end
- private
-
def ancestors
@ancestors ||= begin
groups = [group = self]
@@ -243,12 +239,8 @@ def world
end
def relevant_line_numbers(metadata)
- line_numbers = [metadata[:line_number]]
- if metadata[:example_group]
- line_numbers + relevant_line_numbers(metadata[:example_group])
- else
- line_numbers
- end
+ return [metadata[:line_number]] unless metadata[:example_group]
+ [metadata[:line_number]] + relevant_line_numbers(metadata[:example_group])
end
end

0 comments on commit 45eb0d3

Please sign in to comment.