Class: Transpec::Syntax::OnelinerShould
- Inherits:
-
Syntax
- Object
- Syntax
- Transpec::Syntax::OnelinerShould
- Includes:
- RSpecDSL, Mixin::ShouldBase, Util
- Defined in:
- lib/transpec/syntax/oneliner_should.rb
Defined Under Namespace
Classes: OnelinerShouldHaveRecord
Constant Summary
Constants included from RSpecDSL
RSpecDSL::EXAMPLE_GROUP_METHODS, RSpecDSL::EXAMPLE_METHODS, RSpecDSL::HELPER_METHODS, RSpecDSL::HOOK_METHODS
Constants included from Util
Util::LITERAL_TYPES, Util::WHITESPACES
Instance Attribute Summary collapse
-
#current_syntax_type ⇒ Object
readonly
Returns the value of attribute current_syntax_type.
Instance Method Summary collapse
- #build_description(size) ⇒ Object
- #convert_have_items_to_standard_expect!(negative_form = 'not_to') ⇒ Object
- #convert_have_items_to_standard_should! ⇒ Object
- #dynamic_analysis_target? ⇒ Boolean
- #example_has_description? ⇒ Boolean
- #expectize!(negative_form = 'not_to') ⇒ Object
-
#initialize ⇒ OnelinerShould
constructor
A new instance of OnelinerShould.
Methods included from Mixin::ShouldBase
#matcher_node, #positive?, #should_range
Methods included from Mixin::Send
#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
Methods included from Mixin::Send::TargetDetection
Methods included from Mixin::MatcherOwner
Methods included from Util
beginning_of_line_range, block_node_taken_by_method, chainable_source, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_line_range, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, proc_literal?, range_from_arg
Constructor Details
#initialize ⇒ OnelinerShould
Returns a new instance of OnelinerShould.
18 19 20 21 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 18 def initialize(*) 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/oneliner_should.rb', line 16 def current_syntax_type @current_syntax_type end |
Instance Method Details
#build_description(size) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 68 def build_description(size) description = positive? ? 'has ' : 'does not have ' case have_matcher.method_name when :have_at_least then description << 'at least ' when :have_at_most then description << 'at most ' end items = have_matcher.items_name if positive? && size == '0' size = 'no' elsif size == '1' items = ActiveSupport::Inflector.singularize(have_matcher.items_name) end description << "#{size} #{items}" end |
#convert_have_items_to_standard_expect!(negative_form = 'not_to') ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 48 def convert_have_items_to_standard_expect!(negative_form = 'not_to') return unless have_matcher.conversion_target? insert_example_description! subject_source = have_matcher.replacement_subject_source('subject') expect_to_source = "expect(#{subject_source})." expect_to_source << (positive? ? 'to' : negative_form) replace(should_range, expect_to_source) @current_syntax_type = :expect report.records << OnelinerShouldHaveRecord.new(self, have_matcher, negative_form) end |
#convert_have_items_to_standard_should! ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 37 def convert_have_items_to_standard_should! return unless have_matcher.conversion_target? insert_example_description! subject_source = have_matcher.replacement_subject_source('subject') insert_before(expression_range, "#{subject_source}.") report.records << OnelinerShouldHaveRecord.new(self, have_matcher) end |
#dynamic_analysis_target? ⇒ Boolean
23 24 25 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 23 def dynamic_analysis_target? super && receiver_node.nil? && [:should, :should_not].include?(method_name) end |
#example_has_description? ⇒ Boolean
63 64 65 66 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 63 def example_has_description? send_node = example_block_node.children.first send_node.children[2] end |
#expectize!(negative_form = 'not_to') ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/transpec/syntax/oneliner_should.rb', line 27 def expectize!(negative_form = 'not_to') replacement = 'is_expected.' replacement << (positive? ? 'to' : negative_form) replace(should_range, replacement) @current_syntax_type = :expect add_record(negative_form) end |