|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +RSpec.describe SuperDiff, type: :unit do |
| 6 | + describe '.inspect_object', 'for ActionDispatch objects', action_dispatch: true do |
| 7 | + context 'given an ActionDispatch::Request' do |
| 8 | + context 'given as_lines: false' do |
| 9 | + it 'returns an inspected version of the object' do |
| 10 | + string = |
| 11 | + described_class.inspect_object( |
| 12 | + ActionDispatch::Request.new( |
| 13 | + { |
| 14 | + 'REQUEST_METHOD' => 'PUT', |
| 15 | + 'REMOTE_ADDR' => '10.0.0.1', |
| 16 | + Rack::RACK_URL_SCHEME => 'http', |
| 17 | + 'HTTP_HOST' => 'host.local' |
| 18 | + } |
| 19 | + ), |
| 20 | + as_lines: false |
| 21 | + ) |
| 22 | + expect(string).to eq( |
| 23 | + %(#<ActionDispatch::Request PUT "http://host.local" for 10.0.0.1>) |
| 24 | + ) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'given as_lines: true' do |
| 29 | + it 'returns an inspected version of the object on one line' do |
| 30 | + tiered_lines = |
| 31 | + described_class.inspect_object( |
| 32 | + ActionDispatch::Request.new( |
| 33 | + { |
| 34 | + 'REQUEST_METHOD' => 'PUT', |
| 35 | + 'REMOTE_ADDR' => '10.0.0.1', |
| 36 | + Rack::RACK_URL_SCHEME => 'http', |
| 37 | + 'HTTP_HOST' => 'host.local' |
| 38 | + } |
| 39 | + ), |
| 40 | + as_lines: true, |
| 41 | + type: :noop, |
| 42 | + indentation_level: 1 |
| 43 | + ) |
| 44 | + |
| 45 | + expect(tiered_lines).to match( |
| 46 | + [ |
| 47 | + an_object_having_attributes( |
| 48 | + type: :noop, |
| 49 | + indentation_level: 1, |
| 50 | + value: '#<ActionDispatch::Request PUT "http://host.local" for 10.0.0.1>' |
| 51 | + ) |
| 52 | + ] |
| 53 | + ) |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments