class RSpecJumpstart::ERBFactory

Public Class Methods

new(custom_template) click to toggle source
# File lib/rspec_jumpstart/erb_factory.rb, line 13
def initialize(custom_template)
  @custom_template = custom_template
end

Public Instance Methods

get_instance_for_appending(rails_mode, target_path) click to toggle source

Returns ERB instance for appending lacking tests

# File lib/rspec_jumpstart/erb_factory.rb, line 28
def get_instance_for_appending(rails_mode, target_path)
  template = get_erb_template(@custom_template, false, rails_mode, target_path)
  ERB.new(template, nil, '-', '_additional_spec_code')
end
get_instance_for_new_spec(rails_mode, target_path) click to toggle source

Returns ERB instance for creating new spec

# File lib/rspec_jumpstart/erb_factory.rb, line 20
def get_instance_for_new_spec(rails_mode, target_path)
  template = get_erb_template(@custom_template, true, rails_mode, target_path)
  ERB.new(template, nil, '-', '_new_spec_code')
end

Private Instance Methods

get_basic_template(is_full) click to toggle source
# File lib/rspec_jumpstart/erb_factory.rb, line 76
def get_basic_template(is_full)
  if is_full
    return RSpecJumpstart::ERBTemplates::BASIC_NEW_SPEC_TEMPLATE
  end

  RSpecJumpstart::ERBTemplates::BASIC_METHODS_PART_TEMPLATE
end
get_erb_template(custom_template, is_full, rails_mode, target_path) click to toggle source

Returns ERB template

# File lib/rspec_jumpstart/erb_factory.rb, line 38
def get_erb_template(custom_template, is_full, rails_mode, target_path)
  if custom_template
    custom_template
  elsif rails_mode && target_path.match(/controllers/)
    get_rails_controller_template(is_full)
  elsif rails_mode && target_path.match(/models/)
    get_rails_model_template(is_full)
  elsif rails_mode && target_path.match(/helpers/)
    get_rails_helper_template(is_full)
  else
    get_basic_template(is_full)
  end
end
get_rails_controller_template(is_full) click to toggle source
# File lib/rspec_jumpstart/erb_factory.rb, line 52
def get_rails_controller_template(is_full)
  if is_full
    return RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_NEW_SPEC_TEMPLATE
  end

  RSpecJumpstart::ERBTemplates::RAILS_CONTROLLER_METHODS_PART_TEMPLATE
end
get_rails_helper_template(is_full) click to toggle source
# File lib/rspec_jumpstart/erb_factory.rb, line 68
def get_rails_helper_template(is_full)
  if is_full
    return RSpecJumpstart::ERBTemplates::RAILS_HELPER_NEW_SPEC_TEMPLATE
  end

  RSpecJumpstart::ERBTemplates::RAILS_HELPER_METHODS_PART_TEMPLATE
end
get_rails_model_template(is_full) click to toggle source
# File lib/rspec_jumpstart/erb_factory.rb, line 60
def get_rails_model_template(is_full)
  if is_full
    return RSpecJumpstart::ERBTemplates::RAILS_MODEL_NEW_SPEC_TEMPLATE
  end

  RSpecJumpstart::ERBTemplates::RAILS_MODEL_METHODS_PART_TEMPLATE
end