Class: Automock::ResponseMock
- Inherits:
-
Object
- Object
- Automock::ResponseMock
- Defined in:
- lib/automock/response_mock.rb
Instance Method Summary collapse
- #description ⇒ Object
- #filename ⇒ Object
-
#initialize(context, example) ⇒ ResponseMock
constructor
A new instance of ResponseMock.
- #method ⇒ Object
- #mock_data ⇒ Object
- #response_body ⇒ Object
- #response_header ⇒ Object
- #status ⇒ Object
- #uri ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(context, example) ⇒ ResponseMock
Returns a new instance of ResponseMock.
5 6 7 8 |
# File 'lib/automock/response_mock.rb', line 5 def initialize(context, example) @context = context @example = example end |
Instance Method Details
#description ⇒ Object
10 11 12 |
# File 'lib/automock/response_mock.rb', line 10 def description @example.try(:example_group).try(:description) || @example.description end |
#filename ⇒ Object
34 35 36 |
# File 'lib/automock/response_mock.rb', line 34 def filename "#{method}_#{description.gsub(/\s/, '_').gsub(/[?"\\\<>*|]/, '')}.json" end |
#method ⇒ Object
14 15 16 |
# File 'lib/automock/response_mock.rb', line 14 def method @context.request.method end |
#mock_data ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/automock/response_mock.rb', line 30 def response_body @context.response.try(:body) end |
#response_header ⇒ Object
22 23 24 |
# File 'lib/automock/response_mock.rb', line 22 def response_header @context.response.try(:header) end |
#status ⇒ Object
26 27 28 |
# File 'lib/automock/response_mock.rb', line 26 def status @context.response.try(:status) end |
#uri ⇒ Object
18 19 20 |
# File 'lib/automock/response_mock.rb', line 18 def uri @context.request.env['PATH_INFO'] end |
#write ⇒ Object
49 50 51 52 53 |
# 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 |