class Transpec::Syntax::RSpecConfigure::Framework
This cannot be a Syntax
class since this can be instanciated and used even when there's no corresponding node in the existing code.
Attributes
rspec_configure[R]
Public Class Methods
new(rspec_configure)
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 15 def initialize(rspec_configure) @rspec_configure = rspec_configure end
Public Instance Methods
add_record(*args)
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 23 def add_record(*args) rspec_configure.add_record(*args) end
block_node()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 27 def block_node return @block_node if instance_variable_defined?(:@block_node) @block_node = rspec_configure.block_node.each_descendant(:block).find do |block_node| send_node = block_node.children.first receiver_node, method_name, = *send_node next unless receiver_node == s(:lvar, rspec_configure.block_arg_name) method_name == block_method_name # TODO: Check expectation framework. end end
source_rewriter()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 19 def source_rewriter rspec_configure.source_rewriter end
Private Instance Methods
block_method_name()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 41 def block_method_name fail NotImplementedError end
block_node_to_insert_code()
click to toggle source
Calls superclass method
# File lib/transpec/syntax/rspec_configure/framework.rb, line 80 def block_node_to_insert_code super || rspec_configure.block_node end
body_indentation()
click to toggle source
Calls superclass method
# File lib/transpec/syntax/rspec_configure/framework.rb, line 72 def body_indentation if block_node super else rspec_configure_body_indentation + (' ' * 2) end end
config_record_syntax(config_name, value = nil)
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 100 def config_record_syntax(config_name, value = nil) inner_block_arg = framework_type_name[0] syntax = "RSpec.configure { |c| c.#{block_method_name} :rspec " syntax << "{ |#{inner_block_arg}| #{inner_block_arg}.#{config_name}" syntax << " = #{value}" unless value.nil? syntax << ' } }' end
config_variable_name()
click to toggle source
Calls superclass method
# File lib/transpec/syntax/rspec_configure/framework.rb, line 56 def config_variable_name super || new_config_variable_name end
framework_begin_code()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 84 def framework_begin_code code = format( '%s.%s :rspec do |%s|', rspec_configure.block_arg_name, block_method_name, config_variable_name ) rspec_configure_body_indentation + code end
framework_end_code()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 92 def framework_end_code rspec_configure_body_indentation + 'end' end
framework_type_name()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 68 def framework_type_name @framework_type_name ||= self.class.name.split('::').last.downcase end
generate_config_lines(config_name, value = nil, comment = nil)
click to toggle source
Calls superclass method
# File lib/transpec/syntax/rspec_configure/framework.rb, line 45 def generate_config_lines(config_name, value = nil, comment = nil) lines = super unless block_node lines.unshift(framework_begin_code) lines << framework_end_code end lines end
new_config_variable_name()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 60 def new_config_variable_name if rspec_configure.block_arg_name.to_s == framework_type_name 'config' else framework_type_name end end
rspec_configure_body_indentation()
click to toggle source
# File lib/transpec/syntax/rspec_configure/framework.rb, line 96 def rspec_configure_body_indentation indentation_of_line(rspec_configure.node) + (' ' * 2) end