class Rambo::RSpec::ExampleGroup
Constants
- TEMPLATE_PATH
Attributes
resource[R]
Public Class Methods
new(resource, options={})
click to toggle source
# File lib/rambo/rspec/example_group.rb, line 9 def initialize(resource, options={}) @resource = resource @options = options || { framework: :rails } end
Public Instance Methods
create_fixture_files()
click to toggle source
# 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
render()
click to toggle source
# 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
template()
click to toggle source
# File lib/rambo/rspec/example_group.rb, line 14 def template @template ||= File.read(TEMPLATE_PATH) end
Private Instance Methods
response_body_fixture_path(method)
click to toggle source
# File lib/rambo/rspec/example_group.rb, line 48 def response_body_fixture_path(method) File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_response_body.json") end
response_schema_fixture_path(method)
click to toggle source
# File lib/rambo/rspec/example_group.rb, line 44 def response_schema_fixture_path(method) File.expand_path("spec/support/examples/#{@resource.to_s.gsub(/\//, "")}_#{method.method}_response_schema.json") end