Class: Approvals::Namers::RSpecNamer

Inherits:
Object
  • Object
show all
Defined in:
lib/approvals/namers/rspec_namer.rb

Direct Known Subclasses

DirectoryNamer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ RSpecNamer

Returns a new instance of RSpecNamer.



6
7
8
# File 'lib/approvals/namers/rspec_namer.rb', line 6

def initialize(example)
  @name = normalize example.full_description
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/approvals/namers/rspec_namer.rb', line 5

def name
  @name
end

Instance Method Details

#normalize(string) ⇒ Object



10
11
12
# File 'lib/approvals/namers/rspec_namer.rb', line 10

def normalize(string)
  string.strip.squeeze(" ").gsub(/[\ :-]+/, '_').gsub(/[\W]/, '').downcase
end

#output_dirObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/approvals/namers/rspec_namer.rb', line 14

def output_dir
  unless @output_dir
    begin
      @output_dir = ::RSpec.configuration.approvals_path
    rescue NoMethodError => e
    end
    @output_dir ||= 'spec/fixtures/approvals/'
  end
  @output_dir
end