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
9
# File 'lib/approvals/namers/rspec_namer.rb', line 6

def initialize(example)
  @name = name_for_example(example)
  @output_dir = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#name_for_example(example) ⇒ Object



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

def name_for_example(example)
  normalize example.full_description
end

#normalize(string) ⇒ Object



15
16
17
# File 'lib/approvals/namers/rspec_namer.rb', line 15

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

#output_dirObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/approvals/namers/rspec_namer.rb', line 19

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