Class: RSpec::SpecificationCoverage::SpecFromFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/specification_coverage/spec_from_file.rb

Overview

Allows getting getting spec name from file name.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual, type) ⇒ SpecFromFile

Returns a new instance of SpecFromFile.

Parameters:

  • actual (String)

    for example ‘app/models/user.rb`

  • type (Symbol)

    the type, ‘nil`, `:routing`, `:requests`, `:lib`

Raises:

  • (::ArgumentError)


20
21
22
23
24
25
# File 'lib/rspec/specification_coverage/spec_from_file.rb', line 20

def initialize(actual, type)
  @actual = actual
  @type = type

  raise(::ArgumentError) unless valid?
end

Class Method Details

.is(actual, type) ⇒ Object

Parameters:

  • actual (String)

    for example ‘app/models/user.rb`

  • type (Symbol)

    the type, ‘nil`, `:routing`, `:requests`, `:lib`



14
15
16
# File 'lib/rspec/specification_coverage/spec_from_file.rb', line 14

def self.is(actual, type)
  new(actual, type).is
end

Instance Method Details

#isString

Returns like ‘spec/models/user_spec.rb`.

Returns:

  • (String)

    like ‘spec/models/user_spec.rb`



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/specification_coverage/spec_from_file.rb', line 28

def is
  case @type
  when :routing
    controller_replaced.gsub(/\.rb$/, "_#{@type}_spec.rb")
  when :requests
    controller_replaced.gsub(/\.rb$/, '_spec.rb')
  when :lib
    suffix_replaced.gsub(/^lib/, 'spec/lib')
  else
    suffix_replaced.gsub(/^lib/, 'spec')
  end
end