lib/focused_test.rb in focused-test-0.4.0 vs lib/focused_test.rb in focused-test-0.5.0
- old
+ new
@@ -11,39 +11,48 @@
def initialize(*args)
parse args
end
def run
- test_type = nil
- current_method = nil
+ strategy_for_file.call
+ end
+ private
+ def strategy_for_file
+ if @file_path =~ /\.feature/
+ return proc { run_feature }
+ elsif @file_path =~ /_spec\.rb/
+ return proc { run_example }
+ end
+
content = IO.read(@file_path)
if content =~ /class .*Test < (.*TestCase|ActionController::IntegrationTest)/
if content =~ /should\s+['"].*['"]\s+do/
- run_should content
+ return proc { run_should content }
else
- run_test content
+ return proc { run_test content }
end
- else
- run_example
end
end
protected
def parse(args)
@file_path = nil
@line_number = nil
+ @format = nil
@rspec_version = ""
@show_backtrace = false
+
options = OptionParser.new do |o|
o.on('-f', '--filepath=FILEPATH', String, "File to run test on") do |path|
@file_path = path
end
o.on('-l', '--linenumber=LINENUMBER', Integer, "Line of the test") do |line|
@line_number = line
end
+
o.on('-r', '--rspec-version=VERSION', String, "Version of Rspec to Run") do |version|
@rspec_version = "_#{version}_"
end
o.on('-b', '--backtrace', String, "Show the backtrace of errors") do
@@ -51,10 +60,14 @@
end
o.on('-X', '--drb', String, "Run examples via DRb.") do
@drb = true
end
+
+ o.on('-F', '--format=FORMAT', String, "Output formatter for rspec or cucumber") do |format|
+ @format = format
+ end
end
options.order(args)
end
def run_test(content)
@@ -80,11 +93,10 @@
end
runner.run
puts "Running '#{current_method}' in file #{@file_path}" unless current_method.nil?
end
-
def run_should(content)
unless @line_number
return run_test(content)
end
@@ -126,12 +138,29 @@
cmd = (RUBY_PLATFORM =~ /[^r]win/) ? "spec.cmd" : "spec" unless cmd
cmd << "#{@rspec_version} #{@file_path}"
cmd << " --line #{@line_number}" if @line_number
cmd << ' --backtrace' if @show_backtrace
cmd << ' --drb' if @drb
+ cmd << " --format #{@format ? @format : 'progress'}"
system cmd
end
+
+ def run_feature
+ cmd = ""
+ ["script/cucumber", `which cucumber`.strip, "/usr/bin/cucumber"].each do |cucumber_executable|
+ if File.exists?(cucumber_executable)
+ cmd = cucumber_executable
+ break
+ end
+ end
+
+ cmd << " #{@file_path}"
+ cmd << ":#{@line_number}" if @line_number
+ cmd << " --format #{@format ? @format : 'pretty'}"
+ system cmd
+ end
+
def parse_from_quotes(name)
name.to_s.gsub(/^(?:.*"(.*)"|.*'(.*)').*$/) { $1 || $2 }
end
-end
\ No newline at end of file
+end