class Automock::ResponseMock
Public Class Methods
new(context, example)
click to toggle source
# File lib/automock/response_mock.rb, line 5 def initialize(context, example) @context = context @example = example end
Public Instance Methods
description()
click to toggle source
# File lib/automock/response_mock.rb, line 10 def description @example.try(:example_group).try(:description) || @example.description end
filename()
click to toggle source
# File lib/automock/response_mock.rb, line 34 def filename "#{method}_#{description.gsub(/\s/, '_').gsub(/[?"\\\<>*|]/, '')}.json" end
method()
click to toggle source
# File lib/automock/response_mock.rb, line 14 def method @context.request.method end
mock_data()
click to toggle source
# File lib/automock/response_mock.rb, line 38 def mock_data { description: description, method: method, uri: uri, status: status, response_header: response_header, response_body: response_body }.to_json end
response_body()
click to toggle source
# File lib/automock/response_mock.rb, line 30 def response_body @context.response.try(:body) end
response_header()
click to toggle source
# File lib/automock/response_mock.rb, line 22 def response_header @context.response.try(:header) end
status()
click to toggle source
# File lib/automock/response_mock.rb, line 26 def status @context.response.try(:status) end
uri()
click to toggle source
# File lib/automock/response_mock.rb, line 18 def uri @context.request.env['PATH_INFO'] end
write()
click to toggle source
# File lib/automock/response_mock.rb, line 49 def write pathname = Pathname.new("#{Rails.root}/automock/data/#{uri}/#{filename}") pathname.parent.mkpath pathname.open('w') { |file| file << mock_data } end