Class: Rambo::RSpec::ExampleGroup

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

Constant Summary collapse

TEMPLATE_PATH =
File.expand_path("../templates/example_group_template.erb", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, options = {}) ⇒ ExampleGroup

Returns a new instance of ExampleGroup.



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

def initialize(resource, options={})
  @resource = resource
  @options  = options || { framework: :rails }
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/rambo/rspec/example_group.rb', line 7

def resource
  @resource
end

Instance Method Details

#create_fixture_filesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rambo/rspec/example_group.rb', line 18

def create_fixture_files
  resource.http_methods.each do |method|
    if method.request_body
      path = File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_request_body.json")
      File.write(path, method.request_body.example)
    end

    method.responses.each do |resp|
      resp.bodies.each do |body|
        path     = body.schema ? response_schema_fixture_path(method) : response_body_fixture_path(method)
        contents = body.schema ? body.schema : body.example
        File.write(path, contents)
      end
    end
  end
end

#renderObject



35
36
37
38
39
40
# File 'lib/rambo/rspec/example_group.rb', line 35

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

#templateObject



14
15
16
# File 'lib/rambo/rspec/example_group.rb', line 14

def template
  @template ||= File.read(TEMPLATE_PATH)
end