-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Application tests #688
Application tests #688
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,12 @@ def name | |
'mina' | ||
end | ||
|
||
# :nocov: | ||
def run | ||
Rake.application = self | ||
super | ||
end | ||
# :nocov: | ||
|
||
def sort_options(options) | ||
not_applicable_to_mina = %w(quiet silent verbose dry-run) | ||
|
@@ -27,8 +29,9 @@ def sort_options(options) | |
|
||
def top_level_tasks | ||
return @top_level_tasks if @top_level_tasks.include?('init') | ||
@top_level_tasks << :debug_configuration_variables | ||
@top_level_tasks << :run_commands | ||
|
||
@top_level_tasks << 'debug_configuration_variables' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All |
||
@top_level_tasks << 'run_commands' | ||
end | ||
|
||
private | ||
|
@@ -38,48 +41,53 @@ def minafile | |
end | ||
|
||
def version | ||
['--version', '-V', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The below code doesn't touch the logic, only style. |
||
'Display the program version.', | ||
lambda do |_value| | ||
puts "Mina, version v#{Mina::VERSION}" | ||
exit | ||
end | ||
[ | ||
'--version', '-V', | ||
'Display the program version.', | ||
lambda do |_value| | ||
puts "Mina, version v#{Mina::VERSION}" | ||
exit | ||
end | ||
] | ||
end | ||
|
||
def verbose | ||
['--verbose', '-v', | ||
'Print more info', | ||
lambda do |_value| | ||
set(:verbose, true) | ||
end | ||
[ | ||
'--verbose', '-v', | ||
'Print more info', | ||
lambda do |_value| | ||
set(:verbose, true) | ||
end | ||
] | ||
end | ||
|
||
def simulate | ||
['--simulate', '-s', | ||
'Do a simulate run without executing actions', | ||
lambda do |_value| | ||
set(:simulate, true) | ||
end | ||
[ | ||
'--simulate', '-s', | ||
'Do a simulate run without executing actions', | ||
lambda do |_value| | ||
set(:simulate, true) | ||
end | ||
] | ||
end | ||
|
||
def debug_configuration_variables | ||
['--debug-configuration-variables', '-d', | ||
'Display the defined config variables before runnig the tasks.', | ||
lambda do |_value| | ||
set(:debug_configuration_variables, true) | ||
end | ||
[ | ||
'--debug-configuration-variables', '-d', | ||
'Display the defined config variables before runnig the tasks.', | ||
lambda do |_value| | ||
set(:debug_configuration_variables, true) | ||
end | ||
] | ||
end | ||
|
||
def no_report_time | ||
['--no-report-time', nil, | ||
'Skip time reporting', | ||
lambda do |_value| | ||
set(:skip_report_time, true) | ||
end | ||
[ | ||
'--no-report-time', nil, | ||
'Skip time reporting', | ||
lambda do |_value| | ||
set(:skip_report_time, true) | ||
end | ||
] | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,100 @@ | ||
require 'spec_helper' | ||
|
||
describe Mina::Application do | ||
# let(:app) { Rake.application } | ||
# | ||
# %w(quiet silent dry-run).each do |switch| | ||
# it "doesn't include --#{switch} in help" do | ||
# binding.pry | ||
# expect(out).not_to match(/--#{switch}/) | ||
# end | ||
# end | ||
# | ||
# it 'runs adds two default tasks to the task list' do | ||
# expect(subject.top_level_tasks).to include(:debug_configuration_variables) | ||
# expect(subject.top_level_tasks).to include(:run_commands) | ||
# end | ||
# | ||
# it 'overrides the rake method, but still prints the rake version' do | ||
# out = capture_io do | ||
# flags '--version', '-V' | ||
# end | ||
# expect(out).to match(/\bMina, version\b/) | ||
# expect(out).to match(/\bv#{Mina::VERSION}\b/) | ||
# end | ||
# | ||
# it 'enables simulation mode, and sets the backend Mina::Runner::Printer' do | ||
# capture_io do | ||
# flags '--simulate', '-s' | ||
# end | ||
# expect(Mina::Configuration.instance.fetch(:simulate)).to be true | ||
# end | ||
# | ||
# it 'enables printing all config variables on command line parameter' do | ||
# capture_io do | ||
# flags '--debug-configuration-variables', '-d' | ||
# end | ||
# expect(Mina::Configuration.instance.fetch(:debug_configuration_variables)).to be true | ||
# end | ||
subject(:application) { described_class.new } | ||
|
||
describe '#top_level_tasks' do | ||
let(:default_tasks) { ['debug_configuration_variables', 'run_commands'] } | ||
|
||
context 'when `init` task is added' do | ||
it "removes default tasks" do | ||
expect do | ||
application.collect_command_line_tasks(['init']) | ||
end.to change(application, :top_level_tasks).from(default_tasks).to(['init']) | ||
end | ||
end | ||
|
||
context "when `init` task isn't added" do | ||
it "keeps default tasks" do | ||
expect do | ||
application.collect_command_line_tasks(['a_task']) | ||
end.to change(application, :top_level_tasks).from(default_tasks).to(['a_task', *default_tasks]) | ||
end | ||
end | ||
end | ||
|
||
describe 'command-line options' do | ||
['--version', '-V'].each do |option| | ||
describe option do | ||
it 'prints Mina version and exits' do | ||
expect do | ||
application.handle_options([option]) | ||
end.to raise_error(SystemExit) | ||
.and output("Mina, version v#{Mina::VERSION}\n").to_stdout | ||
end | ||
end | ||
end | ||
|
||
['--verbose', '-v'].each do |option| | ||
describe option do | ||
around do |example| | ||
original_flag = application.fetch(:verbose) | ||
example.run | ||
application.set(:verbose, original_flag) | ||
end | ||
|
||
it 'sets verbose flag to true' do | ||
expect do | ||
application.handle_options([option]) | ||
end.to change { application.fetch(:verbose) }.from(nil).to(true) | ||
end | ||
end | ||
end | ||
|
||
['--simulate', '-s'].each do |option| | ||
describe option do | ||
around do |example| | ||
original_flag = application.fetch(:simulate) | ||
example.run | ||
application.set(:simulate, original_flag) | ||
end | ||
|
||
it 'sets simulate flag to true' do | ||
expect do | ||
application.handle_options([option]) | ||
end.to change { application.fetch(:simulate) }.from(nil).to(true) | ||
end | ||
end | ||
end | ||
|
||
['--debug-configuration-variables', '-d'].each do |option| | ||
describe option do | ||
around do |example| | ||
original_flag = application.fetch(:debug_configuration_variables) | ||
example.run | ||
application.set(:debug_configuration_variables, original_flag) | ||
end | ||
|
||
it 'sets debug_configuration_variables flag to true' do | ||
expect do | ||
application.handle_options([option]) | ||
end.to change { application.fetch(:debug_configuration_variables) }.from(nil).to(true) | ||
end | ||
end | ||
end | ||
|
||
describe '--no-report-time' do | ||
around do |example| | ||
original_flag = application.fetch(:skip_report_time) | ||
example.run | ||
application.set(:skip_report_time, original_flag) | ||
end | ||
|
||
it 'sets skip_report_time flag to true' do | ||
expect do | ||
application.handle_options(['--no-report-time']) | ||
end.to change { application.fetch(:skip_report_time) }.from(nil).to(true) | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this method from simplecov coverage because there's no easy way to test this without invoking a task.