Skip to content

Commit

Permalink
Run on modifications instead of on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgarriott committed Dec 12, 2013
1 parent 8177a2a commit 638829a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def reload
# @param [Array<String>] paths the changed paths and files
# @raise [:task_has_failed] when stop has failed
#
def run_on_changes(paths)
def run_on_modifications(paths)
paths += @failed_paths if @options[:keep_failed]
paths = Inspector.clean(paths, options[:feature_sets])
options = @options[:change_format] ? change_format(@options[:change_format]) : @options
Expand Down
40 changes: 20 additions & 20 deletions spec/guard/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@

it 'cleans failed memory if passed' do
runner.should_receive(:run).with(['features/foo'], default_options).and_return(false)
expect { guard.run_on_changes(['features/foo']) }.to throw_symbol :task_has_failed
expect { guard.run_on_modifications(['features/foo']) }.to throw_symbol :task_has_failed
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
runner.should_receive(:run).with(['features/bar'], default_options).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end

it 'saves failed features' do
Expand All @@ -119,7 +119,7 @@

runner.should_receive(:run).with(['features/bar', 'features/foo'], default_options).and_return(true)
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end

context 'with the :feature_sets option' do
Expand Down Expand Up @@ -153,7 +153,7 @@
expect { guard.run_all }.to throw_symbol :task_has_failed
runner.should_receive(:run).with(['features/bar'], run_options).and_return(true)
runner.should_receive(:run).with(['features'], run_options.merge(:message => 'Running all features')).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end
end

Expand All @@ -172,50 +172,50 @@
describe '#reload' do
it 'clears failed_path' do
runner.should_receive(:run).with(['features/foo'], default_options).and_return(false)
expect { guard.run_on_changes(['features/foo']) }.to throw_symbol :task_has_failed
expect { guard.run_on_modifications(['features/foo']) }.to throw_symbol :task_has_failed
guard.reload
runner.should_receive(:run).with(['features/bar'], default_options).and_return(true)
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end
end

describe '#run_on_changes' do
describe '#run_on_modifications' do
it 'runs cucumber with all features' do
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
guard.run_on_changes(['features'])
guard.run_on_modifications(['features'])
end

it 'runs cucumber with single feature' do
runner.should_receive(:run).with(['features/a.feature'], default_options).and_return(true)
guard.run_on_changes(['features/a.feature'])
guard.run_on_modifications(['features/a.feature'])
end

it 'passes the matched paths to the inspector for cleanup' do
runner.stub(:run).and_return(true)
Guard::Cucumber::Inspector.should_receive(:clean).with(['features'], ['features']).and_return ['features']
guard.run_on_changes(['features'])
guard.run_on_modifications(['features'])
end

it 'calls #run_all if the changed specs pass after failing' do
runner.should_receive(:run).with(['features/foo'], default_options).and_return(false, true)
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
expect { guard.run_on_changes(['features/foo']) }.to throw_symbol :task_has_failed
guard.run_on_changes(['features/foo'])
expect { guard.run_on_modifications(['features/foo']) }.to throw_symbol :task_has_failed
guard.run_on_modifications(['features/foo'])
end

it 'does not call #run_all if the changed specs pass without failing' do
runner.should_receive(:run).with(['features/foo'], default_options).and_return(true)
runner.should_not_receive(:run).with(['features'], default_options.merge(:message => 'Running all features'))
guard.run_on_changes(['features/foo'])
guard.run_on_modifications(['features/foo'])
end

context 'with a :cli option' do
let(:guard) { Guard::Cucumber.new([], { :cli => '--color' }) }

it 'directly passes the :cli option to the runner' do
runner.should_receive(:run).with(['features'], default_options.merge(:cli => '--color', :message => 'Running all features')).and_return(true)
guard.run_on_changes(['features'])
guard.run_on_modifications(['features'])
end
end

Expand All @@ -225,8 +225,8 @@
it 'does not call #run_all if the changed specs pass after failing but the :all_after_pass option is false' do
runner.should_receive(:run).with(['features/foo'], default_options.merge(:all_after_pass => false)).and_return(false, true)
runner.should_not_receive(:run).with(['features'], default_options.merge(:all_after_pass => false, :message => 'Running all features'))
expect { guard.run_on_changes(['features/foo']) }.to throw_symbol :task_has_failed
guard.run_on_changes(['features/foo'])
expect { guard.run_on_modifications(['features/foo']) }.to throw_symbol :task_has_failed
guard.run_on_modifications(['features/foo'])
end
end

Expand All @@ -241,12 +241,12 @@
runner.should_receive(:run).with(['features/foo'], default_options).and_return(false)
File.should_receive(:exist?).with('rerun.txt').and_return true
File.should_receive(:delete).with('rerun.txt')
expect { guard.run_on_changes(['features/foo']) }.to throw_symbol :task_has_failed
expect { guard.run_on_modifications(['features/foo']) }.to throw_symbol :task_has_failed
runner.should_receive(:run).with(['features/bar', 'features/foo'], default_options).and_return(true)
runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
runner.should_receive(:run).with(['features/bar'], default_options).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end
end

Expand All @@ -258,7 +258,7 @@
it 'uses the change formatter if one is given' do
runner.should_receive(:run).with(['features/bar'], default_options.merge(:change_format => 'pretty',
:cli => expected_cli)).and_return(true)
guard.run_on_changes(['features/bar'])
guard.run_on_modifications(['features/bar'])
end
end
end
Expand Down

0 comments on commit 638829a

Please sign in to comment.