module RSpec::Its::Subject

@api private Handles turning subject into an expectation target

Public Class Methods

for(attribute, subject) click to toggle source
# File lib/rspec/its/subject.rb, line 8
def for(attribute, subject)
  if Array === attribute
    if Hash === subject
      attribute.inject(subject) { |inner, attr| inner[attr] }
    else
      subject[*attribute]
    end
  else
    attribute_chain = attribute.to_s.split('.')
    attribute_chain.inject(subject) do |inner_subject, attr|
      inner_subject.public_send(attr)
    end
  end
end

Private Instance Methods

for(attribute, subject) click to toggle source
# File lib/rspec/its/subject.rb, line 8
def for(attribute, subject)
  if Array === attribute
    if Hash === subject
      attribute.inject(subject) { |inner, attr| inner[attr] }
    else
      subject[*attribute]
    end
  else
    attribute_chain = attribute.to_s.split('.')
    attribute_chain.inject(subject) do |inner_subject, attr|
      inner_subject.public_send(attr)
    end
  end
end