Class: PolishGeeks::DevTools::Commands::RspecFilesNames

Inherits:
Base
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/rspec_files_names.rb

Overview

Validator used to check if all the rspec spec files have a proper sufix (_spec.rb)

Constant Summary collapse

CHECKED_DIRS =

List of dirs in spec/ dir that we will check for _spec.rb naming

%w(
  aggregators controllers helpers lib libs models decorators
  presenters services workers mailers requests polishgeeks*
).freeze
CHECK_REGEXP =

Regexp used to check names in spec files

/(\_spec\.rb)$/

Constants inherited from Base

Base::TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#output, #stored_output

Instance Method Summary collapse

Methods inherited from Base

#ensure_executable!

Instance Attribute Details

#counterObject (readonly)

Returns the value of attribute counter.



9
10
11
# File 'lib/polish_geeks/dev_tools/commands/rspec_files_names.rb', line 9

def counter
  @counter
end

Instance Method Details

#error_messageString

Returns message that should be printed when some files have invalid name.

Returns:

  • (String)

    message that should be printed when some files have invalid name



52
53
54
# File 'lib/polish_geeks/dev_tools/commands/rspec_files_names.rb', line 52

def error_message
  "Following files have invalid name: \n #{output.join("\n")}\n"
end

#executeArray

Executes this command

Returns:

  • (Array)

    command output array with list of spec files that dont have a proper name



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/polish_geeks/dev_tools/commands/rspec_files_names.rb', line 24

def execute
  @output = []
  @counter = 0

  CHECKED_DIRS.each do |name|
    path = File.join(::PolishGeeks::DevTools.app_root, 'spec', name)
    files = Dir.glob("#{path}/**/*").select { |f| File.file? f }

    @counter += files.count

    files.each do |file|
      @output << file unless file =~ CHECK_REGEXP
    end
  end
end

#labelString

Returns default label for this command.

Returns:

  • (String)

    default label for this command



46
47
48
# File 'lib/polish_geeks/dev_tools/commands/rspec_files_names.rb', line 46

def label
  "Rspec files names: #{counter} files checked"
end

#valid?Boolean

Returns true if all specs have a proper sufix (_spec.rb).

Returns:

  • (Boolean)

    true if all specs have a proper sufix (_spec.rb)



41
42
43
# File 'lib/polish_geeks/dev_tools/commands/rspec_files_names.rb', line 41

def valid?
  output.empty?
end