Module: RuboCop::Cop::RSpec::AggregateExamples::Its

Extended by:
NodePattern::Macros
Included in:
RuboCop::Cop::RSpec::AggregateExamples
Defined in:
lib/test_prof/cops/rspec/aggregate_examples/its.rb

Overview

Examples:

‘its`


# Supports regular `its` call with an attribute/method name,
# or a chain of methods expressed as a string with dots.

its(:one) { is_expected.to be(true) }
its('two') { is_expected.to be(false) }
its('phone_numbers.size') { is_expected.to be 2 }

‘its` with single-element array argument


# Also supports single-element array argument.

its(['headers']) { is_expected.to include(encoding: 'text') }

‘its` with multi-element array argument is ambiguous


# Does not support `its` with multi-element array argument due to
# an ambiguity. Transformation depends on the type of the subject:
# - a Hash: `hash[element1][element2]...`
# - and arbitrary type: `hash[element1, element2, ...]`
# It is impossible to infer the type to propose a proper correction.

its(['ambiguous', 'elements']) { ... }

‘its` with metadata


its('header', html: true) { is_expected.to include(text: 'hello') }