Class: Transpec::Syntax

Inherits:
Object
  • Object
show all
Defined in:
lib/transpec/syntax.rb,
lib/transpec/syntax/double.rb,
lib/transpec/syntax/should.rb,
lib/transpec/syntax/matcher.rb,
lib/transpec/syntax/be_close.rb,
lib/transpec/syntax/method_stub.rb,
lib/transpec/syntax/raise_error.rb,
lib/transpec/syntax/expectizable.rb,
lib/transpec/syntax/should_receive.rb,
lib/transpec/syntax/rspec_configure.rb,
lib/transpec/syntax/send_node_syntax.rb,
lib/transpec/syntax/able_to_allow_no_message.rb,
lib/transpec/syntax/able_to_target_any_instance.rb

Defined Under Namespace

Modules: AbleToAllowNoMessage, AbleToTargetAnyInstance, Expectizable, SendNodeSyntax Classes: BeClose, Double, Matcher, MethodStub, NotInExampleGroupContextError, RSpecConfigure, RaiseError, Should, ShouldReceive

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, ancestor_nodes, in_example_group_context, source_rewriter) ⇒ Syntax

Returns a new instance of Syntax.



50
51
52
53
54
55
# File 'lib/transpec/syntax.rb', line 50

def initialize(node, ancestor_nodes, in_example_group_context, source_rewriter)
  @node = node
  @ancestor_nodes = ancestor_nodes
  @in_example_group_context = in_example_group_context
  @source_rewriter = source_rewriter
end

Instance Attribute Details

#ancestor_nodesObject (readonly)

Returns the value of attribute ancestor_nodes.



25
26
27
# File 'lib/transpec/syntax.rb', line 25

def ancestor_nodes
  @ancestor_nodes
end

#in_example_group_contextObject (readonly) Also known as: in_example_group_context?

Returns the value of attribute in_example_group_context.



25
26
27
# File 'lib/transpec/syntax.rb', line 25

def in_example_group_context
  @in_example_group_context
end

#nodeObject (readonly)

Returns the value of attribute node.



25
26
27
# File 'lib/transpec/syntax.rb', line 25

def node
  @node
end

#source_rewriterObject (readonly)

Returns the value of attribute source_rewriter.



25
26
27
# File 'lib/transpec/syntax.rb', line 25

def source_rewriter
  @source_rewriter
end

Class Method Details

.allObject



28
29
30
# File 'lib/transpec/syntax.rb', line 28

def self.all
  @subclasses ||= []
end

.inherited(subclass) ⇒ Object



32
33
34
# File 'lib/transpec/syntax.rb', line 32

def self.inherited(subclass)
  all << subclass
end

.snake_case_nameObject



36
37
38
39
40
41
# File 'lib/transpec/syntax.rb', line 36

def self.snake_case_name
  @snake_cake_name ||= begin
    class_name = name.split('::').last
    class_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
  end
end

.target_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/transpec/syntax.rb', line 43

def self.target_node?(node)
  return false unless node.type == :send
  receiver_node, method_name, *_ = *node
  return false unless target_receiver_node?(receiver_node)
  target_method_names.include?(method_name)
end

Instance Method Details

#expression_rangeObject



61
62
63
# File 'lib/transpec/syntax.rb', line 61

def expression_range
  @node.loc.expression
end

#parent_nodeObject



57
58
59
# File 'lib/transpec/syntax.rb', line 57

def parent_node
  @ancestor_nodes.last
end