15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/fakeapi/generator.rb', line 15
def generate
hash = VCRReader.read("vcr/#{@name}.yml")
http_method = hash['request']['method']
url = URI(hash['request']['uri']).path
status = hash['response']['status']['code']
content_type = hash['response']['headers']['Content-Type'].first
body = hash['response']['body']['string']
body = if content_type =~ /json/i
write_json(body)
else
write_text(body)
end
<<RUBY
#{http_method} '#{url}' do
status #{status}
content_type '#{content_type}'
body #{body}
end
RUBY
end
|