Module: GoodData::Mixin::Inspector

Included in:
Rest::Client
Defined in:
lib/gooddata/mixins/inspector.rb

Overview

When an RSpec test like this fails,

expect(@my_array).to == [@some_model, @some_model2]

RSpec will call inspect on each of the objects to "help" you figure out what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying to figure out why @my_array is not made up of @some_model and @some_model2.

This little module and technique helps get around that. It will redefine inspect if you include it in your model object.

You can define a whitelist of methods that inspect will dump. It will always provide object_id at a minimum.

To use it, drop it in spec/support/inspector.rb and class_eval the models to override inspect.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inspectedObject



34
35
36
# File 'lib/gooddata/mixins/inspector.rb', line 34

def self.inspected
  @inspected ||= []
end

Instance Method Details

#inspectObject



28
29
30
31
32
# File 'lib/gooddata/mixins/inspector.rb', line 28

def inspect
  string = "#<#{self.class.name}:#{object_id} "
  fields = self.class.inspector_fields.map { |field| "#{field}: #{send(field)}" }
  string << fields.join(', ') << '>'
end