Class: SuperDiff::RSpec::ObjectInspection::InspectionTreeBuilders::Double
- Inherits:
-
ObjectInspection::InspectionTreeBuilders::Base
- Object
- ObjectInspection::InspectionTreeBuilders::Base
- SuperDiff::RSpec::ObjectInspection::InspectionTreeBuilders::Double
- Defined in:
- lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #doubled_method_names ⇒ Object
- #doubled_methods ⇒ Object
- #empty? ⇒ Boolean
- #inspected_class ⇒ Object
- #inspected_name ⇒ Object
- #nonempty? ⇒ Boolean
Class Method Details
.applies_to?(value) ⇒ Boolean
6 7 8 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 6 def self.applies_to?(value) value.is_a?(::RSpec::Mocks::Double) end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 10 def call builder = self empty = -> { empty? } nonempty = -> { !empty? } SuperDiff::ObjectInspection::InspectionTree.new do only_when empty do as_lines_when_rendering_to_lines do add_text do |object| inspected_class = builder.inspected_class inspected_name = builder.inspected_name "#<#{inspected_class} #{inspected_name}>" end end end only_when nonempty do as_lines_when_rendering_to_lines(collection_bookend: :open) do add_text do |object| inspected_class = builder.inspected_class inspected_name = builder.inspected_name "#<#{inspected_class} #{inspected_name}" end when_rendering_to_lines { add_text " {" } end when_rendering_to_string { add_text " " } nested do |object| insert_hash_inspection_of(builder.doubled_methods) end as_lines_when_rendering_to_lines(collection_bookend: :close) do when_rendering_to_lines { add_text "}" } add_text ">" end end end end |
#doubled_method_names ⇒ Object
88 89 90 91 92 93 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 88 def doubled_method_names object .__send__(:__mock_proxy) .instance_variable_get("@method_doubles") .keys end |
#doubled_methods ⇒ Object
81 82 83 84 85 86 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 81 def doubled_methods @_doubled_methods ||= doubled_method_names.reduce({}) do |hash, key| hash.merge(key => object.public_send(key)) end end |
#empty? ⇒ Boolean
52 53 54 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 52 def empty? doubled_methods.empty? end |
#inspected_class ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 60 def inspected_class case object when ::RSpec::Mocks::InstanceVerifyingDouble "InstanceDouble" when ::RSpec::Mocks::ClassVerifyingDouble "ClassDouble" when ::RSpec::Mocks::ObjectVerifyingDouble "ObjectDouble" else "Double" end end |
#inspected_name ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 73 def inspected_name if object.instance_variable_get("@name") object.instance_variable_get("@name").inspect else "(anonymous)" end end |
#nonempty? ⇒ Boolean
56 57 58 |
# File 'lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb', line 56 def nonempty? !empty? end |