Class: Transpec::Syntax::Should
- Inherits:
-
Transpec::Syntax
- Object
- Transpec::Syntax
- Transpec::Syntax::Should
- Includes:
- Mixin::Expectizable, Mixin::HaveMatcher, Mixin::MonkeyPatch, Mixin::Send, Util
- Defined in:
- lib/transpec/syntax/should.rb
Instance Attribute Summary collapse
-
#current_syntax_type ⇒ Object
readonly
Returns the value of attribute current_syntax_type.
Attributes inherited from Transpec::Syntax
#ancestor_nodes, #node, #report, #runtime_data, #source_rewriter
Class Method Summary collapse
Instance Method Summary collapse
- #expect_available? ⇒ Boolean
- #expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true) ⇒ Object
-
#initialize(node, ancestor_nodes, source_rewriter = nil, runtime_data = nil, report = nil) ⇒ Should
constructor
A new instance of Should.
- #matcher_node ⇒ Object
- #operator_matcher ⇒ Object
- #positive? ⇒ Boolean
- #register_request_for_dynamic_analysis(rewriter) ⇒ Object
Methods included from Mixin::Send
#arg_node, #arg_nodes, #arg_range, included, #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
Methods included from Mixin::MonkeyPatch
#check_syntax_availability, #register_request_of_syntax_availability_inspection, #subject_node, #subject_range
Methods included from Mixin::Expectizable
Methods included from Mixin::HaveMatcher
Methods included from Util
const_name, contain_here_document?, here_document?, in_parentheses?, indentation_of_line, proc_literal?
Methods inherited from Transpec::Syntax
all_syntaxes, #expression_range, inherited, #parent_node, register_request_for_dynamic_analysis, snake_case_name, standalone?, standalone_syntaxes, #static_context_inspector, target_node?
Constructor Details
#initialize(node, ancestor_nodes, source_rewriter = nil, runtime_data = nil, report = nil) ⇒ Should
Returns a new instance of Should.
22 23 24 25 |
# File 'lib/transpec/syntax/should.rb', line 22 def initialize(node, ancestor_nodes, source_rewriter = nil, runtime_data = nil, report = nil) super @current_syntax_type = :should end |
Instance Attribute Details
#current_syntax_type ⇒ Object (readonly)
Returns the value of attribute current_syntax_type.
16 17 18 |
# File 'lib/transpec/syntax/should.rb', line 16 def current_syntax_type @current_syntax_type end |
Class Method Details
.target_method?(receiver_node, method_name) ⇒ Boolean
18 19 20 |
# File 'lib/transpec/syntax/should.rb', line 18 def self.target_method?(receiver_node, method_name) !receiver_node.nil? && [:should, :should_not].include?(method_name) end |
Instance Method Details
#expect_available? ⇒ Boolean
38 39 40 |
# File 'lib/transpec/syntax/should.rb', line 38 def expect_available? check_syntax_availability(__method__) end |
#expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/transpec/syntax/should.rb', line 46 def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true) unless expect_available? fail InvalidContextError.new(selector_range, "##{method_name}", '#expect') end if proc_literal?(subject_node) replace_proc_selector_with_expect! else wrap_subject_in_expect! end replace(should_range, positive? ? 'to' : negative_form) @current_syntax_type = :expect register_record(negative_form) operator_matcher.correct_operator!(parenthesize_matcher_arg) if operator_matcher end |
#matcher_node ⇒ Object
77 78 79 |
# File 'lib/transpec/syntax/should.rb', line 77 def matcher_node arg_node || parent_node end |
#operator_matcher ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/transpec/syntax/should.rb', line 65 def operator_matcher return @operator_matcher if instance_variable_defined?(:@operator_matcher) @operator_matcher ||= begin if OperatorMatcher.target_node?(matcher_node, @runtime_data) OperatorMatcher.new(matcher_node, @source_rewriter, @runtime_data, @report) else nil end end end |
#positive? ⇒ Boolean
42 43 44 |
# File 'lib/transpec/syntax/should.rb', line 42 def positive? method_name == :should end |
#register_request_for_dynamic_analysis(rewriter) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/transpec/syntax/should.rb', line 27 def register_request_for_dynamic_analysis(rewriter) register_request_of_syntax_availability_inspection( rewriter, :expect_available?, [:expect] ) operator_matcher.register_request_for_dynamic_analysis(rewriter) if operator_matcher have_matcher.register_request_for_dynamic_analysis(rewriter) if have_matcher end |