Class: Tset::Generators::ModelTest

Inherits:
Abstract
  • Object
show all
Defined in:
lib/tset/generators/model_test.rb

Overview

Generates blank test files in the application Uses analyzers, translators, and writers to insert appropriate tests into the files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ ModelTest

Returns a new instance of ModelTest.



18
19
20
21
22
23
# File 'lib/tset/generators/model_test.rb', line 18

def initialize(command)
  super
  @model_name = name.classify

  cli.class.source_root(source)
end

Instance Attribute Details

#model_nameObject (readonly)

Returns the value of attribute model_name.



16
17
18
# File 'lib/tset/generators/model_test.rb', line 16

def model_name
  @model_name
end

Instance Method Details

#startObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tset/generators/model_test.rb', line 25

def start
  assert_model_exists!

  opts = {
    model_name: @model_name
  }

  case framework
  when 'rspec'
    cli.template(source.join('model_spec.rspec.tt'), target.join("spec/models/#{ name }_spec.rb"), opts)
  when 'minitest'
    cli.template(source.join('model_test.minitest.tt'), target.join("test/models/#{ name }_test.rb"), opts)
  end

  testables = Tset::Analyzers::Model.new(name).start
  Tset::Writers::ModelTest.new(name, testables, framework).start!
end