module RuboCop::Cop::RSpec::AggregateExamples::Its
def example_metadata(example)
def example_metadata(example) return super unless its?(example.send_node) # First parameter to `its` is not metadata. example.send_node.arguments[1..-1] end
def its?(node)
def its?(node) node.method_name == :its end
def new_body(node)
It's impossible to aggregate `its` body as is, it needs to be
def new_body(node) return super unless its?(node) transform_its(node.body, node.send_node.arguments) end
def transform_its(body, arguments)
def transform_its(body, arguments) argument = arguments.first replacement = case argument.type when :array key = argument.values.first "expect(subject[#{key.source}])" else property = argument.value "expect(subject.#{property})" end body.source.gsub(/is_expected|are_expected/, replacement) end