Class: MethodMatch::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/method_match/command_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(matcher) ⇒ CommandRunner

Returns a new instance of CommandRunner.



4
5
6
# File 'lib/method_match/command_runner.rb', line 4

def initialize matcher
  @matcher = matcher
end

Instance Method Details

#rspec_commandObject



18
19
20
21
22
23
# File 'lib/method_match/command_runner.rb', line 18

def rspec_command
  command = "rspec #{@matcher.spec_name}"
  command += " -e '#{rspec_method}'" if @matcher.method_name
  command += ":#{@matcher.line}" if @matcher.spec?
  command
end

#rspec_methodObject



25
26
27
28
# File 'lib/method_match/command_runner.rb', line 25

def rspec_method
  return @matcher.method_name.sub('self.', '.') if @matcher.method_name[0..4] == 'self.'
  "##{@matcher.method_name}"
end

#run_commandObject



8
9
10
11
12
13
14
15
16
# File 'lib/method_match/command_runner.rb', line 8

def run_command
  require 'pathname'
  if Pathname.new(@matcher.spec_name).file?
    ::Pry.run_command rspec_command
    return true
  end
  puts "Spec #{@matcher.spec_name} does not exist"
  false
end