Class: Rambo::RSpec::HelperFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rambo/rspec/helper_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path:, file_path:, raml: nil, options: nil) ⇒ HelperFile

Returns a new instance of HelperFile.



11
12
13
14
15
16
# File 'lib/rambo/rspec/helper_file.rb', line 11

def initialize(template_path:, file_path:, raml: nil, options: nil)
  @template_path = template_path
  @file_path     = file_path
  @options       = options || { framework: :rails }
  @raml          = raml ? Rambo::RamlModels::Api.new(raml) : nil
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/rambo/rspec/helper_file.rb', line 9

def options
  @options
end

Instance Method Details

#app_classesObject



18
19
20
21
22
23
24
25
# File 'lib/rambo/rspec/helper_file.rb', line 18

def app_classes
  {
    :rails             => "Rails.application",
    :"sinatra:classic" => "Sinatra::Application",
    :"sinatra:modular" => "Sinatra::Base.descendants.find {|klass| klass != Sinatra::Application } || Sinatra::Application",
    :grape             => "Grape::API.descendants.first"
  }
end

#generateObject



27
28
29
# File 'lib/rambo/rspec/helper_file.rb', line 27

def generate
  write_to_file(render) unless file_already_exists?
end

#renderObject



31
32
33
34
35
# File 'lib/rambo/rspec/helper_file.rb', line 31

def render
  b = binding
  ERB.new(template, 0, "-", "@result").result(raml.instance_eval { b })
  @result
end