Class: Topoisomerase::Comments

Inherits:
Object
  • Object
show all
Defined in:
lib/topoisomerase/comments.rb

Overview

Class to set up comments that will be added to stubs for dynamic methods

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.inheriting_classObject

Returns Class for which stubs will be created from and for which rules to add comments for are defined.

Returns:

  • (Object)

    Class for which stubs will be created from and for which rules to add comments for are defined



7
8
9
# File 'lib/topoisomerase/comments.rb', line 7

def inheriting_class
  @inheriting_class
end

Class Method Details

.add_for_class(inheriting_class, &script) ⇒ Object

Add comments according to matchers for an inheriting class

The order in which they are added is the order in which matching will occur. The first comment that has a match will be used. If several matchers are used on 1 comment, all must be true to be considered a match

Examples:

Add a comment where method name ends with '=' and source contains '.text'

Comments.add_for_class PageObject do
  comment 'Comment to add', method_name: /=$/, source: /.text/
end

Parameters:

  • inheriting_class (Object)

    Class for which stubs will be created from and for which rules to add comments for are defined



34
35
36
37
38
# File 'lib/topoisomerase/comments.rb', line 34

def add_for_class(inheriting_class, &script)
  Topoisomerase.comments_added[inheriting_class] ||= []
  self.inheriting_class = inheriting_class
  instance_eval(&script)
end

.comment(comment, matchers) ⇒ Object

Add a comment that is returned if ALL matchers are true

Examples:

Match a method ending with '_element' and include it's name without the '_element'

comment "@return [Object] The '<%= method_to_stub.to_s.gsub('_element', '') %>' element",
        method_name: /_element$/

Parameters:

  • comment (String)

    Comment to add above class



14
15
16
17
18
19
# File 'lib/topoisomerase/comments.rb', line 14

def comment(comment, matchers)
  Topoisomerase.comments_added[inheriting_class] << {
    message: comment,
    matchers: matchers
  }
end