Class: Transpec::Syntax

Inherits:
Object
  • Object
show all
Extended by:
Collection
Includes:
DynamicAnalysis, Rewritable
Defined in:
lib/transpec/syntax.rb,
lib/transpec/syntax.rb,
lib/transpec/syntax.rb,
lib/transpec/syntax.rb,
lib/transpec/syntax/its.rb,
lib/transpec/syntax/have.rb,
lib/transpec/syntax/allow.rb,
lib/transpec/syntax/double.rb,
lib/transpec/syntax/expect.rb,
lib/transpec/syntax/should.rb,
lib/transpec/syntax/example.rb,
lib/transpec/syntax/pending.rb,
lib/transpec/syntax/receive.rb,
lib/transpec/syntax/be_close.rb,
lib/transpec/syntax/operator.rb,
lib/transpec/syntax/be_boolean.rb,
lib/transpec/syntax/mixin/send.rb,
lib/transpec/syntax/method_stub.rb,
lib/transpec/syntax/raise_error.rb,
lib/transpec/syntax/should_receive.rb,
lib/transpec/syntax/current_example.rb,
lib/transpec/syntax/oneliner_should.rb,
lib/transpec/syntax/rspec_configure.rb,
lib/transpec/syntax/have/have_record.rb,
lib/transpec/syntax/mixin/expect_base.rb,
lib/transpec/syntax/mixin/should_base.rb,
lib/transpec/syntax/matcher_definition.rb,
lib/transpec/syntax/mixin/expectizable.rb,
lib/transpec/syntax/mixin/monkey_patch.rb,
lib/transpec/syntax/have/source_builder.rb,
lib/transpec/syntax/mixin/matcher_owner.rb,
lib/transpec/syntax/mixin/owned_matcher.rb,
lib/transpec/syntax/mixin/messaging_host.rb,
lib/transpec/syntax/rspec_configure/mocks.rb,
lib/transpec/syntax/have/dynamic_inspector.rb,
lib/transpec/syntax/mixin/any_instance_block.rb,
lib/transpec/syntax/mixin/useless_and_return.rb,
lib/transpec/syntax/rspec_configure/framework.rb,
lib/transpec/syntax/mixin/no_message_allowance.rb,
lib/transpec/syntax/rspec_configure/expectations.rb,
lib/transpec/syntax/mixin/monkey_patch_any_instance.rb

Defined Under Namespace

Modules: Collection, DynamicAnalysis, Mixin, Rewritable Classes: Allow, BeBoolean, BeClose, CurrentExample, Double, Example, Expect, Have, Its, MatcherDefinition, MethodStub, OnelinerShould, Operator, Pending, RSpecConfigure, RaiseError, Receive, Should, ShouldReceive

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Collection

all_syntaxes, inherited, require_all, standalone_syntaxes

Methods included from DynamicAnalysis

#register_request_for_dynamic_analysis

Constructor Details

#initialize(node, source_rewriter = nil, runtime_data = nil, report = nil) ⇒ Syntax

Returns a new instance of Syntax.



115
116
117
118
119
120
# File 'lib/transpec/syntax.rb', line 115

def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
  @node = node
  @source_rewriter = source_rewriter
  @runtime_data = runtime_data || DynamicAnalyzer::RuntimeData.new
  @report = report || Report.new
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



92
93
94
# File 'lib/transpec/syntax.rb', line 92

def node
  @node
end

#reportObject (readonly)

Returns the value of attribute report.



92
93
94
# File 'lib/transpec/syntax.rb', line 92

def report
  @report
end

#runtime_dataObject (readonly)

Returns the value of attribute runtime_data.



92
93
94
# File 'lib/transpec/syntax.rb', line 92

def runtime_data
  @runtime_data
end

#source_rewriterObject (readonly)

Returns the value of attribute source_rewriter.



92
93
94
# File 'lib/transpec/syntax.rb', line 92

def source_rewriter
  @source_rewriter
end

Class Method Details

.conversion_target_node?(node, runtime_data = nil) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/transpec/syntax.rb', line 111

def self.conversion_target_node?(node, runtime_data = nil)
  target_node?(node, runtime_data)
end

.snake_case_nameObject



98
99
100
101
102
103
# File 'lib/transpec/syntax.rb', line 98

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

.standalone?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/transpec/syntax.rb', line 94

def self.standalone?
  true
end

.target_node?(node, runtime_data = nil) ⇒ Boolean

The default common method for .conversion_target_node? and .dynamic_analysis_target_node?. If they should behave differently, override either or both.

Returns:

  • (Boolean)


107
108
109
# File 'lib/transpec/syntax.rb', line 107

def self.target_node?(node, runtime_data = nil)
  false
end

Instance Method Details

#expression_rangeObject



130
131
132
# File 'lib/transpec/syntax.rb', line 130

def expression_range
  node.loc.expression
end

#parent_nodeObject



126
127
128
# File 'lib/transpec/syntax.rb', line 126

def parent_node
  node.parent_node
end

#static_context_inspectorObject



122
123
124
# File 'lib/transpec/syntax.rb', line 122

def static_context_inspector
  @static_context_inspector ||= StaticContextInspector.new(node)
end