Class: SnapshotInspector::Snapshot::TestUnitContext

Inherits:
Context
  • Object
show all
Defined in:
app/models/snapshot_inspector/snapshot/test_unit_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Context

extract, from_hash, test_framework

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



6
7
8
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 6

def method_name
  @method_name
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



6
7
8
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 6

def source_location
  @source_location
end

#take_snapshot_indexObject (readonly)

Returns the value of attribute take_snapshot_index.



6
7
8
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 6

def take_snapshot_index
  @take_snapshot_index
end

#test_case_nameObject (readonly)

Returns the value of attribute test_case_name.



6
7
8
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 6

def test_case_name
  @test_case_name
end

#test_frameworkObject (readonly)

Returns the value of attribute test_framework.



6
7
8
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 6

def test_framework
  @test_framework
end

Instance Method Details

#extract(context) ⇒ Object



9
10
11
12
13
14
15
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 9

def extract(context)
  @test_framework = context[:test_framework]
  @test_case_name = context[:test_case_name]
  @method_name = context[:method_name]
  @source_location = context[:source_location]
  @take_snapshot_index = context[:take_snapshot_index]
end

#from_hash(hash) ⇒ Object



18
19
20
21
22
23
24
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 18

def from_hash(hash)
  @test_framework = hash[:test_framework].to_sym
  @test_case_name = hash[:test_case_name]
  @method_name = hash[:method_name]
  @source_location = hash[:source_location]
  @take_snapshot_index = hash[:take_snapshot_index]
end

#nameObject



31
32
33
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 31

def name
  method_name.gsub(/^test_/, "").humanize(capitalize: false)
end

#order_indexObject



39
40
41
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 39

def order_index
  source_location.dup << take_snapshot_index
end

#test_groupObject



35
36
37
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 35

def test_group
  test_case_name
end

#to_slugObject



26
27
28
29
# File 'app/models/snapshot_inspector/snapshot/test_unit_context.rb', line 26

def to_slug
  spec_path_without_extension = source_location[0].delete_suffix(File.extname(source_location[0])).delete_prefix(Rails.root.to_s + "/")
  [spec_path_without_extension, source_location[1], take_snapshot_index].join("_")
end