Class: Runtest::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/runtest/command.rb

Constant Summary collapse

SYNTAX =
/^(test|should)\s(\"|\')|(\"|\')\sdo$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argument) ⇒ Command

Returns a new instance of Command.

Raises:



6
7
8
9
10
11
12
13
# File 'lib/runtest/command.rb', line 6

def initialize argument
  arguments = argument.split ':'
  @file_name =  arguments[0] || ""
  @line_number = arguments[1].to_i || 0
  @base_command = "bundle exec ruby -Itest"

  raise FileNotFound unless File.exists? file_name
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



4
5
6
# File 'lib/runtest/command.rb', line 4

def file_name
  @file_name
end

#line_numberObject

Returns the value of attribute line_number.



4
5
6
# File 'lib/runtest/command.rb', line 4

def line_number
  @line_number
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/runtest/command.rb', line 4

def options
  @options
end

Instance Method Details

#base_commandObject



39
40
41
# File 'lib/runtest/command.rb', line 39

def base_command
  @base_command ||= "ruby -Itest"
end

#closest_exampleObject



23
24
25
# File 'lib/runtest/command.rb', line 23

def closest_example
  line_at_line_number.gsub SYNTAX, ''
end

#consolidated_commandObject



56
57
58
# File 'lib/runtest/command.rb', line 56

def consolidated_command
  [ base_command, file_name, options ].join ' '
end

#file_contentsObject



47
48
49
# File 'lib/runtest/command.rb', line 47

def file_contents
  File.read(file_name).split "\n"
end

#line_at_line_numberObject



43
44
45
# File 'lib/runtest/command.rb', line 43

def line_at_line_number
  file_contents[line_number].strip
end

#perform!Object



15
16
17
18
19
20
21
# File 'lib/runtest/command.rb', line 15

def perform!
  if line_number <= 0
    run_test
  else
    run_test "-n '#{closest_example}'"
  end
end

#run_test(options = "") ⇒ Object



51
52
53
54
# File 'lib/runtest/command.rb', line 51

def run_test options=""
  @options = options
  system consolidated_command
end