Module: Fakery::Wrapping

Defined in:
lib/fakery/wrapping.rb

Class Method Summary collapse

Class Method Details

.http_response(fake, type: :typhoeus, http_status: 200) ⇒ Object

Return a mocked HTTP response that contains the JSON representation of fake in its body. This response has the status code http_status.



6
7
8
9
# File 'lib/fakery/wrapping.rb', line 6

def http_response(fake, type: :typhoeus, http_status: 200)
  fake = Fakery::Fake.cast(fake)
  fake.__send__(:http_response, type: :typhoeus, http_status: http_status)
end

.instance(fake, as:, with: nil) ⇒ Object

Return an instance of class as initialized with the hash representation of fake (via its constructor).



13
14
15
16
17
18
# File 'lib/fakery/wrapping.rb', line 13

def instance(fake, as:, with: nil)
  as or raise ArgumentError, 'as keyword argument is required'
  fake = Fakery::Fake.cast(fake)
  with and fake = Fakery::Fake.cast(fake.to_hash.merge(with))
  as.new(fake.to_hash)
end