Remove default format option #98

Merged
merged 3 commits into from May 12, 2012
@@ -62,13 +62,23 @@ def rspec_class
end
end
+ def default_formatter
+ @default_formatter ||= unless @options[:cli] =~ formatter_regex
+ file_name = "#{Dir.pwd}/.rspec"
+ if File.exist?(file_name)
+ s = File.read(file_name)
+ s.scan(formatter_regex).flatten.map{|i| "-f #{i}"}.join(' ')
+ end
+ end || '-f progress'
+ end
+
private
def rspec_arguments(paths, options)
arg_parts = []
arg_parts << options[:cli]
- arg_parts << "-f progress" if !options[:cli] || options[:cli].split(/[\s=]/).none? { |w| %w[-f --format].include?(w) }
if @options[:notification]
+ arg_parts << default_formatter unless options[:cli] =~ formatter_regex
arg_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_#{rspec_class.downcase}.rb"
arg_parts << "-f Guard::RSpec::Formatter::Notification#{rspec_class}#{rspec_version == 1 ? ":" : " --out "}/dev/null"
end
@@ -84,7 +94,6 @@ def rspec_command(paths, options)
cmd_parts << "bundle exec" if bundler?
cmd_parts << rspec_executable
cmd_parts << rspec_arguments(paths, options)
-
cmd_parts.compact.join(' ')
end
@@ -199,6 +208,10 @@ def deprecations_warnings
end
end
+ def formatter_regex
+ @formatter_regex ||= /(?:^|\s)(?:-f\s*|--format(?:=|\s+))(\w+)/
+ end
+
end
end
end
@@ -0,0 +1,2 @@
+--colour
+--format documentation
@@ -213,7 +213,33 @@
end
end
- context ":cli => '-f doc'" do
+ context ":cli => '-fdoc'" do
@thibaudgg
thibaudgg May 7, 2012 Member

space between '-fdoc' is missing.

@rymai
rymai May 7, 2012 Member

Hum, it actually also works without the space! ;)

@quaternion
quaternion May 8, 2012 Contributor

Example with space already exists. This example for option without space. OptionParser accepts mixing Unix and Gnu styles command line options:
Unix:

-f value
-fvalue

Gnu:

--format value
--format=value

Not accepts:

-f=value
@thibaudgg
thibaudgg May 12, 2012 Member

Ok, I didn't know.

+ subject { described_class.new(:cli => '-fdoc') }
+
+ it 'respects formatter passed in CLI options to RSpec' do
+ subject.should_receive(:system).with(
+ "bundle exec rspec -fdoc -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} " <<
+ '-f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec'
+ ).and_return(true)
+
+ subject.run(['spec'])
+ end
+ end
+
+ context ":cli => '--format doc'" do
+ subject { described_class.new(:cli => '--format doc') }
+
+ it 'respects formatter passed in CLI options to RSpec' do
+ subject.should_receive(:system).with(
+ "bundle exec rspec --format doc -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} " <<
+ '-f Guard::RSpec::Formatter::NotificationRSpec --out /dev/null --failure-exit-code 2 spec'
+ ).and_return(true)
+
+ subject.run(['spec'])
+ end
+ end
+
+ context ":cli => '--format=doc'" do
subject { described_class.new(:cli => '--format=doc') }
it 'respects formatter passed in CLI options to RSpec' do
@@ -276,7 +302,7 @@
it 'runs without notification formatter' do
subject.should_receive(:system).with(
- 'bundle exec rspec -f progress --failure-exit-code 2 spec'
+ 'bundle exec rspec --failure-exit-code 2 spec'
).and_return(true)
subject.run(['spec'])
@@ -356,4 +382,16 @@
end
end
+ describe '#default_formatter' do
+ before { Dir.stub(:pwd).and_return(@fixture_path) }
+ it 'returns formatter from .rspec file' do
+ subject.default_formatter.should eq '-f documentation'
+ end
+ context 'if .rspec file no exists' do
+ before { File.stub(:exist?).and_return(false) }
+ it 'returns progress formatter' do
+ subject.default_formatter.should eq '-f progress'
+ end
+ end
+ end
end