Sha256: aef78156e81a831d25e6d5b16224885b62e44a74c7aa70503753ac492d649235

Contents?: true

Size: 946 Bytes

Versions: 5

Compression:

Stored size: 946 Bytes

Contents

require 'tester/definition/boundary_case'

class Request
  attr_accessor :definition
  attr_accessor :headers
  attr_accessor :fields

  def initialize
    self.fields = []
  end

  def add_field(new_field)
    self.fields << new_field
    self
  end

  def payload
    response = Hash.new
    self.fields.each do |field|
      response[field.name] = field.default_value
    end
    response
  end

  def default_payload
    payload
  end

  def default_headers
    {content_type: :json, accept: :json}
  end

  def cases
    boundary_cases = Array.new
    self.fields.each do |field|
      field.negative_boundary_values.each do |value|
        bcase = BoundaryCase.new("Setting #{field.name} to #{value}", altered_payload(field.name, value), default_headers)
        boundary_cases.push(bcase)
      end
    end
    boundary_cases
  end

  def altered_payload field_name, value
    body = payload
    body[field_name] = value
    body
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
api-tester-0.1.0 lib/tester/definition/request.rb
api-tester-0.0.5 lib/tester/definition/request.rb
api-tester-0.0.4 lib/tester/definition/request.rb
api-tester-0.0.3 lib/tester/definition/request.rb
api-tester-0.0.1 lib/tester/definition/request.rb