Skip to content

Commit

Permalink
Easier reporter setting form cli
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed Mar 3, 2013
1 parent 9bfe8b3 commit e4823bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions features/steps/reporting/use_customized_reporter.rb
Expand Up @@ -6,7 +6,7 @@ class UseCustomizedReporter < Spinach::FeatureSteps

before do
class_str = <<-EOF
class Spinach::TestReporter < Spinach::Reporter
class Spinach::Reporter::TestReporter < Spinach::Reporter
attr_reader :out, :error
attr_accessor :scenario_error
attr_accessor :scenario
Expand Down Expand Up @@ -89,7 +89,7 @@ class ASuccessFeature < Spinach::FeatureSteps
end

When 'I run it using the new reporter' do
run_feature @feature, append: "-r Spinach::TestReporter"
run_feature @feature, append: "-r test_reporter"
end

Then 'I see the desired output' do
Expand Down
21 changes: 19 additions & 2 deletions lib/spinach/cli.rb
Expand Up @@ -51,7 +51,7 @@ def feature_files
files_to_run = []

@args.each do |arg|
if arg.match /\.feature/
if arg.match(/\.feature/)
if File.exists? arg.gsub(/:\d*/, '')
files_to_run << arg
else
Expand Down Expand Up @@ -124,7 +124,7 @@ def parse_options

opts.on('-r', '--reporter CLASS_NAME',
'Formatter class name') do |class_name|
config[:reporter_class] = class_name
config[:reporter_class] = reporter_class(class_name)
end
end.parse!(@args)

Expand All @@ -145,5 +145,22 @@ def fail!(message=nil)
puts message if message
exit 1
end

# Builds the class name to use an output reporter.
#
# @param [String] klass
# The class name fo the reporter.
#
# @return [String]
# The full name of the reporter class.
#
# @example
# reporter_class('progress')
# # => Spinach::Reporter::Progress
#
# @api private
def reporter_class(klass)
"Spinach::Reporter::" + Spinach::Support.camelize(klass)
end
end
end
14 changes: 7 additions & 7 deletions test/spinach/cli_test.rb
Expand Up @@ -17,7 +17,7 @@
config = Spinach::Config.new
Spinach.stubs(:config).returns(config)
cli = Spinach::Cli.new([])
options = cli.options
cli.options
config[:reporter_options].must_equal({})
end

Expand Down Expand Up @@ -55,7 +55,7 @@
config = Spinach::Config.new
Spinach.stubs(:config).returns(config)
cli = Spinach::Cli.new([opt])
options = cli.options
cli.options
config[:reporter_options][:backtrace].must_equal true
end
end
Expand All @@ -66,9 +66,9 @@
it 'sets the reporter class' do
config = Spinach::Config.new
Spinach.stubs(:config).returns(config)
cli = Spinach::Cli.new([opt, "String"])
options = cli.options
config.reporter_class.must_equal 'String'
cli = Spinach::Cli.new([opt, 'progress'])
cli.options
config.reporter_class.must_equal 'Spinach::Reporter::Progress'
end
end
end
Expand Down Expand Up @@ -160,7 +160,7 @@
cli = Spinach::Cli.new([opt])
cli.expects(:exit)
cli.expects(:puts).with(Spinach::VERSION)
output = capture_stdout do
capture_stdout do
cli.options
end
end
Expand Down Expand Up @@ -195,7 +195,7 @@
cli = Spinach::Cli.new([opt])
cli.expects(:exit)
cli.expects(:puts).with("Invalid option: #{opt}")
options = cli.options
cli.options
end
end
end
Expand Down

0 comments on commit e4823bb

Please sign in to comment.