Skip to content

Commit

Permalink
Add specs for Options
Browse files Browse the repository at this point in the history
This brings the coverage in this file up to 100%.
  • Loading branch information
sds committed Apr 27, 2015
1 parent b000f60 commit e214244
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/slim_lint/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ def add_linter_options(parser)

parser.on('-r', '--reporter reporter', String,
'Specify which reporter you want to use to generate the output') do |reporter|
@options[:reporter] = SlimLint::Reporter.const_get("#{reporter.capitalize}Reporter")
@options[:reporter] = load_reporter_class(reporter.capitalize)
end
end

# Returns the class of the specified Reporter.
#
# @param reporter_name [String]
# @raise [SlimLint::Exceptions::InvalidCLIOption] if reporter doesn't exist
# @return [Class]
def load_reporter_class(reporter_name)
SlimLint::Reporter.const_get("#{reporter_name}Reporter")
rescue NameError
raise SlimLint::Exceptions::InvalidCLIOption,
"#{reporter_name}Reporter does not exist"
end

# Register file-related flags.
def add_file_options(parser)
parser.on('-c', '--config config-file', String,
Expand Down
26 changes: 26 additions & 0 deletions spec/slim_lint/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@
end
end

context 'with a reporter option' do
context 'for a reporter that exists' do
let(:args) { %w[--reporter Json] }

it 'sets the `reporter` option' do
subject.should include reporter: SlimLint::Reporter::JsonReporter
end
end

context 'for a reporter that exists when capitalized' do
let(:args) { %w[--reporter json] }

it 'sets the `reporter` option' do
subject.should include reporter: SlimLint::Reporter::JsonReporter
end
end

context 'for a reporter that does not exist' do
let(:args) { %w[--reporter NonExistent] }

it 'raises an error' do
expect { subject }.to raise_error SlimLint::Exceptions::InvalidCLIOption
end
end
end

context 'with the help option' do
let(:args) { ['--help'] }

Expand Down

0 comments on commit e214244

Please sign in to comment.