lib/respec/app.rb in respec-0.2.0 vs lib/respec/app.rb in respec-0.3.0
- old
+ new
@@ -8,18 +8,17 @@
@raw_args = args[1..-1]
else
@args = args
@raw_args = []
end
- @formatter = 'progress'
@selected_failures = false
@update_failures = true
process_args
end
def command
- @command ||= bundler_args + ['rspec'] + formatter_args + generated_args + raw_args
+ @command ||= bundler_args + ['rspec'] + formatter_args + default_formatter_args + generated_args + raw_args
end
def bundler_args
if File.exist?(ENV['BUNDLE_GEMFILE'] || 'Gemfile')
['bundle', 'exec']
@@ -29,44 +28,57 @@
end
def formatter_args
if @update_failures
formatter_path = File.expand_path('formatter.rb', File.dirname(__FILE__))
- ['--require', formatter_path, '--format', 'Respec::Formatter', '--out', failures_path, '--format', @formatter]
+ ['--require', formatter_path, '--format', 'Respec::Formatter', '--out', failures_path]
else
[]
end
end
+ def default_formatter_args
+ args = @generated_args + @raw_args + dotfile_args
+ if args.include?('-f') || args.include?('--format') || args.include?('--formatter')
+ []
+ else
+ ['--format', 'progress']
+ end
+ end
+
attr_reader :generated_args, :raw_args
class << self
attr_accessor :failures_path
+ attr_accessor :local_rspec_config_path
+ attr_accessor :global_rspec_config_path
end
self.failures_path = ENV['RESPEC_FAILURES'] || File.expand_path(".respec_failures")
+ self.local_rspec_config_path = '.rspec'
+ self.global_rspec_config_path = File.expand_path('~/.rspec')
def help_only?
@help_only
end
def help
<<-EOS.gsub(/^ *\|/, '')
|USAGE: respec RESPEC-ARGS ... [ -- RSPEC-ARGS ... ]
|
- |Run rspec recording failed examples for easy rerunning later.
+ |Run rspec, recording failed examples for easy rerunning later.
|
|RESPEC-ARGS may consist of:
|
- | f Rerun all failed examples
- | <integer> Rerun only the n-th failure
- | <file name> Run specs in these files
- | <other> Run only examples matching this pattern
- | --help This! (Also 'help'.)
- | -<anything> Passed directly to rspec.
+ | f Rerun all failed examples
+ | <N> Rerun only the N-th failure
+ | <file name> Run all specs in this file
+ | <file name:N> Run specs at line N in this file
+ | <other> Run only examples matching this pattern
+ | -<anything> Passed directly to rspec.
+ | --help This! (Also 'help'.)
|
- |RSPEC-ARGS may follow a '--' argument, and are also passed
- |directly to rspec.
+ |Any arguments following a '--' argument are passed directly to rspec.
|
|More info: http://github.com/oggy/respec
EOS
end
@@ -100,12 +112,10 @@
@selected_failures = true
end
else
warn "no fail file - ignoring 'f' argument"
end
- elsif arg == 's'
- @formatter = 'specdoc'
elsif arg =~ /\A\d+\z/
i = Integer(arg)
if (failure = failures[i - 1])
args << failure
@selected_failures = true
@@ -115,16 +125,22 @@
end
else
args << '--example' << arg.gsub(/[$]/, '\\\\\\0')
end
end
- # If we selected individual failures to rerun, don't give the
- # files to rspec, as those files will be run in entirety.
+ # If we selected individual failures to rerun, don't give the files to
+ # rspec, as those files will be run in their entirety.
@generated_args = args
@generated_args.concat(files) unless @selected_failures
end
+ def dotfile_args
+ [self.class.local_rspec_config_path, self.class.global_rspec_config_path].map do |path|
+ File.exist?(path) ? File.read(path) : ''
+ end.join(' ').split
+ end
+
def failures_path
self.class.failures_path
end
def failures
@@ -146,10 +162,10 @@
-O --options
--order
--seed
--failure-exit-code
--drb-port
- -f --format
+ -f --format --formatter
-o --out
-P --pattern
-e --example
-l --line_number
-t --tag