Parent

Class/Module Index [+]

Quicksearch

RSpec::Core::Metadata

Constants

RESERVED_KEYS

Public Class Methods

new(superclass_metadata=nil) click to toggle source
# File lib/rspec/core/metadata.rb, line 35
def initialize(superclass_metadata=nil)
  @superclass_metadata = superclass_metadata
  if @superclass_metadata
    update(@superclass_metadata)
    example_group = {:example_group => @superclass_metadata[:example_group]}
  else
    example_group = {}
  end

  store(:example_group, example_group.extend(LocationKeys))
  yield self if block_given?
end

Public Instance Methods

apply?(predicate, filters) click to toggle source
# File lib/rspec/core/metadata.rb, line 105
def apply?(predicate, filters)
  filters.send(predicate) do |key, value|
    apply_condition(key, value)
  end
end
apply_condition(key, value, metadata=self) click to toggle source
# File lib/rspec/core/metadata.rb, line 120
def apply_condition(key, value, metadata=self)
  case value
  when Hash
    value.all? { |k, v| apply_condition(k, v, metadata[key]) }
  when Regexp
    metadata[key] =~ value
  when Proc
    if value.arity == 2
      # Pass the metadata hash to allow the proc to check if it even has the key.
      # This is necessary for the implicit :if exclusion filter:
      #   {            } # => run the example
      #   { :if => nil } # => exclude the example
      # The value of metadata[:if] is the same in these two cases but
      # they need to be treated differently.
      value.call(metadata[key], metadata) rescue false
    else
      value.call(metadata[key]) rescue false
    end
  when Fixnum
    if key == :line_number
      relevant_line_numbers(metadata).include?(world.preceding_declaration_line(value))
    else
      metadata[key] == value
    end
  else
    metadata[key].to_s == value.to_s
  end
end
configure_for_example(description, user_metadata) click to toggle source
# File lib/rspec/core/metadata.rb, line 97
def configure_for_example(description, user_metadata)
  store(:description, description.to_s)
  store(:full_description, "#{self[:example_group][:full_description]} #{self[:description]}")
  store(:execution_result, {})
  store(:caller, user_metadata.delete(:caller) || caller)
  update(user_metadata)
end
ensure_valid_keys(user_metadata) click to toggle source
# File lib/rspec/core/metadata.rb, line 71
def ensure_valid_keys(user_metadata)
  RESERVED_KEYS.each do |key|
    if user_metadata.keys.include?(key)
      raise #{"*"*50}:#{key} is not allowedRSpec reserves some hash keys for its own internal use,including :#{key}, which is used on:  #{caller(0)[4]}.Here are all of RSpec's reserved hash keys:  #{RESERVED_KEYS.join("\n  ")}#{"*"*50}
      raise ":#{key} is not allowed"
    end
  end
end
for_example(description, user_metadata) click to toggle source
# File lib/rspec/core/metadata.rb, line 93
def for_example(description, user_metadata)
  dup.extend(LocationKeys).configure_for_example(description, user_metadata)
end
process(*args) click to toggle source
# File lib/rspec/core/metadata.rb, line 58
def process(*args)
  user_metadata = args.last.is_a?(Hash) ? args.pop : {}
  ensure_valid_keys(user_metadata)

  self[:example_group].store(:caller, user_metadata.delete(:caller) || caller)
  self[:example_group].store(:describes, described_class_from(*args))
  self[:example_group].store(:description, description_from(*args))
  self[:example_group].store(:full_description, full_description_from(*args))
  self[:example_group].store(:block, user_metadata.delete(:example_group_block))

  update(user_metadata)
end
relevant_line_numbers(metadata) click to toggle source
# File lib/rspec/core/metadata.rb, line 111
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
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.