class Transpec::Syntax::Its
Constants
- Attribute
Public Instance Methods
attribute_expression()
click to toggle source
# File lib/transpec/syntax/its.rb, line 41 def attribute_expression @attribute_expression ||= AttributeExpression.new(attribute_node) end
attributes()
click to toggle source
# File lib/transpec/syntax/its.rb, line 45 def attributes attribute_expression.attributes end
block_node()
click to toggle source
# File lib/transpec/syntax/its.rb, line 51 def block_node node.parent end
conversion_target?()
click to toggle source
Calls superclass method
Transpec::Syntax#conversion_target?
# File lib/transpec/syntax/its.rb, line 23 def conversion_target? super && !runtime_data[node, :project_requires_its?] end
convert_to_describe_subject_it!()
click to toggle source
# File lib/transpec/syntax/its.rb, line 27 def convert_to_describe_subject_it! insert_before(beginning_of_line_range(block_node), front_code) replace(range_from_its_to_front_of_block, additional_indentation_for_it + 'it ') insert_after(block_node.loc.expression, rear_code) increment_block_base_indentation! add_record end
description?()
click to toggle source
# File lib/transpec/syntax/its.rb, line 55 def description? false end
dynamic_analysis_target?()
click to toggle source
Calls superclass method
Transpec::Syntax#dynamic_analysis_target?
# File lib/transpec/syntax/its.rb, line 19 def dynamic_analysis_target? super && receiver_node.nil? && method_name == :its end
insert_blank_line_above!()
click to toggle source
# File lib/transpec/syntax/its.rb, line 37 def insert_blank_line_above! insert_after(beginning_of_line_range(node), "\n") end
Private Instance Methods
add_record()
click to toggle source
Calls superclass method
Transpec::Syntax#add_record
# File lib/transpec/syntax/its.rb, line 121 def add_record super(RecordBuilder.build(self)) end
additional_indentation_for_it()
click to toggle source
# File lib/transpec/syntax/its.rb, line 89 def additional_indentation_for_it ' ' * attributes.size end
block_base_indentation()
click to toggle source
TODO: This is an ad-hoc solution for nested indentation manipulations.
# File lib/transpec/syntax/its.rb, line 109 def block_base_indentation block_node.metadata[:indentation] ||= indentation_of_line(node) end
front_code()
click to toggle source
# File lib/transpec/syntax/its.rb, line 61 def front_code code = '' if !previous_line_is_blank? && previous_and_current_line_are_same_indentation_level? code << "\n" end attributes.each_with_index do |attribute, index| indentation = block_base_indentation + ' ' * index code << indentation + "describe #{attribute.description} do\n" code << indentation + " subject { super()#{attribute.selector} }\n" end code end
increment_block_base_indentation!()
click to toggle source
# File lib/transpec/syntax/its.rb, line 113 def increment_block_base_indentation! block_node.metadata[:indentation] = block_base_indentation + ' ' end
previous_and_current_line_are_same_indentation_level?()
click to toggle source
# File lib/transpec/syntax/its.rb, line 98 def previous_and_current_line_are_same_indentation_level? indentation_of_line(previous_line_source) == block_base_indentation end
previous_line_is_blank?()
click to toggle source
# File lib/transpec/syntax/its.rb, line 93 def previous_line_is_blank? return false unless previous_line_source previous_line_source.empty? || previous_line_source.match(/\A\s*\Z/) end
previous_line_source()
click to toggle source
# File lib/transpec/syntax/its.rb, line 102 def previous_line_source expression_range.source_buffer.source_line(expression_range.line - 1) rescue IndexError nil end
range_from_its_to_front_of_block()
click to toggle source
# File lib/transpec/syntax/its.rb, line 117 def range_from_its_to_front_of_block expression_range.join(block_node.loc.begin.begin) end
rear_code()
click to toggle source
# File lib/transpec/syntax/its.rb, line 77 def rear_code code = '' attributes.size.downto(1) do |level| indentation = block_base_indentation + ' ' * (level - 1) code << "\n" code << "#{indentation}end" end code end