Class: Mutineer::Subject

Inherits:
Struct
  • Object
show all
Defined in:
lib/mutineer/subject.rb

Overview

One discoverable method and its AST node.

Location, namespace context, and the live Prism::DefNode are kept together because mutators walk the def node directly. namespace names the owner (module ::X inside Outer owns into X); lexical is the class/module chain as written (["Outer", "::X"]), which the redefine strategy needs to rebuild the same Module.nesting as a whole-file reload (#145). block_owner is the constant a Data.define-style block is assigned to, as written, or the ClassMethods of a concern's class_methods block (#252); owner_unknown is true when the class that owns the method cannot be named (an unassigned builder block, or a concern block whose class or module no constant names, such as an included block that runs in each includer), so the redefine strategy cannot load a mutant onto it. hook_block is true for a def anywhere inside a concern's included or prepended block, which ActiveSupport runs only when a class first includes the concern, so a reload of the file does not reach a class that already has it (#256). reload_hook_call is the included or prepended call node of such a block when reload can still place the def: the mutant file stores the mutated def just before that call, and the child loads it into each class that has the method (#297). It is nil when reload cannot place the def, even when hook_block is true (see docs/json-schema.md for the cases). enclosing_subject is the subject of the def whose body holds this one, or nil, so the redefine strategy can load each enclosing method too (#290).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#block_owner ⇒ Object

Returns the value of attribute block_owner

Returns:

  • (Object) —

    the current value of block_owner



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def block_owner
  @block_owner
end

#def_node ⇒ Object

Returns the value of attribute def_node

Returns:

  • (Object) —

    the current value of def_node



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def def_node
  @def_node
end

#enclosing_subject ⇒ Object

Returns the value of attribute enclosing_subject

Returns:

  • (Object) —

    the current value of enclosing_subject



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def enclosing_subject
  @enclosing_subject
end

#file ⇒ Object

Returns the value of attribute file

Returns:

  • (Object) —

    the current value of file



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def file
  @file
end

#hook_block ⇒ Object

Returns the value of attribute hook_block

Returns:

  • (Object) —

    the current value of hook_block



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def hook_block
  @hook_block
end

#lexical ⇒ Object

Returns the value of attribute lexical

Returns:

  • (Object) —

    the current value of lexical



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def lexical
  @lexical
end

#name ⇒ Object

Returns the value of attribute name

Returns:

  • (Object) —

    the current value of name



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def name
  @name
end

#namespace ⇒ Object

Returns the value of attribute namespace

Returns:

  • (Object) —

    the current value of namespace



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def namespace
  @namespace
end

#owner_unknown ⇒ Object

Returns the value of attribute owner_unknown

Returns:

  • (Object) —

    the current value of owner_unknown



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def owner_unknown
  @owner_unknown
end

#reload_hook_call ⇒ Object

Returns the value of attribute reload_hook_call

Returns:

  • (Object) —

    the current value of reload_hook_call



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def reload_hook_call
  @reload_hook_call
end

#singleton ⇒ Object

Returns the value of attribute singleton

Returns:

  • (Object) —

    the current value of singleton



27
28
29
# File 'lib/mutineer/subject.rb', line 27

def singleton
  @singleton
end

Instance Method Details

#body_loc ⇒ Prism::Location?

Returns the body location for the subject, if any.

Returns:

  • (Prism::Location, nil) —

    body location or nil for empty methods.



60
61
62
# File 'lib/mutineer/subject.rb', line 60

def body_loc
  def_node.body&.location
end

#lexical_namespace ⇒ Array<String>

Class/module chain as written in the source, for textual wrappers. Falls back to namespace for subjects built without one.

Returns:

  • (Array<String>) —

    names; a root-anchored element keeps its ::.



40
41
42
# File 'lib/mutineer/subject.rb', line 40

def lexical_namespace
  lexical || namespace
end

#qualified_name ⇒ String

Returns the fully-qualified subject name.

Returns:

  • (String) —

    namespaced method name like Billing::Invoice#total.



32
33
34
# File 'lib/mutineer/subject.rb', line 32

def qualified_name
  namespace.join("::") + (singleton ? "." : "#") + name.to_s
end

#unplaceable?(strategy) ⇒ Boolean

True when the strategy cannot load a mutant of this method where the tests call it, so the mutant is not run. Redefine needs a named owner. Reload loads the whole file again, which redefines everything except what a concern's included or prepended block defines: that block does not run again in a class that already includes the concern. Reload places such a def only when discovery found its #reload_hook_call (#297).

Parameters:

  • strategy (String) —

    "reload" or "redefine".

Returns:

  • (Boolean)


53
54
55
# File 'lib/mutineer/subject.rb', line 53

def unplaceable?(strategy)
  strategy == "redefine" ? owner_unknown == true : hook_block == true && reload_hook_call.nil?
end