Class: Transpec::Syntax::Have
Defined Under Namespace
Classes: DynamicInspector, HaveRecord, SourceBuilder
Constant Summary
collapse
- QUERY_METHOD_PRIORITIES =
String#count is not query method, and there’s no way to determine whether a method is query method. Method#arity and Method#parameters return same results for Array#count (0+ args) and String#count (1+ args).
So I make #size a priority over #count so that #count won’t be chosen for String (String responds to #size).
[:size, :count, :length].freeze
Instance Attribute Summary
#node, #report, #runtime_data, #source_rewriter
Class Method Summary
collapse
Instance Method Summary
collapse
#arg_node, #arg_nodes, #arg_range, #args_range, #method_name, #parentheses_range, #range_after_arg, #range_in_between_receiver_and_selector, #range_in_between_selector_and_arg, #receiver_node, #receiver_range, #selector_range
#initialize
conversion_target_node?, #expression_range, #initialize, #parent_node, snake_case_name, standalone?, #static_context_inspector, target_node?
Methods included from Collection
#all_syntaxes, #inherited, #require_all, #standalone_syntaxes
#register_request_for_dynamic_analysis
Class Method Details
.target_method?(receiver_node, method_name) ⇒ Boolean
25
26
27
28
|
# File 'lib/transpec/syntax/have.rb', line 25
def self.target_method?(receiver_node, method_name)
receiver_node.nil? &&
[:have, :have_exactly, :have_at_least, :have_at_most].include?(method_name)
end
|
Instance Method Details
#accurate_conversion? ⇒ Boolean
104
105
106
|
# File 'lib/transpec/syntax/have.rb', line 104
def accurate_conversion?
!runtime_subject_data.nil?
end
|
#collection_accessor ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/transpec/syntax/have.rb', line 66
def collection_accessor
if runtime_subject_data(:collection_accessor)
runtime_subject_data(:collection_accessor).to_sym
else
items_name
end
end
|
#collection_accessor_is_private? ⇒ Boolean
79
80
81
|
# File 'lib/transpec/syntax/have.rb', line 79
def collection_accessor_is_private?
runtime_subject_data(:collection_accessor_is_private?)
end
|
#convert_to_standard_expectation!(parenthesize_matcher_arg = true) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/transpec/syntax/have.rb', line 34
def convert_to_standard_expectation!(parenthesize_matcher_arg = true)
return if project_requires_collection_matcher?
replace(expectation.subject_range, replacement_subject_source) if explicit_subject?
replace(matcher_range, source_builder.replacement_matcher_source(parenthesize_matcher_arg))
register_record if explicit_subject?
end
|
#default_query_method ⇒ Object
#explicit_subject? ⇒ Boolean
43
44
45
|
# File 'lib/transpec/syntax/have.rb', line 43
def explicit_subject?
expectation.respond_to?(:subject_node)
end
|
#items_method_has_arguments? ⇒ Boolean
54
55
56
|
# File 'lib/transpec/syntax/have.rb', line 54
def items_method_has_arguments?
items_node.children.size > 2
end
|
#items_name ⇒ Object
58
59
60
|
# File 'lib/transpec/syntax/have.rb', line 58
def items_name
items_node.children[1]
end
|
#matcher_range ⇒ Object
108
109
110
|
# File 'lib/transpec/syntax/have.rb', line 108
def matcher_range
expression_range.join(items_node.loc.expression)
end
|
#project_requires_collection_matcher? ⇒ Boolean
62
63
64
|
# File 'lib/transpec/syntax/have.rb', line 62
def project_requires_collection_matcher?
runtime_subject_data(:project_requires_collection_matcher?)
end
|
#query_method ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/transpec/syntax/have.rb', line 83
def query_method
if (available_query_methods = runtime_subject_data(:available_query_methods))
(QUERY_METHOD_PRIORITIES & available_query_methods.map(&:to_sym)).first
else
default_query_method
end
end
|
#replacement_subject_source(base_subject = nil) ⇒ Object
95
96
97
98
|
# File 'lib/transpec/syntax/have.rb', line 95
def replacement_subject_source(base_subject = nil)
base_subject ||= expectation.subject_node
source_builder.replacement_subject_source(base_subject)
end
|
#size_node ⇒ Object
50
51
52
|
# File 'lib/transpec/syntax/have.rb', line 50
def size_node
have_node.children[2]
end
|
#size_source ⇒ Object
100
101
102
|
# File 'lib/transpec/syntax/have.rb', line 100
def size_source
size_node.loc.expression.source
end
|
#subject_is_owner_of_collection? ⇒ Boolean
74
75
76
77
|
# File 'lib/transpec/syntax/have.rb', line 74
def subject_is_owner_of_collection?
return true if items_method_has_arguments?
!runtime_subject_data(:collection_accessor).nil?
end
|