Class: Rambo::RSpec::ExampleGroup
- Inherits:
-
Object
- Object
- Rambo::RSpec::ExampleGroup
- Defined in:
- lib/rambo/rspec/example_group.rb
Constant Summary collapse
- TEMPLATE_PATH =
File.("../templates/example_group_template.erb", __FILE__)
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #create_fixture_files ⇒ Object
-
#initialize(resource, options = {}) ⇒ ExampleGroup
constructor
A new instance of ExampleGroup.
- #render ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(resource, options = {}) ⇒ ExampleGroup
9 10 11 12 |
# File 'lib/rambo/rspec/example_group.rb', line 9 def initialize(resource, ={}) @resource = resource @options = || { framework: :rails } end |
Instance Attribute Details
#resource ⇒ Object (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_files ⇒ Object
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.("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 ⇒ Object
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 |
#template ⇒ Object
14 15 16 |
# File 'lib/rambo/rspec/example_group.rb', line 14 def template @template ||= File.read(TEMPLATE_PATH) end |