Class: RailsForge::Generators::TestGenerator

Inherits:
BaseGenerator show all
Defined in:
lib/railsforge/generators/test_generator.rb

Overview

Test generator

Constant Summary

Constants inherited from BaseGenerator

BaseGenerator::TEMPLATE_VERSION

Instance Method Summary collapse

Methods inherited from BaseGenerator

#camelize, #find_rails_app_path, #underscore, #validate_name!

Constructor Details

#initialize(name = "test", options = {}) ⇒ TestGenerator

Initialize the generator



11
12
13
14
15
# File 'lib/railsforge/generators/test_generator.rb', line 11

def initialize(name = "test", options = {})
  super(name, options)
  @component_type = options[:type] || "model"
  @spec_path = options[:spec_path] || "spec"
end

Instance Method Details

#generateObject

Generate test files



18
19
20
21
22
23
24
25
26
27
# File 'lib/railsforge/generators/test_generator.rb', line 18

def generate
  return "Not in a Rails application directory" unless @base_path

  results = []
  results << generate_factory
  results << generate_spec
  results << generate_integration_spec if @component_type == "feature"

  results.join("\n")
end