Class: NxtVcrHarness::CassetteNameByExample
- Inherits:
-
Object
- Object
- NxtVcrHarness::CassetteNameByExample
- Defined in:
- lib/nxt_vcr_harness/cassette_name_by_example.rb
Instance Attribute Summary collapse
-
#example ⇒ Object
readonly
Returns the value of attribute example.
Instance Method Summary collapse
- #call(**options) ⇒ Object
- #cassette_name_and_path(options) ⇒ Object
- #cassette_name_from_descriptions ⇒ Object
- #context_hierarchy ⇒ Object
- #context_hierarchy_with_vcr_cassette_tags ⇒ Object
- #gsub_whitespace(name) ⇒ Object
-
#initialize(example) ⇒ CassetteNameByExample
constructor
A new instance of CassetteNameByExample.
- #remove_hash_tags(name) ⇒ Object
Constructor Details
#initialize(example) ⇒ CassetteNameByExample
Returns a new instance of CassetteNameByExample.
3 4 5 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 3 def initialize(example) @example = example end |
Instance Attribute Details
#example ⇒ Object (readonly)
Returns the value of attribute example.
7 8 9 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 7 def example @example end |
Instance Method Details
#call(**options) ⇒ Object
9 10 11 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 9 def call(**) cassette_name_and_path() end |
#cassette_name_and_path(options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 13 def cassette_name_and_path() path = [] path << [:prefix] spec_path = example.file_path.gsub(/\.rb$/, '').gsub('./spec/', '') path << spec_path path << cassette_name_from_descriptions path << [:suffix] "/#{path.flatten.compact.join('/')}" end |
#cassette_name_from_descriptions ⇒ Object
26 27 28 29 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 26 def cassette_name_from_descriptions descriptions = .map { |c| c[:description] } descriptions.map(&method(:gsub_whitespace)).map(&method(:remove_hash_tags)) end |
#context_hierarchy ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 50 def context_hierarchy @context_hierarchy ||= begin context_hierarchy = [example.] example_group = example.[:example_group] context_hierarchy << example_group while parent_example_group = example_group[:parent_example_group] do context_hierarchy << parent_example_group example_group = parent_example_group end context_hierarchy rescue StandardError => e raise StandardError, "Failed to build context hierarchy for example: #{example} - Error was: #{e.inspect}" end end |
#context_hierarchy_with_vcr_cassette_tags ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 39 def @context_hierarchy_with_vcr_cassette_tags ||= begin context_hierarchy.reverse.inject([]) do |acc, context| acc << context break acc if context[:vcr_cassette] acc end end end |
#gsub_whitespace(name) ⇒ Object
31 32 33 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 31 def gsub_whitespace(name) name.gsub(/\s+/, '_') end |
#remove_hash_tags(name) ⇒ Object
35 36 37 |
# File 'lib/nxt_vcr_harness/cassette_name_by_example.rb', line 35 def (name) name.delete('#') end |