Module: RSpec::Its::Subject Private

Defined in:
lib/rspec/its/subject.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Handles turning subject into an expectation target

Class Method Summary collapse

Class Method Details

.for(attribute, subject) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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