Class: Runtest::Command
- Inherits:
-
Object
- Object
- Runtest::Command
- Defined in:
- lib/runtest/command.rb
Constant Summary collapse
- SYNTAX =
/^(test|should)\s(\"|\')|(\"|\')\sdo$/
Instance Attribute Summary collapse
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #base_command ⇒ Object
- #closest_example ⇒ Object
- #consolidated_command ⇒ Object
- #file_contents ⇒ Object
-
#initialize(argument) ⇒ Command
constructor
A new instance of Command.
- #line_at_line_number ⇒ Object
- #perform! ⇒ Object
- #run_test(options = "") ⇒ Object
Constructor Details
#initialize(argument) ⇒ Command
Returns a new instance of Command.
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_name ⇒ Object
Returns the value of attribute file_name.
4 5 6 |
# File 'lib/runtest/command.rb', line 4 def file_name @file_name end |
#line_number ⇒ Object
Returns the value of attribute line_number.
4 5 6 |
# File 'lib/runtest/command.rb', line 4 def line_number @line_number end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/runtest/command.rb', line 4 def @options end |
Instance Method Details
#base_command ⇒ Object
39 40 41 |
# File 'lib/runtest/command.rb', line 39 def base_command @base_command ||= "ruby -Itest" end |
#closest_example ⇒ Object
23 24 25 |
# File 'lib/runtest/command.rb', line 23 def closest_example line_at_line_number.gsub SYNTAX, '' end |
#consolidated_command ⇒ Object
56 57 58 |
# File 'lib/runtest/command.rb', line 56 def consolidated_command [ base_command, file_name, ].join ' ' end |
#file_contents ⇒ Object
47 48 49 |
# File 'lib/runtest/command.rb', line 47 def file_contents File.read(file_name).split "\n" end |
#line_at_line_number ⇒ Object
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 = system consolidated_command end |