Class: Kamaze::Project::Tools::Rspec

Inherits:
BaseTool show all
Includes:
Concern::Cli::WithExitOnFailure
Defined in:
lib/kamaze/project/tools/rspec.rb

Overview

Provide wrapper based on top of RSpec::Core::Runner

Sample of use:

tools.fetch(:rspec).tap do |rspec|
  rspec.tags = args[:tags].to_s.split(',').map(&:strip)
end.run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Kamaze::Project::Tools::BaseTool

Instance Attribute Details

#defaultsArguments

Default arguments used by RSpec::Core::Runner

Returns:

  • (Arguments)


32
33
34
# File 'lib/kamaze/project/tools/rspec.rb', line 32

def defaults
  @defaults
end

#observer_peersHash|nil (readonly, protected) Originally defined in module Concern::Observable

Returns:

  • (Hash|nil)

#stderrObject

Returns the value of attribute stderr.



36
37
38
# File 'lib/kamaze/project/tools/rspec.rb', line 36

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



34
35
36
# File 'lib/kamaze/project/tools/rspec.rb', line 34

def stdout
  @stdout
end

#tagsArray<String>

Returns:

  • (Array<String>)


39
40
41
# File 'lib/kamaze/project/tools/rspec.rb', line 39

def tags
  @tags
end

Instance Method Details

#argumentsArguments

Arguments used by CLI (during execution/run)

Returns:

  • (Arguments)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/kamaze/project/tools/rspec.rb', line 61

def arguments
  @arguments = @defaults if @arguments.to_a.size.zero?

  tags.to_a.each do |tag|
    next if @arguments.slice_before('--tag').to_a.include?(['--tag', tag])

    @arguments += ['--tag', tag]
  end

  # @formatter:off
  {
    true => @arguments,
    false => @arguments.clone.concat(options_arguments).map(&:to_s).freeze
  }.fetch(caller_locations(1..1).first&.path == __FILE__)
  # @formatter:on
end

#coreRSpec::Core::Runner (protected)

Returns:

  • (RSpec::Core::Runner)


100
101
102
103
104
# File 'lib/kamaze/project/tools/rspec.rb', line 100

def core
  require 'rspec/core'

  RSpec::Core::Runner
end

#failure?Boolean Also known as: failed? Originally defined in module Concern::Cli

Denote execution is a failure.

Returns:

  • (Boolean)

#mutable_attributesObject



41
42
43
# File 'lib/kamaze/project/tools/rspec.rb', line 41

def mutable_attributes
  [:defaults, :stdout, :stderr]
end

#options_argumentsArray<String> (protected)

Returns:

  • (Array<String>)


107
108
109
110
111
112
113
114
115
116
# File 'lib/kamaze/project/tools/rspec.rb', line 107

def options_arguments
  options_files = Pathname.new(Dir.pwd).join('.rspec')
  defaults = []

  if options_files.file? and options_files.readable?
    defaults += ['-O', '.rspec']
  end

  defaults
end

#resetself (protected)

Reset arguments + retcode

Returns:

  • (self)


83
84
85
86
87
88
# File 'lib/kamaze/project/tools/rspec.rb', line 83

def reset
  @arguments = nil
  self.retcode = nil if retcode.to_i.zero?

  self
end

#retcodeFixnum Originally defined in module Concern::Cli

Status code usable to eventually initiates the termination.

Returns:

  • (Fixnum)

#runself

Returns:

  • (self)

Raises:

  • (SystemExit)


47
48
49
50
51
52
53
54
55
56
# File 'lib/kamaze/project/tools/rspec.rb', line 47

def run
  with_exit_on_failure do
    options = arguments.concat(options_arguments).map(&:to_s)

    self.retcode = core.run(options, stderr, stdout).to_i
    reset
  end

  self
end

#setupObject (protected)



90
91
92
93
94
95
96
97
# File 'lib/kamaze/project/tools/rspec.rb', line 90

def setup
  reset

  @tags = []
  @stdout ||= $stdout
  @stderr ||= $stderr
  @defaults ||= []
end

#success?Boolean Also known as: successful? Originally defined in module Concern::Cli

Denote execution is a success.

Returns:

  • (Boolean)

#with_exit_on_failure {|Object| ... } ⇒ Object (protected) Originally defined in module Concern::Cli::WithExitOnFailure

Initiates termination by raising SystemExit exception depending on success of given block.

Yields:

Yield Parameters:

  • (self)

Returns:

Raises:

  • (SystemExit)