diff --git a/spec/guard/cli_spec.rb b/spec/guard/cli_spec.rb index 7ceae7ae7..ae3907974 100644 --- a/spec/guard/cli_spec.rb +++ b/spec/guard/cli_spec.rb @@ -6,16 +6,16 @@ let(:ui) { Guard::UI } describe '#start' do - before { Guard.stub(:start) } + before { allow(Guard).to receive(:start) } it 'delegates to Guard.start' do - guard.should_receive(:start) + expect(guard).to receive(:start) subject.start end context 'with a Gemfile in the project dir' do before do - File.stub(:exists?).with('Gemfile').and_return true + allow(File).to receive(:exists?).with('Gemfile').and_return true end context 'when running with Bundler' do @@ -27,7 +27,7 @@ after { ENV['BUNDLE_GEMFILE'] = @bundler_env } it 'does not show the Bundler warning' do - ui.should_not_receive(:info).with(/Guard here!/) + expect(ui).not_to receive(:info).with(/Guard here!/) subject.start end end @@ -41,12 +41,12 @@ after { ENV['BUNDLE_GEMFILE'] = @bundler_env } it 'does show the Bundler warning' do - ui.should_receive(:info).with(/Guard here!/) + expect(ui).to receive(:info).with(/Guard here!/) subject.start end it 'does not show the Bundler warning with the :no_bundler_warning flag' do - ui.should_not_receive(:info).with(/Guard here!/) + expect(ui).not_to receive(:info).with(/Guard here!/) subject.options = { :no_bundler_warning => true } subject.start end @@ -55,7 +55,7 @@ context 'without a Gemfile in the project dir' do before do - File.should_receive(:exists?).with('Gemfile').and_return false + expect(File).to receive(:exists?).with('Gemfile').and_return false @bundler_env = ENV['BUNDLE_GEMFILE'] ENV['BUNDLE_GEMFILE'] = nil end @@ -63,7 +63,7 @@ after { ENV['BUNDLE_GEMFILE'] = @bundler_env } it 'does not show the Bundler warning' do - ui.should_not_receive(:info).with(/Guard here!/) + expect(ui).not_to receive(:info).with(/Guard here!/) subject.start end end @@ -71,14 +71,14 @@ describe '#list' do it 'outputs the Guard::DslDescriber.list result' do - ::Guard::DslDescriber.should_receive(:list) + expect(::Guard::DslDescriber).to receive(:list) subject.list end end describe '#version' do it 'shows the current version' do - subject.should_receive(:puts).with(/#{ ::Guard::VERSION }/) + expect(subject).to receive(:puts).with(/#{ ::Guard::VERSION }/) subject.version end end @@ -87,31 +87,31 @@ let(:options) { { :bare => false } } before do - subject.stub(:options => options) - Guard::Guardfile.stub(:create_guardfile) - Guard::Guardfile.stub(:initialize_all_templates) + allow(subject).to receive(:options).and_return(options) + allow(Guard::Guardfile).to receive(:create_guardfile) + allow(Guard::Guardfile).to receive(:initialize_all_templates) end it 'creates a Guardfile by delegating to Guardfile.create_guardfile' do - Guard::Guardfile.should_receive(:create_guardfile).with(:abort_on_existence => options[:bare]) + expect(Guard::Guardfile).to receive(:create_guardfile).with(:abort_on_existence => options[:bare]) subject.init end it 'initializes the templates of all installed Guards by delegating to Guardfile.initialize_all_templates' do - Guard::Guardfile.should_receive(:initialize_all_templates) + expect(Guard::Guardfile).to receive(:initialize_all_templates) subject.init end it 'initializes each passed template by delegating to Guardfile.initialize_template' do - Guard::Guardfile.should_receive(:initialize_template).with('rspec') - Guard::Guardfile.should_receive(:initialize_template).with('pow') + expect(Guard::Guardfile).to receive(:initialize_template).with('rspec') + expect(Guard::Guardfile).to receive(:initialize_template).with('pow') subject.init 'rspec','pow' end context 'when passed a guard name' do it 'initializes the template of the passed Guard by delegating to Guardfile.initialize_template' do - Guard::Guardfile.should_receive(:initialize_template).with('rspec') + expect(Guard::Guardfile).to receive(:initialize_template).with('rspec') subject.init 'rspec' end end @@ -120,9 +120,9 @@ let(:options) { {:bare => true} } it 'Only creates the Guardfile and does not initialize any Guard template' do - Guard::Guardfile.should_receive(:create_guardfile) - Guard::Guardfile.should_not_receive(:initialize_template) - Guard::Guardfile.should_not_receive(:initialize_all_templates) + expect(Guard::Guardfile).to receive(:create_guardfile) + expect(Guard::Guardfile).not_to receive(:initialize_template) + expect(Guard::Guardfile).not_to receive(:initialize_all_templates) subject.init end @@ -137,7 +137,7 @@ after { ENV['BUNDLE_GEMFILE'] = @bundler_env } it 'does not show the Bundler warning' do - ui.should_not_receive(:info).with(/Guard here!/) + expect(ui).not_to receive(:info).with(/Guard here!/) subject.init end end @@ -151,7 +151,7 @@ after { ENV['BUNDLE_GEMFILE'] = @bundler_env } it 'does not show the Bundler warning' do - ui.should_receive(:info).with(/Guard here!/) + expect(ui).to receive(:info).with(/Guard here!/) subject.init end end @@ -159,7 +159,7 @@ describe '#show' do it 'outputs the Guard::DslDescriber.list result' do - ::Guard::DslDescriber.should_receive(:list) + expect(::Guard::DslDescriber).to receive(:list) subject.list end end diff --git a/spec/guard/commands/all_spec.rb b/spec/guard/commands/all_spec.rb index 7f49ca63a..7c453107a 100644 --- a/spec/guard/commands/all_spec.rb +++ b/spec/guard/commands/all_spec.rb @@ -7,37 +7,37 @@ let(:bar_guard) { guard.add_guard(:bar, [], [], { :group => :foo }) } before do - Guard.stub(:run_all) - Guard.stub(:setup_interactor) - Pry.output.stub(:puts) + allow(Guard).to receive(:run_all) + allow(Guard).to receive(:setup_interactor) + allow(Pry.output).to receive(:puts) stub_const 'Guard::Bar', Class.new(Guard::Guard) end describe '#perform' do context 'without scope' do it 'runs the :run_all action' do - Guard.should_receive(:run_all).with({ :groups => [], :plugins => [] }) + expect(Guard).to receive(:run_all).with({ :groups => [], :plugins => [] }) Pry.run_command 'all' end end context 'with a valid Guard group scope' do it 'runs the :run_all action with the given scope' do - Guard.should_receive(:run_all).with({ :groups => [foo_group], :plugins => [] }) + expect(Guard).to receive(:run_all).with({ :groups => [foo_group], :plugins => [] }) Pry.run_command 'all foo' end end context 'with a valid Guard plugin scope' do it 'runs the :run_all action with the given scope' do - Guard.should_receive(:run_all).with({ :plugins => [bar_guard], :groups => [] }) + expect(Guard).to receive(:run_all).with({ :plugins => [bar_guard], :groups => [] }) Pry.run_command 'all bar' end end context 'with an invalid scope' do it 'does not run the action' do - Guard.should_not_receive(:run_all) + expect(Guard).not_to receive(:run_all) Pry.run_command 'all baz' end end diff --git a/spec/guard/commands/change_spec.rb b/spec/guard/commands/change_spec.rb index 5455340b2..b5ea2ef4a 100644 --- a/spec/guard/commands/change_spec.rb +++ b/spec/guard/commands/change_spec.rb @@ -5,28 +5,28 @@ let!(:guard) { ::Guard.setup } before do - Guard.runner.stub(:run_on_changes) - Pry.output.stub(:puts) + allow(Guard.runner).to receive(:run_on_changes) + allow(Pry.output).to receive(:puts) end describe '#perform' do context 'with a file' do it 'runs the :run_on_changes action with the given scope' do - ::Guard.runner.should_receive(:run_on_changes).with(['foo'], [], []) + expect(::Guard.runner).to receive(:run_on_changes).with(['foo'], [], []) Pry.run_command 'change foo' end end context 'with multiple files' do it 'runs the :run_on_changes action with the given scope' do - ::Guard.runner.should_receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], []) + expect(::Guard.runner).to receive(:run_on_changes).with(['foo', 'bar', 'baz'], [], []) Pry.run_command 'change foo bar baz' end end context 'without a file' do it 'does not run the :run_on_changes action' do - ::Guard.runner.should_not_receive(:run_on_changes) + expect(::Guard.runner).not_to receive(:run_on_changes) Pry.run_command 'change' end end diff --git a/spec/guard/commands/notification_spec.rb b/spec/guard/commands/notification_spec.rb index f8c6c50cd..9997c8e10 100644 --- a/spec/guard/commands/notification_spec.rb +++ b/spec/guard/commands/notification_spec.rb @@ -3,12 +3,12 @@ describe 'Guard::Interactor::NOTIFICATION' do before do - ::Guard::Notifier.stub(:toggle) + allow(::Guard::Notifier).to receive(:toggle) end describe '#perform' do it 'toggles the Guard notifier' do - ::Guard::Notifier.should_receive(:toggle) + expect(::Guard::Notifier).to receive(:toggle) Pry.run_command 'notification' end end diff --git a/spec/guard/commands/pause_spec.rb b/spec/guard/commands/pause_spec.rb index 39fd48c7f..4fb7517b3 100644 --- a/spec/guard/commands/pause_spec.rb +++ b/spec/guard/commands/pause_spec.rb @@ -3,12 +3,12 @@ describe 'Guard::Interactor::PAUSE' do before do - ::Guard::stub(:pause) + allow(::Guard)::to receive(:pause) end describe '#perform' do it 'pauses Guard' do - ::Guard.should_receive(:pause) + expect(::Guard).to receive(:pause) Pry.run_command 'pause' end end diff --git a/spec/guard/commands/reload_spec.rb b/spec/guard/commands/reload_spec.rb index 73325b969..53a8fa225 100644 --- a/spec/guard/commands/reload_spec.rb +++ b/spec/guard/commands/reload_spec.rb @@ -3,9 +3,9 @@ describe 'Guard::Interactor::RELOAD' do before do - Guard.stub(:reload) - Guard.stub(:setup_interactor) - Pry.output.stub(:puts) + allow(Guard).to receive(:reload) + allow(Guard).to receive(:setup_interactor) + allow(Pry.output).to receive(:puts) stub_const 'Guard::Bar', Class.new(Guard::Guard) end @@ -16,28 +16,28 @@ describe '#perform' do context 'without scope' do it 'runs the :reload action' do - Guard.should_receive(:reload).with({ :groups => [], :plugins => [] }) + expect(Guard).to receive(:reload).with({ :groups => [], :plugins => [] }) Pry.run_command 'reload' end end context 'with a valid Guard group scope' do it 'runs the :reload action with the given scope' do - Guard.should_receive(:reload).with({ :groups => [foo_group], :plugins => [] }) + expect(Guard).to receive(:reload).with({ :groups => [foo_group], :plugins => [] }) Pry.run_command 'reload foo' end end context 'with a valid Guard plugin scope' do it 'runs the :reload action with the given scope' do - Guard.should_receive(:reload).with({ :plugins => [bar_guard], :groups => [] }) + expect(Guard).to receive(:reload).with({ :plugins => [bar_guard], :groups => [] }) Pry.run_command 'reload bar' end end context 'with an invalid scope' do it 'does not run the action' do - Guard.should_not_receive(:reload) + expect(Guard).not_to receive(:reload) Pry.run_command 'reload baz' end end diff --git a/spec/guard/commands/scope_spec.rb b/spec/guard/commands/scope_spec.rb index c1fb2554f..afc65fa69 100644 --- a/spec/guard/commands/scope_spec.rb +++ b/spec/guard/commands/scope_spec.rb @@ -3,9 +3,9 @@ describe 'Guard::Interactor::SCOPE' do before do - Guard.stub(:scope=) - Guard.stub(:setup_interactor) - Pry.output.stub(:puts => true) + allow(Guard).to receive(:scope=) + allow(Guard).to receive(:setup_interactor) + allow(Pry.output).to receive(:puts).and_return(true) stub_const 'Guard::Bar', Class.new(Guard::Guard) end @@ -16,29 +16,29 @@ describe '#perform' do context 'without scope' do it 'does not call :scope=' do - Guard.should_not_receive(:scope=) - Pry.output.should_receive(:puts).with 'Usage: scope ' + expect(Guard).not_to receive(:scope=) + expect(Pry.output).to receive(:puts).with 'Usage: scope ' Pry.run_command 'scope' end end context 'with a valid Guard group scope' do it 'runs the :scope= action with the given scope' do - Guard.should_receive(:scope=).with({ :groups => [foo_group], :plugins => [] }) + expect(Guard).to receive(:scope=).with({ :groups => [foo_group], :plugins => [] }) Pry.run_command 'scope foo' end end context 'with a valid Guard plugin scope' do it 'runs the :scope= action with the given scope' do - Guard.should_receive(:scope=).with({ :plugins => [bar_guard], :groups => [] }) + expect(Guard).to receive(:scope=).with({ :plugins => [bar_guard], :groups => [] }) Pry.run_command 'scope bar' end end context 'with an invalid scope' do it 'does not run the action' do - Guard.should_not_receive(:scope=) + expect(Guard).not_to receive(:scope=) Pry.run_command 'scope baz' end end diff --git a/spec/guard/commands/show_spec.rb b/spec/guard/commands/show_spec.rb index 4e3db99a5..be3fbe36b 100644 --- a/spec/guard/commands/show_spec.rb +++ b/spec/guard/commands/show_spec.rb @@ -4,7 +4,7 @@ describe '#perform' do it 'outputs the DSL description' do - ::Guard::DslDescriber.should_receive(:show) + expect(::Guard::DslDescriber).to receive(:show) Pry.run_command 'show' end end diff --git a/spec/guard/dsl_describer_spec.rb b/spec/guard/dsl_describer_spec.rb index 387923b0c..d919ef88a 100644 --- a/spec/guard/dsl_describer_spec.rb +++ b/spec/guard/dsl_describer_spec.rb @@ -33,11 +33,11 @@ @output = '' # Strip escape sequences - STDOUT.stub(:tty?).and_return false + allow(STDOUT).to receive(:tty?).and_return false # Capture formatador output Thread.current[:formatador] = Formatador.new - Thread.current[:formatador].stub(:print) do |msg| + allow(Thread.current[:formatador]).to receive(:print) do |msg| @output << msg end end @@ -57,13 +57,13 @@ end before do - ::Guard.stub(:guard_gem_names).and_return %w(test another even more) + allow(::Guard).to receive(:guard_gem_names).and_return %w(test another even more) end it 'lists the available Guards when they\'re declared as strings or symbols' do ::Guard::DslDescriber.list(:guardfile_contents => guardfile) # Drop the calls to delete when drop Ruby 1.8.7 support - @output.delete(' ').should eq result.delete(' ') + expect(@output.delete(' ')).to eq result.delete(' ') end end @@ -86,7 +86,7 @@ it 'shows the Guards and their options' do ::Guard::DslDescriber.show(:guardfile_contents => guardfile) - @output.should eq result + expect(@output).to eq result end end diff --git a/spec/guard/dsl_spec.rb b/spec/guard/dsl_spec.rb index 88257218a..d528fc030 100644 --- a/spec/guard/dsl_spec.rb +++ b/spec/guard/dsl_spec.rb @@ -9,210 +9,210 @@ stub_const 'Guard::Dummy', Class.new(Guard::Guard) - ::Guard.stub(:setup_interactor) + allow(::Guard).to receive(:setup_interactor) ::Guard.setup - ::Guard.stub(:options).and_return(:debug => true) - ::Guard.stub(:guards).and_return([mock('Guard')]) + allow(::Guard).to receive(:options).and_return(:debug => true) + allow(::Guard).to receive(:guards).and_return([double('Guard')]) - ::Guard::Notifier.stub(:notify) + allow(::Guard::Notifier).to receive(:notify) end def self.disable_user_config - before(:each) { File.stub(:exist?).with(@user_config_path) { false } } + before(:each) { allow(File).to receive(:exist?).with(@user_config_path) { false } } end describe 'it should select the correct data source for Guardfile' do - before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) } + before(:each) { allow(::Guard::Dsl).to receive(:instance_eval_guardfile) } disable_user_config it 'should use a string for initializing' do - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error - described_class.guardfile_contents.should == valid_guardfile_string + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.not_to raise_error + expect(described_class.guardfile_contents).to eq(valid_guardfile_string) end it 'should use a given file over the default loc' do fake_guardfile('/abc/Guardfile', 'guard :foo') - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error - described_class.guardfile_contents.should == 'guard :foo' + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.not_to raise_error + expect(described_class.guardfile_contents).to eq('guard :foo') end it 'should use a default file if no other options are given' do fake_guardfile(@local_guardfile_path, 'guard :bar') - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile }.should_not raise_error - described_class.guardfile_contents.should == 'guard :bar' + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile }.not_to raise_error + expect(described_class.guardfile_contents).to eq('guard :bar') end it 'should use a string over any other method' do fake_guardfile('/abc/Guardfile', 'guard :foo') fake_guardfile(@local_guardfile_path, 'guard :bar') - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error - described_class.guardfile_contents.should == valid_guardfile_string + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.not_to raise_error + expect(described_class.guardfile_contents).to eq(valid_guardfile_string) end it 'should use the given Guardfile over default Guardfile' do fake_guardfile('/abc/Guardfile', 'guard :foo') fake_guardfile(@local_guardfile_path, 'guard :bar') - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error - described_class.guardfile_contents.should == 'guard :foo' + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.not_to raise_error + expect(described_class.guardfile_contents).to eq('guard :foo') end it 'should append the user config file if present' do fake_guardfile('/abc/Guardfile', 'guard :foo') fake_guardfile(@user_config_path, 'guard :bar') - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error - described_class.guardfile_contents_with_user_config.should == "guard :foo\nguard :bar" + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.not_to raise_error + expect(described_class.guardfile_contents_with_user_config).to eq("guard :foo\nguard :bar") end end it 'displays an error message when no Guardfile is found' do - described_class.stub(:guardfile_default_path).and_return('no_guardfile_here') - Guard::UI.should_receive(:error).with('No Guardfile found, please create one with `guard init`.') - lambda { described_class.evaluate_guardfile }.should raise_error + allow(described_class).to receive(:guardfile_default_path).and_return('no_guardfile_here') + expect(Guard::UI).to receive(:error).with('No Guardfile found, please create one with `guard init`.') + expect { described_class.evaluate_guardfile }.to raise_error end it 'doesn\'t display an error message when no Guard plugins are defined in Guardfile' do - ::Guard::Dsl.stub!(:instance_eval_guardfile) - ::Guard.stub!(:guards).and_return([]) - Guard::UI.should_not_receive(:error) + allow(::Guard::Dsl).to receive(:instance_eval_guardfile) + allow(::Guard).to receive(:guards).and_return([]) + expect(Guard::UI).not_to receive(:error) described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) end describe 'correctly reads data from its valid data source' do - before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) } + before(:each) { allow(::Guard::Dsl).to receive(:instance_eval_guardfile) } disable_user_config it 'reads correctly from a string' do - lambda { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.should_not raise_error - described_class.guardfile_contents.should == valid_guardfile_string + expect { described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) }.not_to raise_error + expect(described_class.guardfile_contents).to eq(valid_guardfile_string) end it 'reads correctly from a Guardfile' do fake_guardfile('/abc/Guardfile', 'guard :foo') - lambda { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.should_not raise_error - described_class.guardfile_contents.should == 'guard :foo' + expect { described_class.evaluate_guardfile(:guardfile => '/abc/Guardfile') }.not_to raise_error + expect(described_class.guardfile_contents).to eq('guard :foo') end it 'reads correctly from a Guardfile' do fake_guardfile(File.join(Dir.pwd, 'Guardfile'), valid_guardfile_string) - lambda { described_class.evaluate_guardfile }.should_not raise_error - described_class.guardfile_contents.should == valid_guardfile_string + expect { described_class.evaluate_guardfile }.not_to raise_error + expect(described_class.guardfile_contents).to eq(valid_guardfile_string) end end describe 'correctly throws errors when initializing with invalid data' do - before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) } + before(:each) { allow(::Guard::Dsl).to receive(:instance_eval_guardfile) } it 'raises error when there\'s a problem reading a file' do - File.stub!(:exist?).with('/def/Guardfile') { true } - File.stub!(:read).with('/def/Guardfile') { raise Errno::EACCES.new('permission error') } + allow(File).to receive(:exist?).with('/def/Guardfile') { true } + allow(File).to receive(:read).with('/def/Guardfile') { raise Errno::EACCES.new('permission error') } - Guard::UI.should_receive(:error).with(/^Error reading file/) - lambda { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error + expect(Guard::UI).to receive(:error).with(/^Error reading file/) + expect { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.to raise_error end it 'raises error when given Guardfile doesn\'t exist' do - File.stub!(:exist?).with('/def/Guardfile') { false } + allow(File).to receive(:exist?).with('/def/Guardfile') { false } - Guard::UI.should_receive(:error).with(/No Guardfile exists at/) - lambda { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.should raise_error + expect(Guard::UI).to receive(:error).with(/No Guardfile exists at/) + expect { described_class.evaluate_guardfile(:guardfile => '/def/Guardfile') }.to raise_error end it 'raises error when resorting to use default, finds no default' do - File.stub!(:exist?).with(@local_guardfile_path) { false } - File.stub!(:exist?).with(@home_guardfile_path) { false } + allow(File).to receive(:exist?).with(@local_guardfile_path) { false } + allow(File).to receive(:exist?).with(@home_guardfile_path) { false } - Guard::UI.should_receive(:error).with('No Guardfile found, please create one with `guard init`.') - lambda { described_class.evaluate_guardfile }.should raise_error + expect(Guard::UI).to receive(:error).with('No Guardfile found, please create one with `guard init`.') + expect { described_class.evaluate_guardfile }.to raise_error end it 'raises error when guardfile_content ends up empty or nil' do - Guard::UI.should_receive(:error).with('No Guard plugins found in Guardfile, please add at least one.') + expect(Guard::UI).to receive(:error).with('No Guard plugins found in Guardfile, please add at least one.') described_class.evaluate_guardfile(:guardfile_contents => '') end it 'doesn\'t raise error when guardfile_content is nil (skipped)' do - Guard::UI.should_not_receive(:error) - lambda { described_class.evaluate_guardfile(:guardfile_contents => nil) }.should_not raise_error + expect(Guard::UI).not_to receive(:error) + expect { described_class.evaluate_guardfile(:guardfile_contents => nil) }.not_to raise_error end end it 'displays an error message when Guardfile is not valid' do - Guard::UI.should_receive(:error).with(/Invalid Guardfile, original error is:/) + expect(Guard::UI).to receive(:error).with(/Invalid Guardfile, original error is:/) described_class.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string ) end describe '.reevaluate_guardfile' do - before(:each) { ::Guard::Dsl.stub!(:instance_eval_guardfile) } + before(:each) { allow(::Guard::Dsl).to receive(:instance_eval_guardfile) } it 'executes the before hook' do - ::Guard::Dsl.should_receive(:evaluate_guardfile) + expect(::Guard::Dsl).to receive(:evaluate_guardfile) described_class.reevaluate_guardfile end it 'evaluates the Guardfile' do - ::Guard::Dsl.should_receive(:before_reevaluate_guardfile) + expect(::Guard::Dsl).to receive(:before_reevaluate_guardfile) described_class.reevaluate_guardfile end it 'executes the after hook' do - ::Guard::Dsl.should_receive(:after_reevaluate_guardfile) + expect(::Guard::Dsl).to receive(:after_reevaluate_guardfile) described_class.reevaluate_guardfile end end describe '.before_reevaluate_guardfile' do it 'stops all Guards' do - ::Guard.runner.should_receive(:run).with(:stop) + expect(::Guard.runner).to receive(:run).with(:stop) described_class.before_reevaluate_guardfile end it 'clears all Guards' do - ::Guard.guards.should_not be_empty + expect(::Guard.guards).not_to be_empty described_class.reevaluate_guardfile - ::Guard.guards.should be_empty + expect(::Guard.guards).to be_empty end it 'resets all groups' do - ::Guard.groups.should_not be_empty + expect(::Guard.groups).not_to be_empty described_class.before_reevaluate_guardfile - ::Guard.groups.should_not be_empty - ::Guard.groups[0].name.should eq :default - ::Guard.groups[0].options.should == {} + expect(::Guard.groups).not_to be_empty + expect(::Guard.groups[0].name).to eq :default + expect(::Guard.groups[0].options).to eq({}) end it 'clears the notifications' do ::Guard::Notifier.turn_off ::Guard::Notifier.notifications = [{ :name => :growl }] - ::Guard::Notifier.notifications.should_not be_empty + expect(::Guard::Notifier.notifications).not_to be_empty described_class.before_reevaluate_guardfile - ::Guard::Notifier.notifications.should be_empty + expect(::Guard::Notifier.notifications).to be_empty end it 'removes the cached Guardfile content' do - ::Guard::Dsl.should_receive(:after_reevaluate_guardfile) + expect(::Guard::Dsl).to receive(:after_reevaluate_guardfile) described_class.after_reevaluate_guardfile end @@ -220,48 +220,48 @@ def self.disable_user_config describe '.after_reevaluate_guardfile' do context 'with notifications enabled' do - before { ::Guard::Notifier.stub(:enabled?).and_return true } + before { allow(::Guard::Notifier).to receive(:enabled?).and_return true } it 'enables the notifications again' do - ::Guard::Notifier.should_receive(:turn_on) + expect(::Guard::Notifier).to receive(:turn_on) described_class.after_reevaluate_guardfile end end context 'with notifications disabled' do - before { ::Guard::Notifier.stub(:enabled?).and_return false } + before { allow(::Guard::Notifier).to receive(:enabled?).and_return false } it 'does not enable the notifications again' do - ::Guard::Notifier.should_not_receive(:turn_on) + expect(::Guard::Notifier).not_to receive(:turn_on) described_class.after_reevaluate_guardfile end end context 'with Guards afterwards' do it 'shows a success message' do - ::Guard.runner.stub(:run) + allow(::Guard.runner).to receive(:run) - ::Guard::UI.should_receive(:info).with('Guardfile has been re-evaluated.') + expect(::Guard::UI).to receive(:info).with('Guardfile has been re-evaluated.') described_class.after_reevaluate_guardfile end it 'shows a success notification' do - ::Guard::Notifier.should_receive(:notify).with('Guardfile has been re-evaluated.', :title => 'Guard re-evaluate') + expect(::Guard::Notifier).to receive(:notify).with('Guardfile has been re-evaluated.', :title => 'Guard re-evaluate') described_class.after_reevaluate_guardfile end it 'starts all Guards' do - ::Guard.runner.should_receive(:run).with(:start) + expect(::Guard.runner).to receive(:run).with(:start) described_class.after_reevaluate_guardfile end end context 'without Guards afterwards' do - before { ::Guard.stub(:guards).and_return([]) } + before { allow(::Guard).to receive(:guards).and_return([]) } it 'shows a failure notification' do - ::Guard::Notifier.should_receive(:notify).with('No guards found in Guardfile, please add at least one.', :title => 'Guard re-evaluate', :image => :failed) + expect(::Guard::Notifier).to receive(:notify).with('No guards found in Guardfile, please add at least one.', :title => 'Guard re-evaluate', :image => :failed) described_class.after_reevaluate_guardfile end end @@ -270,54 +270,54 @@ def self.disable_user_config describe '.guardfile_default_path' do let(:local_path) { File.join(Dir.pwd, 'Guardfile') } let(:user_path) { File.expand_path(File.join("~", '.Guardfile')) } - before(:each) { File.stub(:exist? => false) } + before(:each) { allow(File).to receive(:exist?).and_return(false) } context 'when there is a local Guardfile' do it 'returns the path to the local Guardfile' do - File.stub(:exist?).with(local_path).and_return(true) - described_class.guardfile_default_path.should == local_path + allow(File).to receive(:exist?).with(local_path).and_return(true) + expect(described_class.guardfile_default_path).to eq(local_path) end end context 'when there is a Guardfile in the user\'s home directory' do it 'returns the path to the user Guardfile' do - File.stub(:exist?).with(user_path).and_return(true) - described_class.guardfile_default_path.should == user_path + allow(File).to receive(:exist?).with(user_path).and_return(true) + expect(described_class.guardfile_default_path).to eq(user_path) end end context 'when there\'s both a local and user Guardfile' do it 'returns the path to the local Guardfile' do - File.stub(:exist?).with(local_path).and_return(true) - File.stub(:exist?).with(user_path).and_return(true) - described_class.guardfile_default_path.should == local_path + allow(File).to receive(:exist?).with(local_path).and_return(true) + allow(File).to receive(:exist?).with(user_path).and_return(true) + expect(described_class.guardfile_default_path).to eq(local_path) end end end describe '.guardfile_include?' do it 'detects a guard specified by a string with double quotes' do - described_class.stub(:guardfile_contents => 'guard "test" {watch("c")}') + allow(described_class).to receive(:guardfile_contents).and_return('guard "test" {watch("c")}') - described_class.guardfile_include?('test').should be_true + expect(described_class.guardfile_include?('test')).to be_truthy end it 'detects a guard specified by a string with single quote' do - described_class.stub(:guardfile_contents => 'guard \'test\' {watch("c")}') + allow(described_class).to receive(:guardfile_contents).and_return('guard \'test\' {watch("c")}') - described_class.guardfile_include?('test').should be_true + expect(described_class.guardfile_include?('test')).to be_truthy end it 'detects a guard specified by a symbol' do - described_class.stub(:guardfile_contents => 'guard :test {watch("c")}') + allow(described_class).to receive(:guardfile_contents).and_return('guard :test {watch("c")}') - described_class.guardfile_include?('test').should be_true + expect(described_class.guardfile_include?('test')).to be_truthy end it 'detects a guard wrapped in parentheses' do - described_class.stub(:guardfile_contents => 'guard(:test) {watch("c")}') + allow(described_class).to receive(:guardfile_contents).and_return('guard(:test) {watch("c")}') - described_class.guardfile_include?('test').should be_true + expect(described_class.guardfile_include?('test')).to be_truthy end end @@ -325,7 +325,7 @@ def self.disable_user_config disable_user_config it 'adds the paths to the listener\'s ignore_paths' do - ::Guard::UI.should_receive(:deprecation).with(described_class::IGNORE_PATHS_DEPRECATION) + expect(::Guard::UI).to receive(:deprecation).with(described_class::IGNORE_PATHS_DEPRECATION) described_class.evaluate_guardfile(:guardfile_contents => 'ignore_paths \'foo\', \'bar\'') end @@ -333,12 +333,12 @@ def self.disable_user_config describe '#ignore' do disable_user_config - let(:listener) { stub } + let(:listener) { double } it 'add ignored regexps to the listener' do - ::Guard.stub(:listener) { listener } - ::Guard.listener.should_receive(:ignore).with(/^foo/,/bar/) { listener } - ::Guard.should_receive(:listener=).with(listener) + allow(::Guard).to receive(:listener) { listener } + expect(::Guard.listener).to receive(:ignore).with(/^foo/,/bar/) { listener } + expect(::Guard).to receive(:listener=).with(listener) described_class.evaluate_guardfile(:guardfile_contents => 'ignore %r{^foo}, /bar/') end @@ -346,12 +346,12 @@ def self.disable_user_config describe '#ignore!' do disable_user_config - let(:listener) { stub } + let(:listener) { double } it 'replace ignored regexps in the listener' do - ::Guard.stub(:listener) { listener } - ::Guard.listener.should_receive(:ignore!).with(/^foo/,/bar/) { listener } - ::Guard.should_receive(:listener=).with(listener) + allow(::Guard).to receive(:listener) { listener } + expect(::Guard.listener).to receive(:ignore!).with(/^foo/,/bar/) { listener } + expect(::Guard).to receive(:listener=).with(listener) described_class.evaluate_guardfile(:guardfile_contents => 'ignore! %r{^foo}, /bar/') end @@ -359,12 +359,12 @@ def self.disable_user_config describe '#filter' do disable_user_config - let(:listener) { stub } + let(:listener) { double } it 'add ignored regexps to the listener' do - ::Guard.stub(:listener) { listener } - ::Guard.listener.should_receive(:filter).with(/.txt$/, /.*.zip/) { listener } - ::Guard.should_receive(:listener=).with(listener) + allow(::Guard).to receive(:listener) { listener } + expect(::Guard.listener).to receive(:filter).with(/.txt$/, /.*.zip/) { listener } + expect(::Guard).to receive(:listener=).with(listener) described_class.evaluate_guardfile(:guardfile_contents => 'filter %r{.txt$}, /.*.zip/') end @@ -372,12 +372,12 @@ def self.disable_user_config describe '#filter!' do disable_user_config - let(:listener) { stub } + let(:listener) { double } it 'replace ignored regexps in the listener' do - ::Guard.stub(:listener) { listener } - ::Guard.listener.should_receive(:filter!).with(/.txt$/, /.*.zip/) { listener } - ::Guard.should_receive(:listener=).with(listener) + allow(::Guard).to receive(:listener) { listener } + expect(::Guard.listener).to receive(:filter!).with(/.txt$/, /.*.zip/) { listener } + expect(::Guard).to receive(:listener=).with(listener) described_class.evaluate_guardfile(:guardfile_contents => 'filter! %r{.txt$}, /.*.zip/') end @@ -387,13 +387,13 @@ def self.disable_user_config disable_user_config it 'adds a notification to the notifier' do - ::Guard::Notifier.should_receive(:add_notification).with(:growl, {}, false) + expect(::Guard::Notifier).to receive(:add_notification).with(:growl, {}, false) described_class.evaluate_guardfile(:guardfile_contents => 'notification :growl') end it 'adds multiple notification to the notifier' do - ::Guard::Notifier.should_receive(:add_notification).with(:growl, {}, false) - ::Guard::Notifier.should_receive(:add_notification).with(:ruby_gntp, { :host => '192.168.1.5' }, false) + expect(::Guard::Notifier).to receive(:add_notification).with(:growl, {}, false) + expect(::Guard::Notifier).to receive(:add_notification).with(:ruby_gntp, { :host => '192.168.1.5' }, false) described_class.evaluate_guardfile(:guardfile_contents => "notification :growl\nnotification :ruby_gntp, :host => '192.168.1.5'") end end @@ -402,20 +402,20 @@ def self.disable_user_config disable_user_config it 'disables the interactions with :off' do - ::Guard::UI.should_not_receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) + expect(::Guard::UI).not_to receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) described_class.evaluate_guardfile(:guardfile_contents => 'interactor :off') - Guard::Interactor.enabled.should be_false + expect(Guard::Interactor.enabled).to be_falsey end it 'shows a deprecation for symbols other than :off' do - ::Guard::UI.should_receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) + expect(::Guard::UI).to receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) described_class.evaluate_guardfile(:guardfile_contents => 'interactor :coolline') end it 'passes the options to the interactor' do - ::Guard::UI.should_not_receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) + expect(::Guard::UI).not_to receive(:deprecation).with(described_class::INTERACTOR_DEPRECATION) described_class.evaluate_guardfile(:guardfile_contents => 'interactor :option1 => \'a\', :option2 => 123') - Guard::Interactor.options.should include({ :option1 => 'a', :option2 => 123 }) + expect(Guard::Interactor.options).to include({ :option1 => 'a', :option2 => 123 }) end end @@ -423,11 +423,11 @@ def self.disable_user_config disable_user_config it 'evaluates all groups' do - ::Guard.should_receive(:add_guard).with('pow', [], [], { :group => :default }) - ::Guard.should_receive(:add_guard).with('test', [], [], { :group => :w }) - ::Guard.should_receive(:add_guard).with('rspec', [], [], { :group => :x }) - ::Guard.should_receive(:add_guard).with('ronn', [], [], { :group => :x }) - ::Guard.should_receive(:add_guard).with('less', [], [], { :group => :y }) + expect(::Guard).to receive(:add_guard).with('pow', [], [], { :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :group => :w }) + expect(::Guard).to receive(:add_guard).with('rspec', [], [], { :group => :x }) + expect(::Guard).to receive(:add_guard).with('ronn', [], [], { :group => :x }) + expect(::Guard).to receive(:add_guard).with('less', [], [], { :group => :y }) described_class.evaluate_guardfile(:guardfile_contents => valid_guardfile_string) end @@ -437,31 +437,31 @@ def self.disable_user_config disable_user_config it 'loads a guard specified as a quoted string from the DSL' do - ::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :group => :default }) described_class.evaluate_guardfile(:guardfile_contents => 'guard \'test\'') end it 'loads a guard specified as a double quoted string from the DSL' do - ::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :group => :default }) described_class.evaluate_guardfile(:guardfile_contents => 'guard "test"') end it 'loads a guard specified as a symbol from the DSL' do - ::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :group => :default }) described_class.evaluate_guardfile(:guardfile_contents => 'guard :test') end it 'loads a guard specified as a symbol and called with parens from the DSL' do - ::Guard.should_receive(:add_guard).with('test', [], [], { :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :group => :default }) described_class.evaluate_guardfile(:guardfile_contents => 'guard(:test)') end it 'receives options when specified, from normal arg' do - ::Guard.should_receive(:add_guard).with('test', [], [], { :opt_a => 1, :opt_b => 'fancy', :group => :default }) + expect(::Guard).to receive(:add_guard).with('test', [], [], { :opt_a => 1, :opt_b => 'fancy', :group => :default }) described_class.evaluate_guardfile(:guardfile_contents => 'guard \'test\', :opt_a => 1, :opt_b => \'fancy\'') end @@ -471,12 +471,12 @@ def self.disable_user_config disable_user_config it 'should receive watchers when specified' do - ::Guard.should_receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |_, watchers, _, _| - watchers.size.should eq 2 - watchers[0].pattern.should eq 'a' - watchers[0].action.call.should eq proc { 'b' }.call - watchers[1].pattern.should eq 'c' - watchers[1].action.should be_nil + expect(::Guard).to receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |_, watchers, _, _| + expect(watchers.size).to eq 2 + expect(watchers[0].pattern).to eq 'a' + expect(watchers[0].action.call).to eq proc { 'b' }.call + expect(watchers[1].pattern).to eq 'c' + expect(watchers[1].action).to be_nil end described_class.evaluate_guardfile(:guardfile_contents => ' guard :dummy do @@ -494,12 +494,12 @@ def self.call(guard_class, event, args) end end - ::Guard.should_receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |name, watchers, callbacks, options| - callbacks.should have(2).items - callbacks[0][:events].should eq :start_end - callbacks[0][:listener].call(Guard::Dummy, :start_end, 'foo').should eq 'Guard::Dummy executed \'start_end\' hook with foo!' - callbacks[1][:events].should eq [:start_begin, :run_all_begin] - callbacks[1][:listener].should eq MyCustomCallback + expect(::Guard).to receive(:add_guard).with('dummy', anything, anything, { :group => :default }) do |name, watchers, callbacks, options| + expect(callbacks.size).to eq(2) + expect(callbacks[0][:events]).to eq :start_end + expect(callbacks[0][:listener].call(Guard::Dummy, :start_end, 'foo')).to eq 'Guard::Dummy executed \'start_end\' hook with foo!' + expect(callbacks[1][:events]).to eq [:start_begin, :run_all_begin] + expect(callbacks[1][:listener]).to eq MyCustomCallback end described_class.evaluate_guardfile(:guardfile_contents => ' guard :dummy do @@ -515,78 +515,78 @@ def self.call(guard_class, event, args) context 'with valid options' do it 'sets the logger log level' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :error') - Guard::UI.options[:level].should eql :error + expect(Guard::UI.options[:level]).to eql :error end it 'sets the logger log level and convert to a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => \'error\'') - Guard::UI.options[:level].should eql :error + expect(Guard::UI.options[:level]).to eql :error end it 'sets the logger template' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :template => \':message - :severity\'') - Guard::UI.options[:template].should eql ':message - :severity' + expect(Guard::UI.options[:template]).to eql ':message - :severity' end it 'sets the logger time format' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :time_format => \'%Y\'') - Guard::UI.options[:time_format].should eql '%Y' + expect(Guard::UI.options[:time_format]).to eql '%Y' end it 'sets the logger only filter from a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :cucumber') - Guard::UI.options[:only].should eql(/cucumber/i) + expect(Guard::UI.options[:only]).to eql(/cucumber/i) end it 'sets the logger only filter from a string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => \'jasmine\'') - Guard::UI.options[:only].should eql(/jasmine/i) + expect(Guard::UI.options[:only]).to eql(/jasmine/i) end it 'sets the logger only filter from an array of symbols and string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => [:rspec, \'cucumber\']') - Guard::UI.options[:only].should eql(/rspec|cucumber/i) + expect(Guard::UI.options[:only]).to eql(/rspec|cucumber/i) end it 'sets the logger except filter from a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => :jasmine') - Guard::UI.options[:except].should eql(/jasmine/i) + expect(Guard::UI.options[:except]).to eql(/jasmine/i) end it 'sets the logger except filter from a string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => \'jasmine\'') - Guard::UI.options[:except].should eql(/jasmine/i) + expect(Guard::UI.options[:except]).to eql(/jasmine/i) end it 'sets the logger except filter from an array of symbols and string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => [:rspec, \'cucumber\', :jasmine]') - Guard::UI.options[:except].should eql(/rspec|cucumber|jasmine/i) + expect(Guard::UI.options[:except]).to eql(/rspec|cucumber|jasmine/i) end end context 'with invalid options' do context 'for the log level' do it 'shows a warning' do - Guard::UI.should_receive(:warning).with 'Invalid log level `baz` ignored. Please use either :debug, :info, :warn or :error.' + expect(Guard::UI).to receive(:warning).with 'Invalid log level `baz` ignored. Please use either :debug, :info, :warn or :error.' described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :baz') end it 'does not set the invalid value' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :baz') - Guard::UI.options[:level].should eql :info + expect(Guard::UI.options[:level]).to eql :info end end context 'when having both the :only and :except options' do it 'shows a warning' do - Guard::UI.should_receive(:warning).with 'You cannot specify the logger options :only and :except at the same time.' + expect(Guard::UI).to receive(:warning).with 'You cannot specify the logger options :only and :except at the same time.' described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :jasmine, :except => :rspec') end it 'removes the options' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :jasmine, :except => :rspec') - Guard::UI.options[:only].should be_nil - Guard::UI.options[:except].should be_nil + expect(Guard::UI.options[:only]).to be_nil + expect(Guard::UI.options[:except]).to be_nil end end @@ -602,12 +602,12 @@ def self.call(guard_class, event, args) it 'does not use the DSL scope plugin' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :plugin => :baz') - ::Guard.options[:plugin].should eql(['rspec']) + expect(::Guard.options[:plugin]).to eql(['rspec']) end it 'does not use the DSL scope plugins' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :plugins => [:foo, :bar]') - ::Guard.options[:plugin].should eql(['rspec']) + expect(::Guard.options[:plugin]).to eql(['rspec']) end end @@ -619,12 +619,12 @@ def self.call(guard_class, event, args) it 'does use the DSL scope plugin' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :plugin => :baz') - ::Guard.options[:plugin].should eql([:baz]) + expect(::Guard.options[:plugin]).to eql([:baz]) end it 'does use the DSL scope plugins' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :plugins => [:foo, :bar]') - ::Guard.options[:plugin].should eql([:foo, :bar]) + expect(::Guard.options[:plugin]).to eql([:foo, :bar]) end end @@ -636,12 +636,12 @@ def self.call(guard_class, event, args) it 'does not use the DSL scope plugin' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :group => :baz') - ::Guard.options[:group].should eql(['frontend']) + expect(::Guard.options[:group]).to eql(['frontend']) end it 'does not use the DSL scope plugins' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :groups => [:foo, :bar]') - ::Guard.options[:group].should eql(['frontend']) + expect(::Guard.options[:group]).to eql(['frontend']) end end @@ -653,12 +653,12 @@ def self.call(guard_class, event, args) it 'does use the DSL scope group' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :group => :baz') - ::Guard.options[:group].should eql([:baz]) + expect(::Guard.options[:group]).to eql([:baz]) end it 'does use the DSL scope groups' do described_class.evaluate_guardfile(:guardfile_contents => 'scope :groups => [:foo, :bar]') - ::Guard.options[:group].should eql([:foo, :bar]) + expect(::Guard.options[:group]).to eql([:foo, :bar]) end end end @@ -666,8 +666,8 @@ def self.call(guard_class, event, args) private def fake_guardfile(name, contents) - File.stub!(:exist?).with(name) { true } - File.stub!(:read).with(name) { contents } + allow(File).to receive(:exist?).with(name) { true } + allow(File).to receive(:read).with(name) { contents } end def valid_guardfile_string diff --git a/spec/guard/group_spec.rb b/spec/guard/group_spec.rb index 193980b31..f75464fda 100644 --- a/spec/guard/group_spec.rb +++ b/spec/guard/group_spec.rb @@ -4,22 +4,22 @@ describe ".initialize" do it "accepts a name as a string and provides an accessor for it (returning a symbol)" do - described_class.new('foo').name.should eq :foo + expect(described_class.new('foo').name).to eq :foo end it "accepts a name as a symbol and provides an accessor for it (returning a symbol)" do - described_class.new(:foo).name.should eq :foo + expect(described_class.new(:foo).name).to eq :foo end it "accepts options and provides an accessor for it" do - described_class.new('foo', :halt_on_fail => true).options.should == { :halt_on_fail => true } + expect(described_class.new('foo', :halt_on_fail => true).options).to eq({ :halt_on_fail => true }) end end describe '#to_s' do it "output Group properly" do group = described_class.new(:foo) - group.to_s.should eq "Foo" + expect(group.to_s).to eq "Foo" end end diff --git a/spec/guard/guard_spec.rb b/spec/guard/guard_spec.rb index 9d4e791dc..bbb1ad379 100644 --- a/spec/guard/guard_spec.rb +++ b/spec/guard/guard_spec.rb @@ -7,20 +7,20 @@ it 'assigns the defined watchers' do watchers = [ Guard::Watcher.new('*') ] guard = Guard::Guard.new(watchers) - guard.watchers.should == watchers + expect(guard.watchers).to eq(watchers) end it 'assigns the defined options' do options = { :a => 1, :b => 2 } guard = Guard::Guard.new([], options) - guard.options.should == options + expect(guard.options).to eq(options) end context 'with a group in the options' do it 'assigns the given group' do options = { :group => :test } guard = Guard::Guard.new([], options) - guard.group.should == :test + expect(guard.group).to eq(:test) end end @@ -28,32 +28,32 @@ it 'assigns a default group' do options = { } guard = Guard::Guard.new([], options) - guard.group.should == :default + expect(guard.group).to eq(:default) end end end describe '#init' do context 'when the Guard is already in the Guardfile' do - before { ::Guard::Dsl.stub(:guardfile_include?).and_return true } + before { allow(::Guard::Dsl).to receive(:guardfile_include?).and_return true } it 'shows an info message' do - ::Guard::UI.should_receive(:info).with 'Guardfile already includes myguard guard' + expect(::Guard::UI).to receive(:info).with 'Guardfile already includes myguard guard' Guard::Guard.init('myguard') end end context 'when the Guard is not in the Guardfile' do - before { ::Guard::Dsl.stub(:guardfile_include?).and_return false } + before { allow(::Guard::Dsl).to receive(:guardfile_include?).and_return false } it 'appends the template to the Guardfile' do - File.should_receive(:read).with('Guardfile').and_return 'Guardfile content' - ::Guard.should_receive(:locate_guard).with('myguard').and_return '/Users/me/projects/guard-myguard' - File.should_receive(:read).with('/Users/me/projects/guard-myguard/lib/guard/myguard/templates/Guardfile').and_return('Template content') + expect(File).to receive(:read).with('Guardfile').and_return 'Guardfile content' + expect(::Guard).to receive(:locate_guard).with('myguard').and_return '/Users/me/projects/guard-myguard' + expect(File).to receive(:read).with('/Users/me/projects/guard-myguard/lib/guard/myguard/templates/Guardfile').and_return('Template content') io = StringIO.new - File.should_receive(:open).with('Guardfile', 'wb').and_yield io + expect(File).to receive(:open).with('Guardfile', 'wb').and_yield io Guard::Guard.init('myguard') - io.string.should == "Guardfile content\n\nTemplate content\n" + expect(io.string).to eq("Guardfile content\n\nTemplate content\n") end end end @@ -63,7 +63,7 @@ it "output the short plugin name" do guard = Guard::Dummy.new - guard.to_s.should eq "Dummy" + expect(guard.to_s).to eq "Dummy" end end diff --git a/spec/guard/guardfile_spec.rb b/spec/guard/guardfile_spec.rb index 231de7892..7ae568f22 100644 --- a/spec/guard/guardfile_spec.rb +++ b/spec/guard/guardfile_spec.rb @@ -3,43 +3,43 @@ describe Guard::Guardfile do it "has a valid Guardfile template" do - File.exists?(Guard::GUARDFILE_TEMPLATE).should be_true + expect(File.exists?(Guard::GUARDFILE_TEMPLATE)).to be_truthy end describe ".create_guardfile" do - before { Dir.stub(:pwd).and_return "/home/user" } + before { allow(Dir).to receive(:pwd).and_return "/home/user" } context "with an existing Guardfile" do - before { File.should_receive(:exist?).and_return true } + before { expect(File).to receive(:exist?).and_return true } it "does not copy the Guardfile template or notify the user" do - ::Guard::UI.should_not_receive(:info) - FileUtils.should_not_receive(:cp) + expect(::Guard::UI).not_to receive(:info) + expect(FileUtils).not_to receive(:cp) described_class.create_guardfile end it "does not display any kind of error or abort" do - ::Guard::UI.should_not_receive(:error) - described_class.should_not_receive(:abort) + expect(::Guard::UI).not_to receive(:error) + expect(described_class).not_to receive(:abort) described_class.create_guardfile end context "with the :abort_on_existence option set to true" do it "displays an error message and aborts the process" do - ::Guard::UI.should_receive(:error).with("Guardfile already exists at /home/user/Guardfile") - described_class.should_receive(:abort) + expect(::Guard::UI).to receive(:error).with("Guardfile already exists at /home/user/Guardfile") + expect(described_class).to receive(:abort) described_class.create_guardfile(:abort_on_existence => true) end end end context "without an existing Guardfile" do - before { File.should_receive(:exist?).and_return false } + before { expect(File).to receive(:exist?).and_return false } it "copies the Guardfile template and notifies the user" do - ::Guard::UI.should_receive(:info) - FileUtils.should_receive(:cp) + expect(::Guard::UI).to receive(:info) + expect(FileUtils).to receive(:cp) described_class.create_guardfile end @@ -51,14 +51,14 @@ context "that has duplicate definitions" do it "should return true" do io = StringIO.new("guard 'rspec' do\nend\nguard 'rspec' do\nend\n") - Guard::Guardfile.duplicate_definitions?('rspec', io.string).should == true + expect(Guard::Guardfile.duplicate_definitions?('rspec', io.string)).to eq(true) end end context "that doesn't have duplicate definitions" do it "should return false" do io = StringIO.new("guard 'rspec' do\nend\n") - Guard::Guardfile.duplicate_definitions?('rspec', io.string).should == false + expect(Guard::Guardfile.duplicate_definitions?('rspec', io.string)).to eq(false) end end end @@ -68,10 +68,10 @@ context 'with an installed Guard implementation' do let(:foo_guard) { double('Guard::Foo').as_null_object } - before { ::Guard.should_receive(:get_guard_class).and_return(foo_guard) } + before { expect(::Guard).to receive(:get_guard_class).and_return(foo_guard) } it "initializes the Guard" do - foo_guard.should_receive(:init) + expect(foo_guard).to receive(:init) described_class.initialize_template('foo') end end @@ -79,26 +79,26 @@ context "with a user defined template" do let(:template) { File.join(Guard::HOME_TEMPLATES, '/bar') } - before { File.should_receive(:exist?).with(template).and_return true } + before { expect(File).to receive(:exist?).with(template).and_return true } it "copies the Guardfile template and initializes the Guard" do - File.should_receive(:read).with('Guardfile').and_return 'Guardfile content' - File.should_receive(:read).with(template).and_return 'Template content' + expect(File).to receive(:read).with('Guardfile').and_return 'Guardfile content' + expect(File).to receive(:read).with(template).and_return 'Template content' io = StringIO.new - File.should_receive(:open).with('Guardfile', 'wb').and_yield io + expect(File).to receive(:open).with('Guardfile', 'wb').and_yield io described_class.initialize_template('bar') - io.string.should == "Guardfile content\n\nTemplate content\n" + expect(io.string).to eq("Guardfile content\n\nTemplate content\n") end end context "when the passed guard can't be found" do before do - ::Guard.should_receive(:get_guard_class).and_return nil - File.should_receive(:exist?).and_return false + expect(::Guard).to receive(:get_guard_class).and_return nil + expect(File).to receive(:exist?).and_return false end it "notifies the user about the problem" do - ::Guard::UI.should_receive(:error).with( + expect(::Guard::UI).to receive(:error).with( "Could not load 'guard/foo' or '~/.guard/templates/foo' or find class Guard::Foo" ) described_class.initialize_template('foo') @@ -109,11 +109,11 @@ describe ".initialize_all_templates" do let(:guards) { ['rspec', 'spork', 'phpunit'] } - before { ::Guard.should_receive(:guard_gem_names).and_return(guards) } + before { expect(::Guard).to receive(:guard_gem_names).and_return(guards) } it "calls Guard.initialize_template on all installed guards" do guards.each do |g| - described_class.should_receive(:initialize_template).with(g) + expect(described_class).to receive(:initialize_template).with(g) end described_class.initialize_all_templates diff --git a/spec/guard/hook_spec.rb b/spec/guard/hook_spec.rb index 560f6ed6f..b84087637 100644 --- a/spec/guard/hook_spec.rb +++ b/spec/guard/hook_spec.rb @@ -31,33 +31,33 @@ def stop describe '.add_callback' do it 'can add a single callback' do - described_class.has_callback?(listener, ::Guard::Dummy, :start_begin).should be_true + expect(described_class.has_callback?(listener, ::Guard::Dummy, :start_begin)).to be_truthy end it 'can add multiple callbacks' do described_class.add_callback(listener, ::Guard::Dummy, [:event1, :event2]) - described_class.has_callback?(listener, ::Guard::Dummy, :event1).should be_true - described_class.has_callback?(listener, ::Guard::Dummy, :event2).should be_true + expect(described_class.has_callback?(listener, ::Guard::Dummy, :event1)).to be_truthy + expect(described_class.has_callback?(listener, ::Guard::Dummy, :event2)).to be_truthy end end describe '.notify' do it "sends :call to the given Guard class's callbacks" do - listener.should_receive(:call).with(::Guard::Dummy, :start_begin, 'args') + expect(listener).to receive(:call).with(::Guard::Dummy, :start_begin, 'args') described_class.notify(::Guard::Dummy, :start_begin, 'args') end it 'runs only the given callbacks' do listener2 = double('listener2') described_class.add_callback(listener2, ::Guard::Dummy, :start_end) - listener2.should_not_receive(:call).with(::Guard::Dummy, :start_end) + expect(listener2).not_to receive(:call).with(::Guard::Dummy, :start_end) described_class.notify(::Guard::Dummy, :start_begin) end it 'runs callbacks only for the guard given' do guard2_class = double('Guard::Dummy2').class described_class.add_callback(listener, guard2_class, :start_begin) - listener.should_not_receive(:call).with(guard2_class, :start_begin) + expect(listener).not_to receive(:call).with(guard2_class, :start_begin) described_class.notify(::Guard::Dummy, :start_begin) end end @@ -66,19 +66,19 @@ def stop let(:plugin) { ::Guard::Dummy.new } it 'notifies the hooks' do - Guard::Hook.should_receive(:notify).with(::Guard::Dummy, :run_all_begin) - Guard::Hook.should_receive(:notify).with(::Guard::Dummy, :run_all_end) + expect(Guard::Hook).to receive(:notify).with(::Guard::Dummy, :run_all_begin) + expect(Guard::Hook).to receive(:notify).with(::Guard::Dummy, :run_all_end) plugin.run_all end it 'passes the hooks name' do - Guard::Hook.should_receive(:notify).with(::Guard::Dummy, :my_hook) + expect(Guard::Hook).to receive(:notify).with(::Guard::Dummy, :my_hook) plugin.start end it 'accepts extra arguments' do - Guard::Hook.should_receive(:notify).with(::Guard::Dummy, :stop_begin, 'args') - Guard::Hook.should_receive(:notify).with(::Guard::Dummy, :special_sauce, 'first_arg', 'second_arg') + expect(Guard::Hook).to receive(:notify).with(::Guard::Dummy, :stop_begin, 'args') + expect(Guard::Hook).to receive(:notify).with(::Guard::Dummy, :special_sauce, 'first_arg', 'second_arg') plugin.stop end end diff --git a/spec/guard/interactor_spec.rb b/spec/guard/interactor_spec.rb index 25e1bea23..acb91d93a 100644 --- a/spec/guard/interactor_spec.rb +++ b/spec/guard/interactor_spec.rb @@ -17,36 +17,36 @@ it 'returns a group scope' do scopes, _ = Guard::Interactor.convert_scope %w(backend) - scopes.should eql({ :groups => [@backend_group], :plugins => [] }) + expect(scopes).to eql({ :groups => [@backend_group], :plugins => [] }) scopes, _ = Guard::Interactor.convert_scope %w(frontend) - scopes.should eql({ :groups => [@frontend_group], :plugins => [] }) + expect(scopes).to eql({ :groups => [@frontend_group], :plugins => [] }) end it 'returns a plugin scope' do scopes, _ = Guard::Interactor.convert_scope %w(foo) - scopes.should eql({ :plugins => [@foo_guard], :groups => [] }) + expect(scopes).to eql({ :plugins => [@foo_guard], :groups => [] }) scopes, _ = Guard::Interactor.convert_scope %w(bar) - scopes.should eql({ :plugins => [@bar_guard], :groups => [] }) + expect(scopes).to eql({ :plugins => [@bar_guard], :groups => [] }) end it 'returns multiple group scopes' do scopes, _ = Guard::Interactor.convert_scope %w(backend frontend) - scopes.should eql({ :groups => [@backend_group, @frontend_group], :plugins => [] }) + expect(scopes).to eql({ :groups => [@backend_group, @frontend_group], :plugins => [] }) end it 'returns multiple plugin scopes' do scopes, _ = Guard::Interactor.convert_scope %w(foo bar) - scopes.should eql({ :plugins => [@foo_guard, @bar_guard], :groups => [] }) + expect(scopes).to eql({ :plugins => [@foo_guard, @bar_guard], :groups => [] }) end it 'returns a plugin and group scope' do scopes, _ = Guard::Interactor.convert_scope %w(foo backend) - scopes.should eql({ :plugins => [@foo_guard], :groups => [@backend_group] }) + expect(scopes).to eql({ :plugins => [@foo_guard], :groups => [@backend_group] }) end it 'returns the unkown scopes' do _, unkown = Guard::Interactor.convert_scope %w(unkown scope) - unkown.should eql %w(unkown scope) + expect(unkown).to eql %w(unkown scope) end end diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 22a71a227..a2ce03761 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -9,17 +9,17 @@ end it 'shows the used notifications' do - Guard::UI.should_receive(:info).with 'Guard uses GNTP to send notifications.' + expect(Guard::UI).to receive(:info).with 'Guard uses GNTP to send notifications.' Guard::Notifier.turn_on end it 'enables the notifications' do Guard::Notifier.turn_on - Guard::Notifier.should be_enabled + expect(Guard::Notifier).to be_enabled end it 'turns on the defined notification module' do - ::Guard::Notifier::GNTP.should_receive(:turn_on) + expect(::Guard::Notifier::GNTP).to receive(:turn_on) Guard::Notifier.turn_on end end @@ -32,74 +32,74 @@ context 'when notifications are globally enabled' do before do ::Guard.options = { } - ::Guard.options.should_receive(:[]).with(:notify).and_return true + expect(::Guard.options).to receive(:[]).with(:notify).and_return true end it 'tries to add each available notification silently' do - Guard::Notifier.should_receive(:add_notification).with(:gntp, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl_notify, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:terminal_notifier, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:libnotify, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:notifysend, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:notifu, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:terminal_title, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:file, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:gntp, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:growl, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:growl_notify, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:terminal_notifier, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:libnotify, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:notifysend, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:notifu, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:emacs, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:terminal_title, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:tmux, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:file, { }, true).and_return false Guard::Notifier.turn_on end it 'adds only the first notification per group' do - Guard::Notifier.should_receive(:add_notification).with(:gntp, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl, { }, true).and_return false - Guard::Notifier.should_receive(:add_notification).with(:growl_notify, { }, true).and_return true - Guard::Notifier.should_not_receive(:add_notification).with(:terminal_notifier, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:libnotify, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:notifysend, { }, true) - Guard::Notifier.should_not_receive(:add_notification).with(:notifu, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:terminal_title, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true) - Guard::Notifier.should_receive(:add_notification).with(:file, { }, true) + expect(Guard::Notifier).to receive(:add_notification).with(:gntp, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:growl, { }, true).and_return false + expect(Guard::Notifier).to receive(:add_notification).with(:growl_notify, { }, true).and_return true + expect(Guard::Notifier).not_to receive(:add_notification).with(:terminal_notifier, { }, true) + expect(Guard::Notifier).not_to receive(:add_notification).with(:libnotify, { }, true) + expect(Guard::Notifier).not_to receive(:add_notification).with(:notifysend, { }, true) + expect(Guard::Notifier).not_to receive(:add_notification).with(:notifu, { }, true) + expect(Guard::Notifier).to receive(:add_notification).with(:emacs, { }, true) + expect(Guard::Notifier).to receive(:add_notification).with(:terminal_title, { }, true) + expect(Guard::Notifier).to receive(:add_notification).with(:tmux, { }, true) + expect(Guard::Notifier).to receive(:add_notification).with(:file, { }, true) Guard::Notifier.turn_on end it 'does enable the notifications when a library is available' do - Guard::Notifier.should_receive(:add_notification) do + allow(Guard::Notifier).to receive(:add_notification) { Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] true - end.any_number_of_times + } Guard::Notifier.turn_on - Guard::Notifier.should be_enabled + expect(Guard::Notifier).to be_enabled end it 'does turn on the notification module for libraries that are available' do - ::Guard::Notifier::GNTP.should_receive(:turn_on) - Guard::Notifier.should_receive(:add_notification) do + expect(::Guard::Notifier::GNTP).to receive(:turn_on) + allow(Guard::Notifier).to receive(:add_notification) { Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] true - end.any_number_of_times + } Guard::Notifier.turn_on end it 'does not enable the notifications when no library is available' do - Guard::Notifier.should_receive(:add_notification).any_number_of_times.and_return false + allow(Guard::Notifier).to receive(:add_notification).and_return false Guard::Notifier.turn_on - Guard::Notifier.should_not be_enabled + expect(Guard::Notifier).not_to be_enabled end end context 'when notifications are globally disabled' do before do ::Guard.options = { } - ::Guard.options.should_receive(:[]).with(:notify).and_return false + expect(::Guard.options).to receive(:[]).with(:notify).and_return false end it 'does not try to add each available notification silently' do - Guard::Notifier.should_not_receive(:auto_detect_notification) + expect(Guard::Notifier).not_to receive(:auto_detect_notification) Guard::Notifier.turn_on - Guard::Notifier.should_not be_enabled + expect(Guard::Notifier).not_to be_enabled end end end @@ -110,7 +110,7 @@ it 'disables the notifications' do Guard::Notifier.turn_off - ENV['GUARD_NOTIFY'].should == 'false' + expect(ENV['GUARD_NOTIFY']).to eq('false') end context 'when turned on with available notifications' do @@ -119,24 +119,24 @@ end it 'turns off each notification' do - ::Guard::Notifier::GNTP.should_receive(:turn_off) + expect(::Guard::Notifier::GNTP).to receive(:turn_off) Guard::Notifier.turn_off end end end describe 'toggle_notification' do - before { ::Guard::UI.stub(:info) } + before { allow(::Guard::UI).to receive(:info) } it 'disables the notifications when enabled' do ENV['GUARD_NOTIFY'] = 'true' - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) subject.toggle end it 'enables the notifications when disabled' do ENV['GUARD_NOTIFY'] = 'false' - ::Guard::Notifier.should_receive(:turn_on) + expect(::Guard::Notifier).to receive(:turn_on) subject.toggle end end @@ -145,13 +145,13 @@ context 'when enabled' do before { ENV['GUARD_NOTIFY'] = 'true' } - it { should be_enabled } + it { is_expected.to be_enabled } end context 'when disabled' do before { ENV['GUARD_NOTIFY'] = 'false' } - it { should_not be_enabled } + it { is_expected.not_to be_enabled } end end @@ -163,33 +163,33 @@ context 'for an unknown notification library' do it 'does not add the library' do Guard::Notifier.add_notification(:unknown) - Guard::Notifier.notifications.should be_empty + expect(Guard::Notifier.notifications).to be_empty end end context 'for an notification library with the name :off' do it 'disables the notifier' do ENV['GUARD_NOTIFY'] = 'true' - Guard::Notifier.should be_enabled + expect(Guard::Notifier).to be_enabled Guard::Notifier.add_notification(:off) - Guard::Notifier.should_not be_enabled + expect(Guard::Notifier).not_to be_enabled end end context 'for a supported notification library' do context 'that is available' do it 'adds the notifier to the notifications' do - Guard::Notifier::GNTP.should_receive(:available?).and_return true + expect(Guard::Notifier::GNTP).to receive(:available?).and_return true Guard::Notifier.add_notification(:gntp, { :param => 1 }) - Guard::Notifier.notifications.should include({ :name => :gntp, :options => { :param => 1 } }) + expect(Guard::Notifier.notifications).to include({ :name => :gntp, :options => { :param => 1 } }) end end context 'that is not available' do it 'does not add the notifier to the notifications' do - Guard::Notifier::GNTP.should_receive(:available?).and_return false + expect(Guard::Notifier::GNTP).to receive(:available?).and_return false Guard::Notifier.add_notification(:gntp, { :param => 1 }) - Guard::Notifier.notifications.should_not include({ :name => :gntp, :options => { :param => 1 } }) + expect(Guard::Notifier.notifications).not_to include({ :name => :gntp, :options => { :param => 1 } }) end end end @@ -199,48 +199,48 @@ context 'when notifications are enabled' do before do Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }] - Guard::Notifier.stub(:enabled?).and_return true + allow(Guard::Notifier).to receive(:enabled?).and_return true end it 'uses the :success image when no image is defined' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Hi', 'Hi to everyone', /success.png/, { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('success', 'Hi', 'Hi to everyone', /success.png/, { }) ::Guard::Notifier.notify('Hi to everyone', :title => 'Hi') end it 'uses "Guard" as title when no title is defined' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) ::Guard::Notifier.notify('Hi to everyone') end it 'sets the "failed" type for a :failed image' do - Guard::Notifier::GNTP.should_receive(:notify).with('failed', 'Guard', 'Hi to everyone', /failed.png/, { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('failed', 'Guard', 'Hi to everyone', /failed.png/, { }) ::Guard::Notifier.notify('Hi to everyone', :image => :failed) end it 'sets the "pending" type for a :pending image' do - Guard::Notifier::GNTP.should_receive(:notify).with('pending', 'Guard', 'Hi to everyone', /pending.png/, { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('pending', 'Guard', 'Hi to everyone', /pending.png/, { }) ::Guard::Notifier.notify('Hi to everyone', :image => :pending) end it 'sets the "success" type for a :success image' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { }) ::Guard::Notifier.notify('Hi to everyone', :image => :success) end it 'sets the "notify" type for a custom image' do - Guard::Notifier::GNTP.should_receive(:notify).with('notify', 'Guard', 'Hi to everyone', '/path/to/image.png', { }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('notify', 'Guard', 'Hi to everyone', '/path/to/image.png', { }) ::Guard::Notifier.notify('Hi to everyone', :image => '/path/to/image.png') end it 'passes custom options to the notifier' do - Guard::Notifier::GNTP.should_receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { :param => 'test' }) + expect(Guard::Notifier::GNTP).to receive(:notify).with('success', 'Guard', 'Hi to everyone', /success.png/, { :param => 'test' }) ::Guard::Notifier.notify('Hi to everyone', :param => 'test') end it 'sends the notification to multiple notifier' do Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }, { :name => :growl, :options => { } }] - Guard::Notifier::GNTP.should_receive(:notify) - Guard::Notifier::Growl.should_receive(:notify) + expect(Guard::Notifier::GNTP).to receive(:notify) + expect(Guard::Notifier::Growl).to receive(:notify) ::Guard::Notifier.notify('Hi to everyone') end end @@ -248,12 +248,12 @@ context 'when notifications are disabled' do before do Guard::Notifier.notifications = [{ :name => :gntp, :options => { } }, { :name => :growl, :options => { } }] - Guard::Notifier.stub(:enabled?).and_return false + allow(Guard::Notifier).to receive(:enabled?).and_return false end it 'does not send any notifications to a notifier' do - Guard::Notifier::GNTP.should_not_receive(:notify) - Guard::Notifier::Growl.should_not_receive(:notify) + expect(Guard::Notifier::GNTP).not_to receive(:notify) + expect(Guard::Notifier::Growl).not_to receive(:notify) ::Guard::Notifier.notify('Hi to everyone') end end diff --git a/spec/guard/notifiers/emacs_spec.rb b/spec/guard/notifiers/emacs_spec.rb index b96126257..854ab339f 100644 --- a/spec/guard/notifiers/emacs_spec.rb +++ b/spec/guard/notifiers/emacs_spec.rb @@ -5,9 +5,9 @@ describe '.notify' do context 'when no color options are specified' do it 'should set modeline color to the default color using emacsclient' do - subject.should_receive(:run_cmd) do |command| - command.should include("emacsclient") - command.should include(%{(set-face-attribute 'mode-line nil :background "ForestGreen" :foreground "White")}) + expect(subject).to receive(:run_cmd) do |command| + expect(command).to include("emacsclient") + expect(command).to include(%{(set-face-attribute 'mode-line nil :background "ForestGreen" :foreground "White")}) end subject.notify('success', 'any title', 'any message', 'any image', { }) @@ -18,9 +18,9 @@ let(:options) { {:success => 'Orange'} } it 'should set modeline color to the specified color using emacsclient' do - subject.should_receive(:run_cmd) do |command| - command.should include("emacsclient") - command.should include(%{(set-face-attribute 'mode-line nil :background "Orange" :foreground "White")}) + expect(subject).to receive(:run_cmd) do |command| + expect(command).to include("emacsclient") + expect(command).to include(%{(set-face-attribute 'mode-line nil :background "Orange" :foreground "White")}) end subject.notify('success', 'any title', 'any message', 'any image', options) @@ -31,9 +31,9 @@ let(:options) { {:pending => 'Yellow'} } it 'should set modeline color to the specified color using emacsclient' do - subject.should_receive(:run_cmd) do |command| - command.should include("emacsclient") - command.should include(%{(set-face-attribute 'mode-line nil :background "Yellow" :foreground "White")}) + expect(subject).to receive(:run_cmd) do |command| + expect(command).to include("emacsclient") + expect(command).to include(%{(set-face-attribute 'mode-line nil :background "Yellow" :foreground "White")}) end subject.notify('pending', 'any title', 'any message', 'any image', options) diff --git a/spec/guard/notifiers/file_notifier_spec.rb b/spec/guard/notifiers/file_notifier_spec.rb index 87ea421dd..49dc60082 100644 --- a/spec/guard/notifiers/file_notifier_spec.rb +++ b/spec/guard/notifiers/file_notifier_spec.rb @@ -5,23 +5,23 @@ describe '.available?' do it 'is true if there is a file in options' do - subject.should be_available(true, :path => '.guard_result') + expect(subject).to be_available(true, :path => '.guard_result') end it 'is false if there is no path in options' do - subject.should_not be_available + expect(subject).not_to be_available end end describe '.notify' do it 'writes to a file on success' do - subject.should_receive(:write).with('tmp/guard_result', "success\nany title\nany message\n") + expect(subject).to receive(:write).with('tmp/guard_result', "success\nany title\nany message\n") subject.notify('success', 'any title', 'any message', 'any image', { :path => 'tmp/guard_result' }) end it 'also writes to a file on failure' do - subject.should_receive(:write).with('tmp/guard_result', "failed\nany title\nany message\n") + expect(subject).to receive(:write).with('tmp/guard_result', "failed\nany title\nany message\n") subject.notify('failed', 'any title', 'any message', 'any image', { :path => 'tmp/guard_result' }) end @@ -29,8 +29,8 @@ # We don't have a way to return false in .available? when no path is # specified. So, we just don't do anything in .notify if there's no path. it 'does not write to a file if no path is specified' do - subject.should_not_receive(:write) - ::Guard::UI.should_receive(:error).with ":file notifier requires a :path option" + expect(subject).not_to receive(:write) + expect(::Guard::UI).to receive(:error).with ":file notifier requires a :path option" subject.notify('success', 'any title', 'any message', 'any image', { }) end diff --git a/spec/guard/notifiers/gntp_spec.rb b/spec/guard/notifiers/gntp_spec.rb index 07a0b58b0..75db9c0d5 100644 --- a/spec/guard/notifiers/gntp_spec.rb +++ b/spec/guard/notifiers/gntp_spec.rb @@ -9,56 +9,56 @@ def self.notify(options) end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'GNTP', fake_gntp end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'os2' + expect(::Guard::UI).to receive(:error).with 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'os2' subject.available? end it 'shows an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_receive(:error).with "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('ruby_gntp').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('ruby_gntp').and_raise LoadError subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'os2' + expect(::Guard::UI).not_to receive(:error).with 'The :gntp notifier runs only on Mac OS X, Linux, FreeBSD, OpenBSD, Solaris and Windows.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'os2' subject.available?(true) end it 'does not show an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_not_receive(:error).with "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('ruby_gntp').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with "Please add \"gem 'ruby_gntp'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('ruby_gntp').and_raise LoadError subject.available?(true) end end end describe '.nofify' do - let(:gntp) { mock('GNTP').as_null_object } + let(:gntp) { double('GNTP').as_null_object } before do - ::GNTP.stub(:new).and_return gntp + allow(::GNTP).to receive(:new).and_return gntp end it 'requires the library again' do - subject.should_receive(:require).with('ruby_gntp').and_return true + expect(subject).to receive(:require).with('ruby_gntp').and_return true subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end it 'opens GNTP as Guard application' do - ::GNTP.should_receive(:new).with('Guard', '127.0.0.1', '', 23053) + expect(::GNTP).to receive(:new).with('Guard', '127.0.0.1', '', 23053) subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end @@ -66,7 +66,7 @@ def self.notify(options) end before { Guard::Notifier::GNTP.instance_variable_set :@registered, false } it 'registers the Guard notification types' do - gntp.should_receive(:register) + expect(gntp).to receive(:register) subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end end @@ -75,14 +75,14 @@ def self.notify(options) end before { Guard::Notifier::GNTP.instance_variable_set :@registered, true } it 'registers the Guard notification types' do - gntp.should_not_receive(:register) + expect(gntp).not_to receive(:register) subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end end context 'without additional options' do it 'shows the notification with the default options' do - gntp.should_receive(:notify).with({ + expect(gntp).to receive(:notify).with({ :sticky => false, :name => 'success', :title => 'Welcome', @@ -95,7 +95,7 @@ def self.notify(options) end context 'with additional options' do it 'can override the default options' do - gntp.should_receive(:notify).with({ + expect(gntp).to receive(:notify).with({ :sticky => true, :name => 'pending', :title => 'Waiting', @@ -108,7 +108,7 @@ def self.notify(options) end end it 'cannot override the core options' do - gntp.should_receive(:notify).with({ + expect(gntp).to receive(:notify).with({ :sticky => false, :name => 'failed', :title => 'Failed', diff --git a/spec/guard/notifiers/growl_notify_spec.rb b/spec/guard/notifiers/growl_notify_spec.rb index 6c1a46eff..9f0eac09d 100644 --- a/spec/guard/notifiers/growl_notify_spec.rb +++ b/spec/guard/notifiers/growl_notify_spec.rb @@ -10,60 +10,60 @@ def self.send_notification(options) end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'GrowlNotify', fake_growl_notify end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :growl_notify notifier runs only on Mac OS X.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'mswin' + expect(::Guard::UI).to receive(:error).with 'The :growl_notify notifier runs only on Mac OS X.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'mswin' subject.available? end it 'shows an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_receive(:error).with "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('growl_notify').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('growl_notify').and_raise LoadError subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :growl_notify notifier runs only on Mac OS X.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'mswin' + expect(::Guard::UI).not_to receive(:error).with 'The :growl_notify notifier runs only on Mac OS X.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'mswin' subject.available?(true) end it 'does not show an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_not_receive(:error).with "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('growl_notify').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with "Please add \"gem 'growl_notify'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('growl_notify').and_raise LoadError subject.available?(true) end end context 'when the application name is not Guard' do - let(:config) { mock('config') } + let(:config) { double('config') } it 'does configure GrowlNotify' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::GrowlNotify.should_receive(:application_name).and_return nil - ::GrowlNotify.should_receive(:config).and_yield config - config.should_receive(:notifications=).with ['success', 'pending', 'failed', 'notify'] - config.should_receive(:default_notifications=).with 'notify' - config.should_receive(:application_name=).with 'Guard' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::GrowlNotify).to receive(:application_name).and_return nil + expect(::GrowlNotify).to receive(:config).and_yield config + expect(config).to receive(:notifications=).with ['success', 'pending', 'failed', 'notify'] + expect(config).to receive(:default_notifications=).with 'notify' + expect(config).to receive(:application_name=).with 'Guard' subject.available? end end context 'when the application name is Guard' do it 'does not configure GrowlNotify again' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::GrowlNotify.should_receive(:application_name).and_return 'Guard' - ::GrowlNotify.should_not_receive(:config) + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::GrowlNotify).to receive(:application_name).and_return 'Guard' + expect(::GrowlNotify).not_to receive(:config) subject.available? end end @@ -72,13 +72,13 @@ def self.send_notification(options) end describe '.nofify' do it 'requires the library again' do - subject.should_receive(:require).with('growl_notify').and_return true + expect(subject).to receive(:require).with('growl_notify').and_return true subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end context 'without additional options' do it 'shows the notification with the default options' do - ::GrowlNotify.should_receive(:send_notification).with({ + expect(::GrowlNotify).to receive(:send_notification).with({ :sticky => false, :priority => 0, :application_name => 'Guard', @@ -93,7 +93,7 @@ def self.send_notification(options) end context 'with additional options' do it 'can override the default options' do - ::GrowlNotify.should_receive(:send_notification).with({ + expect(::GrowlNotify).to receive(:send_notification).with({ :sticky => true, :priority => -2, :application_name => 'Guard', @@ -109,7 +109,7 @@ def self.send_notification(options) end end it 'cannot override the core options' do - ::GrowlNotify.should_receive(:send_notification).with({ + expect(::GrowlNotify).to receive(:send_notification).with({ :sticky => false, :priority => 0, :application_name => 'Guard', diff --git a/spec/guard/notifiers/growl_spec.rb b/spec/guard/notifiers/growl_spec.rb index 3cacdf839..a1a24a34a 100644 --- a/spec/guard/notifiers/growl_spec.rb +++ b/spec/guard/notifiers/growl_spec.rb @@ -10,51 +10,51 @@ def self.installed?; end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'Growl', fake_growl end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :growl notifier runs only on Mac OS X.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'linux' + expect(::Guard::UI).to receive(:error).with 'The :growl notifier runs only on Mac OS X.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'linux' subject.available? end it 'shows an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_receive(:error).with "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('growl').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('growl').and_raise LoadError subject.available? end it 'shows an error message when the growlnotify executable cannot be found' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_receive(:error).with "Please install the 'growlnotify' executable." - ::Growl.should_receive(:installed?).and_return false + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with "Please install the 'growlnotify' executable." + expect(::Growl).to receive(:installed?).and_return false subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :growl notifier runs only on Mac OS X.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'linux' + expect(::Guard::UI).not_to receive(:error).with 'The :growl notifier runs only on Mac OS X.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'linux' subject.available?(true) end it 'does not show an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_not_receive(:error).with "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('growl').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with "Please add \"gem 'growl'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('growl').and_raise LoadError subject.available?(true) end it 'does not show an error message when the growlnotify executable cannot be found' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' - ::Guard::UI.should_not_receive(:error).with "Please install the 'growlnotify' library." - ::Growl.should_receive(:installed?).and_return false + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with "Please install the 'growlnotify' library." + expect(::Growl).to receive(:installed?).and_return false subject.available?(true) end end @@ -62,13 +62,13 @@ def self.installed?; end describe '.nofify' do it 'requires the library again' do - subject.should_receive(:require).with('growl').and_return true + expect(subject).to receive(:require).with('growl').and_return true subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end context 'without additional options' do it 'shows the notification with the default options' do - ::Growl.should_receive(:notify).with('Welcome to Guard', { + expect(::Growl).to receive(:notify).with('Welcome to Guard', { :sticky => false, :priority => 0, :name => 'Guard', @@ -81,7 +81,7 @@ def self.installed?; end context 'with additional options' do it 'can override the default options' do - ::Growl.should_receive(:notify).with('Waiting for something', { + expect(::Growl).to receive(:notify).with('Waiting for something', { :sticky => true, :priority => 2, :name => 'Guard', @@ -95,7 +95,7 @@ def self.installed?; end end it 'cannot override the core options' do - ::Growl.should_receive(:notify).with('Something failed', { + expect(::Growl).to receive(:notify).with('Something failed', { :sticky => false, :priority => 0, :name => 'Guard', diff --git a/spec/guard/notifiers/libnotify_spec.rb b/spec/guard/notifiers/libnotify_spec.rb index 6264682f4..d33d6e1b0 100644 --- a/spec/guard/notifiers/libnotify_spec.rb +++ b/spec/guard/notifiers/libnotify_spec.rb @@ -9,37 +9,37 @@ def self.show(options) end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'Libnotify', fake_libnotify end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' subject.available? end it 'shows an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'linux' - ::Guard::UI.should_receive(:error).with "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('libnotify').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'linux' + expect(::Guard::UI).to receive(:error).with "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('libnotify').and_raise LoadError subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' subject.available?(true) end it 'does not show an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'linux' - ::Guard::UI.should_not_receive(:error).with "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('libnotify').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'linux' + expect(::Guard::UI).not_to receive(:error).with "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('libnotify').and_raise LoadError subject.available?(true) end end @@ -47,13 +47,13 @@ def self.show(options) end describe '.notify' do it 'requires the library again' do - subject.should_receive(:require).with('libnotify').and_return true + expect(subject).to receive(:require).with('libnotify').and_return true subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end context 'without additional options' do it 'shows the notification with the default options' do - ::Libnotify.should_receive(:show).with({ + expect(::Libnotify).to receive(:show).with({ :transient => false, :append => true, :timeout => 3, @@ -68,7 +68,7 @@ def self.show(options) end context 'with additional options' do it 'can override the default options' do - ::Libnotify.should_receive(:show).with({ + expect(::Libnotify).to receive(:show).with({ :transient => true, :append => false, :timeout => 5, @@ -86,7 +86,7 @@ def self.show(options) end end it 'cannot override the core options' do - ::Libnotify.should_receive(:show).with({ + expect(::Libnotify).to receive(:show).with({ :transient => false, :append => true, :timeout => 3, diff --git a/spec/guard/notifiers/notifysend_spec.rb b/spec/guard/notifiers/notifysend_spec.rb index 7d1591887..6d8483f56 100644 --- a/spec/guard/notifiers/notifysend_spec.rb +++ b/spec/guard/notifiers/notifysend_spec.rb @@ -15,16 +15,16 @@ def self.show(options) end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).to receive(:error).with 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'darwin' + expect(::Guard::UI).not_to receive(:error).with 'The :notifysend notifier runs only on Linux, FreeBSD, OpenBSD and Solaris with the libnotify-bin package installed.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'darwin' subject.available?(true) end end @@ -33,12 +33,12 @@ def self.show(options) end describe '.notify' do context 'without additional options' do it 'shows the notification with the default options' do - subject.should_receive(:system) do |command, *arguments| - command.should eql 'notify-send' - arguments.should include '-i', '/tmp/welcome.png' - arguments.should include '-u', 'low' - arguments.should include '-t', '3000' - arguments.should include '-h', 'int:transient:1' + expect(subject).to receive(:system) do |command, *arguments| + expect(command).to eql 'notify-send' + expect(arguments).to include '-i', '/tmp/welcome.png' + expect(arguments).to include '-u', 'low' + expect(arguments).to include '-t', '3000' + expect(arguments).to include '-h', 'int:transient:1' end subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end @@ -46,11 +46,11 @@ def self.show(options) end context 'with additional options' do it 'can override the default options' do - subject.should_receive(:system) do |command, *arguments| - command.should eql 'notify-send' - arguments.should include '-i', '/tmp/wait.png' - arguments.should include '-u', 'critical' - arguments.should include '-t', '5' + expect(subject).to receive(:system) do |command, *arguments| + expect(command).to eql 'notify-send' + expect(arguments).to include '-i', '/tmp/wait.png' + expect(arguments).to include '-u', 'critical' + expect(arguments).to include '-t', '5' end subject.notify('pending', 'Waiting', 'Waiting for something', '/tmp/wait.png', { :t => 5, diff --git a/spec/guard/notifiers/rb_notifu_spec.rb b/spec/guard/notifiers/rb_notifu_spec.rb index dc7a6a9a0..1412dfa00 100644 --- a/spec/guard/notifiers/rb_notifu_spec.rb +++ b/spec/guard/notifiers/rb_notifu_spec.rb @@ -9,37 +9,37 @@ def self.show(options) end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'Notifu', fake_notifu end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :notifu notifier runs only on Windows.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'os2' + expect(::Guard::UI).to receive(:error).with 'The :notifu notifier runs only on Windows.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'os2' subject.available? end it 'shows an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'mswin' - ::Guard::UI.should_receive(:error).with "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('rb-notifu').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'mswin' + expect(::Guard::UI).to receive(:error).with "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('rb-notifu').and_raise LoadError subject.available? end end context 'with the silent option' do it 'does not show an error message when not available on the host OS' do - ::Guard::UI.should_not_receive(:error).with 'The :notifu notifier runs only on Windows.' - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'os2' + expect(::Guard::UI).not_to receive(:error).with 'The :notifu notifier runs only on Windows.' + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'os2' subject.available?(true) end it 'does not show an error message when the gem cannot be loaded' do - RbConfig::CONFIG.should_receive(:[]).with('host_os').and_return 'mswin' - ::Guard::UI.should_not_receive(:error).with "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." - subject.should_receive(:require).with('rb-notifu').and_raise LoadError + expect(RbConfig::CONFIG).to receive(:[]).with('host_os').and_return 'mswin' + expect(::Guard::UI).not_to receive(:error).with "Please add \"gem 'rb-notifu'\" to your Gemfile and run Guard with \"bundle exec\"." + expect(subject).to receive(:require).with('rb-notifu').and_raise LoadError subject.available?(true) end end @@ -47,13 +47,13 @@ def self.show(options) end describe '.nofify' do it 'requires the library again' do - subject.should_receive(:require).with('rb-notifu').and_return true + expect(subject).to receive(:require).with('rb-notifu').and_return true subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { }) end context 'without additional options' do it 'shows the notification with the default options' do - ::Notifu.should_receive(:show).with({ + expect(::Notifu).to receive(:show).with({ :time => 3, :icon => false, :baloon => false, @@ -70,7 +70,7 @@ def self.show(options) end context 'with additional options' do it 'can override the default options' do - ::Notifu.should_receive(:show).with({ + expect(::Notifu).to receive(:show).with({ :time => 5, :icon => true, :baloon => true, @@ -92,7 +92,7 @@ def self.show(options) end end it 'cannot override the core options' do - ::Notifu.should_receive(:show).with({ + expect(::Notifu).to receive(:show).with({ :time => 3, :icon => false, :baloon => false, diff --git a/spec/guard/notifiers/terminal_notifier_spec.rb b/spec/guard/notifiers/terminal_notifier_spec.rb index b1281b99b..0f76e4e1d 100644 --- a/spec/guard/notifiers/terminal_notifier_spec.rb +++ b/spec/guard/notifiers/terminal_notifier_spec.rb @@ -9,15 +9,15 @@ def self.execute(options) end end before do - subject.stub(:require) + allow(subject).to receive(:require) stub_const 'TerminalNotifier::Guard', fake_terminal_notifier end describe '.available?' do context 'without the silent option' do it 'shows an error message when not available on the host OS' do - ::Guard::UI.should_receive(:error).with 'The :terminal_notifier only runs on Mac OS X 10.8 and later.' - ::TerminalNotifier::Guard.stub(:available?).and_return(false) + expect(::Guard::UI).to receive(:error).with 'The :terminal_notifier only runs on Mac OS X 10.8 and later.' + allow(::TerminalNotifier::Guard).to receive(:available?).and_return(false) subject.available? end end @@ -25,7 +25,7 @@ def self.execute(options) end describe '.notify' do it 'should call the notifier.' do - ::TerminalNotifier::Guard.should_receive(:execute).with( + expect(::TerminalNotifier::Guard).to receive(:execute).with( false, { :title => 'any title', :type => :success, :message => 'any message' } ) @@ -33,7 +33,7 @@ def self.execute(options) end end it "should allow the title to be customized" do - ::TerminalNotifier::Guard.should_receive(:execute).with( + expect(::TerminalNotifier::Guard).to receive(:execute).with( false, { :title => 'any title', :message => 'any message', :type => :error } ) @@ -43,7 +43,7 @@ def self.execute(options) end context 'without a title set' do it 'should show the app name in the title' do - ::TerminalNotifier::Guard.should_receive(:execute).with( + expect(::TerminalNotifier::Guard).to receive(:execute).with( false, { :title => 'FooBar Success', :type => :success, :message => 'any message' } ) diff --git a/spec/guard/notifiers/terminal_title_spec.rb b/spec/guard/notifiers/terminal_title_spec.rb index 0ea345b4b..024c2f597 100644 --- a/spec/guard/notifiers/terminal_title_spec.rb +++ b/spec/guard/notifiers/terminal_title_spec.rb @@ -3,26 +3,26 @@ describe Guard::Notifier::TerminalTitle do before do - subject.stub!(:puts) + allow(subject).to receive(:puts) end describe '.available?' do context 'without the silent option' do it 'returns true' do - subject.available?.should be_true + expect(subject.available?).to be_truthy end end context 'with the silent option' do it 'returns true' do - subject.available?.should be_true + expect(subject.available?).to be_truthy end end end describe '.notify' do it 'set title + first line of message to terminal title' do - subject.should_receive(:puts).with("\e]2;[any title] first line\a") + expect(subject).to receive(:puts).with("\e]2;[any title] first line\a") subject.notify('success', 'any title', "first line\nsecond line\nthird", 'any image', { }) end end diff --git a/spec/guard/notifiers/tmux_spec.rb b/spec/guard/notifiers/tmux_spec.rb index 0c34b0e83..9008b559a 100644 --- a/spec/guard/notifiers/tmux_spec.rb +++ b/spec/guard/notifiers/tmux_spec.rb @@ -9,7 +9,7 @@ end it 'should return true' do - subject.available?.should be_true + expect(subject.available?).to be_truthy end end @@ -20,14 +20,14 @@ context 'without the silent option' do it 'shows an error message when the TMUX environment variable is not set' do - ::Guard::UI.should_receive(:error).with 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.' + expect(::Guard::UI).to receive(:error).with 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.' subject.available? end end context 'with the silent option' do it 'should return false' do - subject.available?(true).should be_false + expect(subject.available?(true)).to be_falsey end end end @@ -35,51 +35,51 @@ describe '.notify' do it 'should set the tmux status bar color to green on success' do - subject.should_receive(:system).with 'tmux set status-left-bg green' + expect(subject).to receive(:system).with 'tmux set status-left-bg green' subject.notify('success', 'any title', 'any message', 'any image', { }) end it 'should set the tmux status bar color to black on success when black is passed in as an option' do - subject.should_receive(:system).with "tmux set status-left-bg black" + expect(subject).to receive(:system).with "tmux set status-left-bg black" subject.notify('success', 'any title', 'any message', 'any image', { :success => 'black' }) end it 'should set the tmux status bar color to red on failure' do - subject.should_receive(:system).with 'tmux set status-left-bg red' + expect(subject).to receive(:system).with 'tmux set status-left-bg red' subject.notify('failed', 'any title', 'any message', 'any image', { }) end it 'should set the tmux status bar color to yellow on pending' do - subject.should_receive(:system).with 'tmux set status-left-bg yellow' + expect(subject).to receive(:system).with 'tmux set status-left-bg yellow' subject.notify('pending', 'any title', 'any message', 'any image', { }) end it 'should set the tmux status bar color to green on notify' do - subject.should_receive(:system).with 'tmux set status-left-bg green' + expect(subject).to receive(:system).with 'tmux set status-left-bg green' subject.notify('notify', 'any title', 'any message', 'any image', { }) end it 'should set the right tmux status bar color on success when the right status bar is passed in as an option' do - subject.should_receive(:system).with 'tmux set status-right-bg green' + expect(subject).to receive(:system).with 'tmux set status-right-bg green' subject.notify('success', 'any title', 'any message', 'any image', { :color_location => 'status-right-bg' }) end it 'calls display_message if the display_message flag is set' do - subject.stub :system => true - subject.should_receive(:display_message).with('notify', 'any title', 'any message', { :display_message => true }) + allow(subject).to receive(:system).and_return(true) + expect(subject).to receive(:display_message).with('notify', 'any title', 'any message', { :display_message => true }) subject.notify('notify', 'any title', 'any message', 'any image', { :display_message => true }) end it 'does not call display message if the display_message flag is not set' do - subject.stub :system => true - subject.should_receive(:display_message).never + allow(subject).to receive(:system).and_return(true) + expect(subject).to receive(:display_message).never subject.notify('notify', 'any title', 'any message', 'any image', { }) end @@ -87,71 +87,71 @@ describe '.display_message' do before do - subject.stub :system => true + allow(subject).to receive(:system).and_return(true) end it 'sets the display-time' do - subject.should_receive(:system).with('tmux set display-time 3000') + expect(subject).to receive(:system).with('tmux set display-time 3000') subject.display_message 'success', 'any title', 'any message', :timeout => 3 end it 'displays the message' do - subject.should_receive(:system).with('tmux display-message \'any title - any message\'').once + expect(subject).to receive(:system).with('tmux display-message \'any title - any message\'').once subject.display_message 'success', 'any title', 'any message' end it 'handles line-breaks' do - subject.should_receive(:system).with('tmux display-message \'any title - any message xx line two\'').once + expect(subject).to receive(:system).with('tmux display-message \'any title - any message xx line two\'').once subject.display_message 'success', 'any title', "any message\nline two", :line_separator => ' xx ' end context 'with success message type options' do it 'formats the message' do - subject.should_receive(:system).with('tmux display-message \'[any title] => any message - line two\'').once + expect(subject).to receive(:system).with('tmux display-message \'[any title] => any message - line two\'').once subject.display_message 'success', 'any title', "any message\nline two", :success_message_format => '[%s] => %s', :default_message_format => '(%s) -> %s' end it 'sets the foreground color based on the type for success' do - subject.should_receive(:system).with('tmux set message-fg green') + expect(subject).to receive(:system).with('tmux set message-fg green') subject.display_message 'success', 'any title', 'any message', { :success_message_color => 'green' } end it 'sets the background color' do - subject.should_receive(:system).with('tmux set message-bg blue') + expect(subject).to receive(:system).with('tmux set message-bg blue') subject.display_message 'success', 'any title', 'any message', { :success => :blue } end end context 'with pending message type options' do it 'formats the message' do - subject.should_receive(:system).with('tmux display-message \'[any title] === any message - line two\'').once + expect(subject).to receive(:system).with('tmux display-message \'[any title] === any message - line two\'').once subject.display_message 'pending', 'any title', "any message\nline two", :pending_message_format => '[%s] === %s', :default_message_format => '(%s) -> %s' end it 'sets the foreground color' do - subject.should_receive(:system).with('tmux set message-fg blue') + expect(subject).to receive(:system).with('tmux set message-fg blue') subject.display_message 'pending', 'any title', 'any message', { :pending_message_color => 'blue' } end it 'sets the background color' do - subject.should_receive(:system).with('tmux set message-bg white') + expect(subject).to receive(:system).with('tmux set message-bg white') subject.display_message 'pending', 'any title', 'any message', { :pending => :white } end end context 'with failed message type options' do it 'formats the message' do - subject.should_receive(:system).with('tmux display-message \'[any title] <=> any message - line two\'').once + expect(subject).to receive(:system).with('tmux display-message \'[any title] <=> any message - line two\'').once subject.display_message 'failed', 'any title', "any message\nline two", :failed_message_format => '[%s] <=> %s', :default_message_format => '(%s) -> %s' end it 'sets the foreground color' do - subject.should_receive(:system).with('tmux set message-fg red') + expect(subject).to receive(:system).with('tmux set message-fg red') subject.display_message 'failed', 'any title', 'any message', { :failed_message_color => 'red' } end it 'sets the background color' do - subject.should_receive(:system).with('tmux set message-bg black') + expect(subject).to receive(:system).with('tmux set message-bg black') subject.display_message 'failed', 'any title', 'any message', { :failed => :black } end end @@ -160,12 +160,12 @@ describe '.turn_on' do before do - subject.stub(:`).and_return("option1 setting1\noption2 setting2\n") - subject.stub :system => true + allow(subject).to receive(:`).and_return("option1 setting1\noption2 setting2\n") + allow(subject).to receive(:system).and_return(true) end it 'quiets the tmux output' do - subject.should_receive(:system).with 'tmux set quiet on' + expect(subject).to receive(:system).with 'tmux set quiet on' subject.turn_on end @@ -175,12 +175,12 @@ end it 'resets the options store' do - subject.should_receive(:reset_options_store) + expect(subject).to receive(:reset_options_store) subject.turn_on end it 'saves the current tmux options' do - subject.should_receive(:`).with('tmux show') + expect(subject).to receive(:`).with('tmux show') subject.turn_on end end @@ -191,12 +191,12 @@ end it 'does not reset the options store' do - subject.should_not_receive(:reset_options_store) + expect(subject).not_to receive(:reset_options_store) subject.turn_on end it 'does not save the current tmux options' do - subject.should_not_receive(:`).with('tmux show') + expect(subject).not_to receive(:`).with('tmux show') subject.turn_on end end @@ -204,8 +204,8 @@ describe '.turn_off' do before do - subject.stub(:`).and_return("option1 setting1\noption2 setting2\n") - subject.stub :system => true + allow(subject).to receive(:`).and_return("option1 setting1\noption2 setting2\n") + allow(subject).to receive(:system).and_return(true) end context 'when on' do @@ -214,24 +214,24 @@ end it 'restores the tmux options' do - subject.should_receive(:system).with('tmux set option2 setting2') - subject.should_receive(:system).with('tmux set -u status-left-bg') - subject.should_receive(:system).with('tmux set option1 setting1') - subject.should_receive(:system).with('tmux set -u status-right-bg') - subject.should_receive(:system).with('tmux set -u status-right-fg') - subject.should_receive(:system).with('tmux set -u status-left-fg') - subject.should_receive(:system).with('tmux set -u message-fg') - subject.should_receive(:system).with('tmux set -u message-bg') + expect(subject).to receive(:system).with('tmux set option2 setting2') + expect(subject).to receive(:system).with('tmux set -u status-left-bg') + expect(subject).to receive(:system).with('tmux set option1 setting1') + expect(subject).to receive(:system).with('tmux set -u status-right-bg') + expect(subject).to receive(:system).with('tmux set -u status-right-fg') + expect(subject).to receive(:system).with('tmux set -u status-left-fg') + expect(subject).to receive(:system).with('tmux set -u message-fg') + expect(subject).to receive(:system).with('tmux set -u message-bg') subject.turn_off end it 'resets the options store' do - subject.should_receive(:reset_options_store) + expect(subject).to receive(:reset_options_store) subject.turn_off end it 'unquiets the tmux output' do - subject.should_receive(:system).with 'tmux set quiet off' + expect(subject).to receive(:system).with 'tmux set quiet off' subject.turn_off end end @@ -242,22 +242,22 @@ end it 'does not restore the tmux options' do - subject.should_not_receive(:system).with('tmux set -u status-left-bg') - subject.should_not_receive(:system).with('tmux set -u status-right-bg') - subject.should_not_receive(:system).with('tmux set -u status-right-fg') - subject.should_not_receive(:system).with('tmux set -u status-left-fg') - subject.should_not_receive(:system).with('tmux set -u message-fg') - subject.should_not_receive(:system).with('tmux set -u message-bg') + expect(subject).not_to receive(:system).with('tmux set -u status-left-bg') + expect(subject).not_to receive(:system).with('tmux set -u status-right-bg') + expect(subject).not_to receive(:system).with('tmux set -u status-right-fg') + expect(subject).not_to receive(:system).with('tmux set -u status-left-fg') + expect(subject).not_to receive(:system).with('tmux set -u message-fg') + expect(subject).not_to receive(:system).with('tmux set -u message-bg') subject.turn_off end it 'does not reset the options store' do - subject.should_not_receive(:reset_options_store) + expect(subject).not_to receive(:reset_options_store) subject.turn_off end it 'unquiets the tmux output' do - subject.should_receive(:system).with 'tmux set quiet off' + expect(subject).to receive(:system).with 'tmux set quiet off' subject.turn_off end end diff --git a/spec/guard/runner_spec.rb b/spec/guard/runner_spec.rb index 2979899b4..9bc0d035e 100644 --- a/spec/guard/runner_spec.rb +++ b/spec/guard/runner_spec.rb @@ -29,24 +29,24 @@ before do # Stub the groups to avoid using the real ones from Guardfile (ex.: Guard::Rspec) - guard_module.stub(:groups) { [foo_group, bar_group] } + allow(guard_module).to receive(:groups) { [foo_group, bar_group] } end describe '#deprecation_warning' do - before { guard_module.stub(:guards) { [foo_guard] } } + before { allow(guard_module).to receive(:guards) { [foo_guard] } } context 'when neither run_on_change nor run_on_deletion is implemented in a guard' do it 'does not display a deprecation warning to the user' do - ui_module.should_not_receive(:deprecation) + expect(ui_module).not_to receive(:deprecation) subject.deprecation_warning end end context 'when run_on_change is implemented in a guard' do - before { foo_guard.stub(:run_on_change) } + before { allow(foo_guard).to receive(:run_on_change) } it 'displays a deprecation warning to the user' do - ui_module.should_receive(:deprecation).with( + expect(ui_module).to receive(:deprecation).with( described_class::RUN_ON_CHANGE_DEPRECATION % foo_guard.class.name ) subject.deprecation_warning @@ -54,10 +54,10 @@ end context 'when run_on_deletion is implemented in a guard' do - before { foo_guard.stub(:run_on_deletion) } + before { allow(foo_guard).to receive(:run_on_deletion) } it 'displays a deprecation warning to the user' do - ui_module.should_receive(:deprecation).with( + expect(ui_module).to receive(:deprecation).with( described_class::RUN_ON_DELETION_DEPRECATION % foo_guard.class.name ) subject.deprecation_warning @@ -70,19 +70,19 @@ it 'executes a supervised task on all registered guards implementing that task' do [foo_guard, bar1_guard].each do |g| - g.stub(:my_task) - subject.should_receive(:run_supervised_task).with(g, :my_task) + allow(g).to receive(:my_task) + expect(subject).to receive(:run_supervised_task).with(g, :my_task) end subject.run(:my_task) end it 'marks an action as unit of work' do - Lumberjack.should_receive(:unit_of_work) + expect(Lumberjack).to receive(:unit_of_work) subject.run(:my_task) end context 'with a failing task' do - before { subject.stub(:run_supervised_task) { throw :task_has_failed } } + before { allow(subject).to receive(:run_supervised_task) { throw :task_has_failed } } it 'catches the thrown symbol' do expect { @@ -95,11 +95,11 @@ let(:scopes) { { :plugins => [bar1_guard] } } it 'executes the supervised task on the specified guard only' do - bar1_guard.stub(:my_task) - subject.should_receive(:run_supervised_task).with(bar1_guard, :my_task) + allow(bar1_guard).to receive(:my_task) + expect(subject).to receive(:run_supervised_task).with(bar1_guard, :my_task) - subject.should_not_receive(:run_supervised_task).with(foo_guard, :my_task) - subject.should_not_receive(:run_supervised_task).with(bar2_guard, :my_task) + expect(subject).not_to receive(:run_supervised_task).with(foo_guard, :my_task) + expect(subject).not_to receive(:run_supervised_task).with(bar2_guard, :my_task) subject.run(:my_task, scopes) end @@ -109,11 +109,11 @@ let(:scopes) { { :groups => [foo_group] } } it 'executes the task on each guard in the specified group only' do - foo_guard.stub(:my_task) - subject.should_receive(:run_supervised_task).with(foo_guard, :my_task) + allow(foo_guard).to receive(:my_task) + expect(subject).to receive(:run_supervised_task).with(foo_guard, :my_task) - subject.should_not_receive(:run_supervised_task).with(bar1_guard, :my_task) - subject.should_not_receive(:run_supervised_task).with(bar2_guard, :my_task) + expect(subject).not_to receive(:run_supervised_task).with(bar1_guard, :my_task) + expect(subject).not_to receive(:run_supervised_task).with(bar2_guard, :my_task) subject.run(:my_task, scopes) end @@ -125,21 +125,21 @@ let(:watcher_module) { ::Guard::Watcher } before do - subject.stub(:scoped_guards).and_yield(foo_guard) - subject.stub(:clearable?) { false } - watcher_module.stub(:match_files) { [] } + allow(subject).to receive(:scoped_guards).and_yield(foo_guard) + allow(subject).to receive(:clearable?) { false } + allow(watcher_module).to receive(:match_files) { [] } end it "always calls UI.clearable" do - Guard::UI.should_receive(:clearable) + expect(Guard::UI).to receive(:clearable) subject.run_on_changes(*changes) end context 'when clearable' do - before { subject.stub(:clearable?) { true } } + before { allow(subject).to receive(:clearable?) { true } } it "clear UI" do - Guard::UI.should_receive(:clear) + expect(Guard::UI).to receive(:clear) subject.run_on_changes(*changes) end end @@ -147,7 +147,7 @@ context 'with no changes' do it 'does not run any task' do %w[run_on_modifications run_on_change run_on_additions run_on_removals run_on_deletion].each do |task| - foo_guard.should_not_receive(task.to_sym) + expect(foo_guard).not_to receive(task.to_sym) end subject.run_on_changes(*changes) end @@ -158,11 +158,11 @@ before do changes[0] = modified - watcher_module.should_receive(:match_files).once.with(foo_guard, modified).and_return([]) + expect(watcher_module).to receive(:match_files).once.with(foo_guard, modified).and_return([]) end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + expect(subject).not_to receive(:run_first_task_found) subject.run_on_changes(*changes) end end @@ -172,11 +172,11 @@ before do changes[0] = modified - watcher_module.should_receive(:match_files).with(foo_guard, modified).and_return(modified) + expect(watcher_module).to receive(:match_files).with(foo_guard, modified).and_return(modified) end it 'executes the :run_first_task_found task' do - subject.should_receive(:run_first_task_found).with(foo_guard, [:run_on_modifications, :run_on_changes, :run_on_change], modified) + expect(subject).to receive(:run_first_task_found).with(foo_guard, [:run_on_modifications, :run_on_changes, :run_on_change], modified) subject.run_on_changes(*changes) end end @@ -186,11 +186,11 @@ before do changes[0] = added - watcher_module.should_receive(:match_files).once.with(foo_guard, added).and_return([]) + expect(watcher_module).to receive(:match_files).once.with(foo_guard, added).and_return([]) end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + expect(subject).not_to receive(:run_first_task_found) subject.run_on_changes(*changes) end end @@ -200,11 +200,11 @@ before do changes[1] = added - watcher_module.should_receive(:match_files).with(foo_guard, added).and_return(added) + expect(watcher_module).to receive(:match_files).with(foo_guard, added).and_return(added) end it 'executes the :run_on_additions task' do - subject.should_receive(:run_first_task_found).with(foo_guard, [:run_on_additions, :run_on_changes, :run_on_change], added) + expect(subject).to receive(:run_first_task_found).with(foo_guard, [:run_on_additions, :run_on_changes, :run_on_change], added) subject.run_on_changes(*changes) end end @@ -214,11 +214,11 @@ before do changes[0] = removed - watcher_module.should_receive(:match_files).once.with(foo_guard, removed).and_return([]) + expect(watcher_module).to receive(:match_files).once.with(foo_guard, removed).and_return([]) end it 'does not call run_first_task_found' do - subject.should_not_receive(:run_first_task_found) + expect(subject).not_to receive(:run_first_task_found) subject.run_on_changes(*changes) end end @@ -228,28 +228,28 @@ before do changes[2] = removed - watcher_module.should_receive(:match_files).with(foo_guard, removed).and_return(removed) + expect(watcher_module).to receive(:match_files).with(foo_guard, removed).and_return(removed) end it 'executes the :run_on_removals task' do - subject.should_receive(:run_first_task_found).with(foo_guard, [:run_on_removals, :run_on_changes, :run_on_deletion], removed) + expect(subject).to receive(:run_first_task_found).with(foo_guard, [:run_on_removals, :run_on_changes, :run_on_deletion], removed) subject.run_on_changes(*changes) end end end describe '#run_supervised_task' do - before { guard_module.unstub(:groups) } + before { allow(guard_module).to receive(:groups).and_call_original } it 'executes the task on the passed guard' do - foo_guard.should_receive(:my_task) + expect(foo_guard).to receive(:my_task) subject.run_supervised_task(foo_guard, :my_task) end context 'with a task that succeeds' do context 'without any arguments' do before do - foo_guard.stub(:regular_without_arg) { true } + allow(foo_guard).to receive(:regular_without_arg) { true } end it 'does not remove the Guard' do @@ -259,24 +259,24 @@ end it 'returns the result of the task' do - subject.run_supervised_task(foo_guard, :regular_without_arg).should be_true + expect(subject.run_supervised_task(foo_guard, :regular_without_arg)).to be_truthy end it 'passes the args to the :begin hook' do - foo_guard.should_receive(:hook).with('regular_without_arg_begin', 'given_path') + expect(foo_guard).to receive(:hook).with('regular_without_arg_begin', 'given_path') subject.run_supervised_task(foo_guard, :regular_without_arg, 'given_path') end it 'passes the result of the supervised method to the :end hook' do - foo_guard.should_receive(:hook).with('regular_without_arg_begin', 'given_path') - foo_guard.should_receive(:hook).with('regular_without_arg_end', true) + expect(foo_guard).to receive(:hook).with('regular_without_arg_begin', 'given_path') + expect(foo_guard).to receive(:hook).with('regular_without_arg_end', true) subject.run_supervised_task(foo_guard, :regular_without_arg, 'given_path') end end context 'with arguments' do before do - foo_guard.stub(:regular_with_arg).with('given_path') { "I'm a success" } + allow(foo_guard).to receive(:regular_with_arg).with('given_path') { "I'm a success" } end it 'does not remove the Guard' do @@ -286,19 +286,19 @@ end it 'returns the result of the task' do - subject.run_supervised_task(foo_guard, :regular_with_arg, "given_path").should == "I'm a success" + expect(subject.run_supervised_task(foo_guard, :regular_with_arg, "given_path")).to eq("I'm a success") end it 'calls the default begin hook but not the default end hook' do - foo_guard.should_receive(:hook).with('failing_begin') - foo_guard.should_not_receive(:hook).with('failing_end') + expect(foo_guard).to receive(:hook).with('failing_begin') + expect(foo_guard).not_to receive(:hook).with('failing_end') subject.run_supervised_task(foo_guard, :failing) end end end context 'with a task that throws :task_has_failed' do - before { foo_guard.stub(:failing) { throw :task_has_failed } } + before { allow(foo_guard).to receive(:failing) { throw :task_has_failed } } context 'for a guard in group that has the :halt_on_fail option set to true' do before { foo_group.options[:halt_on_fail] = true } @@ -322,63 +322,63 @@ end context 'with a task that raises an exception' do - before { foo_guard.stub(:failing) { raise 'I break your system' } } + before { allow(foo_guard).to receive(:failing) { raise 'I break your system' } } it 'removes the Guard' do expect { subject.run_supervised_task(foo_guard, :failing) }.to change(guard_module.guards, :size).by(-1) - guard_module.guards.should_not include(foo_guard) + expect(guard_module.guards).not_to include(foo_guard) end it 'display an error to the user' do - ui_module.should_receive :error - ui_module.should_receive :info + expect(ui_module).to receive :error + expect(ui_module).to receive :info subject.run_supervised_task(foo_guard, :failing) end it 'returns the exception' do failing_result = subject.run_supervised_task(foo_guard, :failing) - failing_result.should be_kind_of(Exception) - failing_result.message.should == 'I break your system' + expect(failing_result).to be_kind_of(Exception) + expect(failing_result.message).to eq('I break your system') end end end describe '.stopping_symbol_for' do - let(:guard_implmentation) { mock(Guard::Guard).as_null_object } + let(:guard_implmentation) { double(Guard::Guard).as_null_object } it 'returns :task_has_failed when the group is missing' do - described_class.stopping_symbol_for(guard_implmentation).should == :task_has_failed + expect(described_class.stopping_symbol_for(guard_implmentation)).to eq(:task_has_failed) end context 'for a group with :halt_on_fail' do - let(:group) { mock(Guard::Group) } + let(:group) { double(Guard::Group) } before do - guard_implmentation.stub(:group).and_return :foo - group.stub(:options).and_return({ :halt_on_fail => true }) + allow(guard_implmentation).to receive(:group).and_return :foo + allow(group).to receive(:options).and_return({ :halt_on_fail => true }) end it 'returns :no_catch' do - guard_module.should_receive(:groups).with(:foo).and_return group - described_class.stopping_symbol_for(guard_implmentation).should == :no_catch + expect(guard_module).to receive(:groups).with(:foo).and_return group + expect(described_class.stopping_symbol_for(guard_implmentation)).to eq(:no_catch) end end context 'for a group without :halt_on_fail' do - let(:group) { mock(Guard::Group) } + let(:group) { double(Guard::Group) } before do - guard_implmentation.stub(:group).and_return :foo - group.stub(:options).and_return({ :halt_on_fail => false }) + allow(guard_implmentation).to receive(:group).and_return :foo + allow(group).to receive(:options).and_return({ :halt_on_fail => false }) end it 'returns :task_has_failed' do - guard_module.should_receive(:groups).with(:foo).and_return group - described_class.stopping_symbol_for(guard_implmentation).should == :task_has_failed + expect(guard_module).to receive(:groups).with(:foo).and_return group + expect(described_class.stopping_symbol_for(guard_implmentation)).to eq(:task_has_failed) end end end diff --git a/spec/guard/ui_spec.rb b/spec/guard/ui_spec.rb index 365f5997d..927916cda 100644 --- a/spec/guard/ui_spec.rb +++ b/spec/guard/ui_spec.rb @@ -7,53 +7,53 @@ # The spec helper stubs all UI classes, so other specs doesn't have # to explicit take care of it. We unstub and move the stubs one layer # down just for this spec. - Guard::UI.unstub(:info) - Guard::UI.unstub(:warning) - Guard::UI.unstub(:error) - Guard::UI.unstub(:deprecation) - Guard::UI.unstub(:debug) - - Guard::UI.logger.stub(:info) - Guard::UI.logger.stub(:warn) - Guard::UI.logger.stub(:error) - Guard::UI.logger.stub(:deprecation) - Guard::UI.logger.stub(:debug) + allow(Guard::UI).to receive(:info).and_call_original + allow(Guard::UI).to receive(:warning).and_call_original + allow(Guard::UI).to receive(:error).and_call_original + allow(Guard::UI).to receive(:deprecation).and_call_original + allow(Guard::UI).to receive(:debug).and_call_original + + allow(Guard::UI.logger).to receive(:info) + allow(Guard::UI.logger).to receive(:warn) + allow(Guard::UI.logger).to receive(:error) + allow(Guard::UI.logger).to receive(:deprecation) + allow(Guard::UI.logger).to receive(:debug) end after do - ::Guard::UI.stub(:info) - ::Guard::UI.stub(:warning) - ::Guard::UI.stub(:error) - ::Guard::UI.stub(:debug) - ::Guard::UI.stub(:deprecation) + allow(::Guard::UI).to receive(:info) + allow(::Guard::UI).to receive(:warning) + allow(::Guard::UI).to receive(:error) + allow(::Guard::UI).to receive(:debug) + allow(::Guard::UI).to receive(:deprecation) end describe '.logger' do it 'returns the logger instance' do - Guard::UI.logger.should be_an_instance_of Lumberjack::Logger + expect(Guard::UI.logger).to be_an_instance_of Lumberjack::Logger end it 'sets the logger device' do - Guard::UI.logger.device.send(:stream).should be $stderr + expect(Guard::UI.logger.device.send(:stream)).to be $stderr end end describe '.options=' do it 'sets the logger options' do Guard::UI.options = { :hi => :ho } - Guard::UI.options.should eql({ :hi => :ho }) + expect(Guard::UI.options).to eql({ :hi => :ho }) end end describe '.info' do it 'resets the line with the :reset option' do - Guard::UI.should_receive :reset_line + expect(Guard::UI).to receive :reset_line Guard::UI.info('Info message', { :reset => true }) end it 'logs the message to with the info severity' do - pending 'See: https://github.com/rspec/rspec-mocks/issues/613' - Guard::UI.logger.should_receive(:info).with('Info message', 'Guard::UiSpec') + skip 'See: https://github.com/rspec/rspec-mocks/issues/613' + expect(Guard::UI.logger).to receive(:info).with('Info message', 'Guard::UiSpec') Guard::UI.info 'Info message' end @@ -61,9 +61,9 @@ before { Guard::UI.options[:only] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_receive(:info).with('Info message', 'A') - Guard::UI.logger.should_not_receive(:info).with('Info message', 'B') - Guard::UI.logger.should_not_receive(:info).with('Info message', 'C') + expect(Guard::UI.logger).to receive(:info).with('Info message', 'A') + expect(Guard::UI.logger).not_to receive(:info).with('Info message', 'B') + expect(Guard::UI.logger).not_to receive(:info).with('Info message', 'C') Guard::UI.info 'Info message', :plugin => 'A' Guard::UI.info 'Info message', :plugin => 'B' @@ -75,9 +75,9 @@ before { Guard::UI.options[:except] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_not_receive(:info).with('Info message', 'A') - Guard::UI.logger.should_receive(:info).with('Info message', 'B') - Guard::UI.logger.should_receive(:info).with('Info message', 'C') + expect(Guard::UI.logger).not_to receive(:info).with('Info message', 'A') + expect(Guard::UI.logger).to receive(:info).with('Info message', 'B') + expect(Guard::UI.logger).to receive(:info).with('Info message', 'C') Guard::UI.info 'Info message', :plugin => 'A' Guard::UI.info 'Info message', :plugin => 'B' @@ -88,13 +88,13 @@ describe '.warning' do it 'resets the line with the :reset option' do - Guard::UI.should_receive :reset_line + expect(Guard::UI).to receive :reset_line Guard::UI.warning('Warn message', { :reset => true }) end it 'logs the message to with the warn severity' do - pending 'See: https://github.com/rspec/rspec-mocks/issues/613' - Guard::UI.logger.should_receive(:warn).with("\e[0;33mWarn message\e[0m", 'Guard::UiSpec') + skip 'See: https://github.com/rspec/rspec-mocks/issues/613' + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mWarn message\e[0m", 'Guard::UiSpec') Guard::UI.warning 'Warn message' end @@ -102,9 +102,9 @@ before { Guard::UI.options[:only] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_receive(:warn).with("\e[0;33mWarn message\e[0m", 'A') - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mWarn message\e[0m", 'B') - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mWarn message\e[0m", 'C') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mWarn message\e[0m", 'A') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mWarn message\e[0m", 'B') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mWarn message\e[0m", 'C') Guard::UI.warning 'Warn message', :plugin => 'A' Guard::UI.warning 'Warn message', :plugin => 'B' @@ -116,9 +116,9 @@ before { Guard::UI.options[:except] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mWarn message\e[0m", 'A') - Guard::UI.logger.should_receive(:warn).with("\e[0;33mWarn message\e[0m", 'B') - Guard::UI.logger.should_receive(:warn).with("\e[0;33mWarn message\e[0m", 'C') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mWarn message\e[0m", 'A') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mWarn message\e[0m", 'B') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mWarn message\e[0m", 'C') Guard::UI.warning 'Warn message', :plugin => 'A' Guard::UI.warning 'Warn message', :plugin => 'B' @@ -129,13 +129,13 @@ describe '.error' do it 'resets the line with the :reset option' do - Guard::UI.should_receive :reset_line + expect(Guard::UI).to receive :reset_line Guard::UI.error('Error message', { :reset => true }) end it 'logs the message to with the error severity' do - pending 'See: https://github.com/rspec/rspec-mocks/issues/613' - Guard::UI.logger.should_receive(:error).with("\e[0;31mError message\e[0m", 'Guard::UiSpec') + skip 'See: https://github.com/rspec/rspec-mocks/issues/613' + expect(Guard::UI.logger).to receive(:error).with("\e[0;31mError message\e[0m", 'Guard::UiSpec') Guard::UI.error 'Error message' end @@ -143,9 +143,9 @@ before { Guard::UI.options[:only] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_receive(:error).with("\e[0;31mError message\e[0m", 'A') - Guard::UI.logger.should_not_receive(:error).with("\e[0;31mError message\e[0m", 'B') - Guard::UI.logger.should_not_receive(:error).with("\e[0;31mError message\e[0m", 'C') + expect(Guard::UI.logger).to receive(:error).with("\e[0;31mError message\e[0m", 'A') + expect(Guard::UI.logger).not_to receive(:error).with("\e[0;31mError message\e[0m", 'B') + expect(Guard::UI.logger).not_to receive(:error).with("\e[0;31mError message\e[0m", 'C') Guard::UI.error 'Error message', :plugin => 'A' Guard::UI.error 'Error message', :plugin => 'B' @@ -157,9 +157,9 @@ before { Guard::UI.options[:except] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_not_receive(:error).with("\e[0;31mError message\e[0m", 'A') - Guard::UI.logger.should_receive(:error).with("\e[0;31mError message\e[0m", 'B') - Guard::UI.logger.should_receive(:error).with("\e[0;31mError message\e[0m", 'C') + expect(Guard::UI.logger).not_to receive(:error).with("\e[0;31mError message\e[0m", 'A') + expect(Guard::UI.logger).to receive(:error).with("\e[0;31mError message\e[0m", 'B') + expect(Guard::UI.logger).to receive(:error).with("\e[0;31mError message\e[0m", 'C') Guard::UI.error 'Error message', :plugin => 'A' Guard::UI.error 'Error message', :plugin => 'B' @@ -170,13 +170,13 @@ describe '.deprecation' do it 'resets the line with the :reset option' do - Guard::UI.should_receive :reset_line + expect(Guard::UI).to receive :reset_line Guard::UI.deprecation('Deprecation message', { :reset => true }) end it 'logs the message to with the warn severity' do - pending 'See: https://github.com/rspec/rspec-mocks/issues/613' - Guard::UI.logger.should_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'Guard::UiSpec') + skip 'See: https://github.com/rspec/rspec-mocks/issues/613' + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'Guard::UiSpec') Guard::UI.deprecation 'Deprecation message' end @@ -184,9 +184,9 @@ before { Guard::UI.options[:only] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'A') - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'B') - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'C') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'A') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'B') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'C') Guard::UI.deprecation 'Deprecation message', :plugin => 'A' Guard::UI.deprecation 'Deprecation message', :plugin => 'B' @@ -198,9 +198,9 @@ before { Guard::UI.options[:except] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_not_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'A') - Guard::UI.logger.should_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'B') - Guard::UI.logger.should_receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'C') + expect(Guard::UI.logger).not_to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'A') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'B') + expect(Guard::UI.logger).to receive(:warn).with("\e[0;33mDeprecation message\e[0m", 'C') Guard::UI.deprecation 'Deprecation message', :plugin => 'A' Guard::UI.deprecation 'Deprecation message', :plugin => 'B' @@ -211,13 +211,13 @@ describe '.debug' do it 'resets the line with the :reset option' do - Guard::UI.should_receive :reset_line + expect(Guard::UI).to receive :reset_line Guard::UI.debug('Debug message', { :reset => true }) end it 'logs the message to with the debug severity' do - pending 'See: https://github.com/rspec/rspec-mocks/issues/613' - Guard::UI.logger.should_receive(:debug).with("\e[0;33mDebug message\e[0m", 'Guard::UiSpec') + skip 'See: https://github.com/rspec/rspec-mocks/issues/613' + expect(Guard::UI.logger).to receive(:debug).with("\e[0;33mDebug message\e[0m", 'Guard::UiSpec') Guard::UI.debug 'Debug message' end @@ -225,9 +225,9 @@ before { Guard::UI.options[:only] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_receive(:debug).with("\e[0;33mDebug message\e[0m", 'A') - Guard::UI.logger.should_not_receive(:debug).with("\e[0;33mDebug message\e[0m", 'B') - Guard::UI.logger.should_not_receive(:debug).with("\e[0;33mDebug message\e[0m", 'C') + expect(Guard::UI.logger).to receive(:debug).with("\e[0;33mDebug message\e[0m", 'A') + expect(Guard::UI.logger).not_to receive(:debug).with("\e[0;33mDebug message\e[0m", 'B') + expect(Guard::UI.logger).not_to receive(:debug).with("\e[0;33mDebug message\e[0m", 'C') Guard::UI.debug 'Debug message', :plugin => 'A' Guard::UI.debug 'Debug message', :plugin => 'B' @@ -239,9 +239,9 @@ before { Guard::UI.options[:except] = /A/ } it 'shows only the matching messages' do - Guard::UI.logger.should_not_receive(:debug).with("\e[0;33mDebug message\e[0m", 'A') - Guard::UI.logger.should_receive(:debug).with("\e[0;33mDebug message\e[0m", 'B') - Guard::UI.logger.should_receive(:debug).with("\e[0;33mDebug message\e[0m", 'C') + expect(Guard::UI.logger).not_to receive(:debug).with("\e[0;33mDebug message\e[0m", 'A') + expect(Guard::UI.logger).to receive(:debug).with("\e[0;33mDebug message\e[0m", 'B') + expect(Guard::UI.logger).to receive(:debug).with("\e[0;33mDebug message\e[0m", 'C') Guard::UI.debug 'Debug message', :plugin => 'A' Guard::UI.debug 'Debug message', :plugin => 'B' @@ -252,34 +252,34 @@ describe '.clear' do context 'when the Guard clear option is enabled' do - before { ::Guard.stub(:options) { { :clear => true } } } + before { allow(::Guard).to receive(:options) { { :clear => true } } } it 'clears the outputs if clearable' do Guard::UI.clearable - Guard::UI.should_receive(:system).with('clear;') + expect(Guard::UI).to receive(:system).with('clear;') Guard::UI.clear end it 'doesn not clear the output if already cleared' do - Guard::UI.stub(:system) + allow(Guard::UI).to receive(:system) Guard::UI.clear - Guard::UI.should_not_receive(:system).with('clear;') + expect(Guard::UI).not_to receive(:system).with('clear;') Guard::UI.clear end it 'clears the outputs if forced' do - Guard::UI.stub(:system) + allow(Guard::UI).to receive(:system) Guard::UI.clear - Guard::UI.should_receive(:system).with('clear;') + expect(Guard::UI).to receive(:system).with('clear;') Guard::UI.clear(:force => true) end end context 'when the Guard clear option is disabled' do - before { ::Guard.stub(:options) { { :clear => false } } } + before { allow(::Guard).to receive(:options) { { :clear => false } } } it 'does not clear the output' do - Guard::UI.should_not_receive(:system).with('clear;') + expect(Guard::UI).not_to receive(:system).with('clear;') Guard::UI.clear end end @@ -288,14 +288,14 @@ describe '.action_with_scopes' do context 'with a plugins scope' do it 'shows the plugin scoped action' do - Guard::UI.should_receive(:info).with('Reload rspec,jasmine') + expect(Guard::UI).to receive(:info).with('Reload rspec,jasmine') Guard::UI.action_with_scopes('Reload', { :plugins => [:rspec, :jasmine] }) end end context 'with a groups scope' do it 'shows the group scoped action' do - Guard::UI.should_receive(:info).with('Reload frontend') + expect(Guard::UI).to receive(:info).with('Reload frontend') Guard::UI.action_with_scopes('Reload', { :groups => [:frontend] }) end end @@ -304,7 +304,7 @@ context 'with a global plugin scope' do it 'shows the global plugin scoped action' do Guard.scope = { :groups => [:test] } - Guard::UI.should_receive(:info).with('Reload test') + expect(Guard::UI).to receive(:info).with('Reload test') Guard::UI.action_with_scopes('Reload', {}) end end @@ -312,7 +312,7 @@ context 'with a global group scope' do it 'shows the global group scoped action' do Guard.scope = { :groups => [:backend] } - Guard::UI.should_receive(:info).with('Reload backend') + expect(Guard::UI).to receive(:info).with('Reload backend') Guard::UI.action_with_scopes('Reload', {}) end end diff --git a/spec/guard/watcher_spec.rb b/spec/guard/watcher_spec.rb index 48958b8d6..2879fb67e 100644 --- a/spec/guard/watcher_spec.rb +++ b/spec/guard/watcher_spec.rb @@ -10,24 +10,24 @@ context "with a pattern parameter" do context "that is a string" do it "keeps the string pattern unmodified" do - described_class.new('spec_helper.rb').pattern.should == 'spec_helper.rb' + expect(described_class.new('spec_helper.rb').pattern).to eq('spec_helper.rb') end end context "that is a regexp" do it "keeps the regex pattern unmodified" do - described_class.new(/spec_helper\.rb/).pattern.should == /spec_helper\.rb/ + expect(described_class.new(/spec_helper\.rb/).pattern).to eq(/spec_helper\.rb/) end end context "that is a string looking like a regex (deprecated)" do - before(:each) { Guard::UI.should_receive(:info).any_number_of_times } + before(:each) { allow(Guard::UI).to receive(:info) } it "converts the string automatically to a regex" do - described_class.new('^spec_helper.rb').pattern.should eq(/^spec_helper.rb/) - described_class.new('spec_helper.rb$').pattern.should eq(/spec_helper.rb$/) - described_class.new('spec_helper\.rb').pattern.should eq(/spec_helper\.rb/) - described_class.new('.*_spec.rb').pattern.should eq(/.*_spec.rb/) + expect(described_class.new('^spec_helper.rb').pattern).to eq(/^spec_helper.rb/) + expect(described_class.new('spec_helper.rb$').pattern).to eq(/spec_helper.rb$/) + expect(described_class.new('spec_helper\.rb').pattern).to eq(/spec_helper\.rb/) + expect(described_class.new('.*_spec.rb').pattern).to eq(/.*_spec.rb/) end end end @@ -35,12 +35,12 @@ describe "#action" do it "sets the action to nothing by default" do - described_class.new(/spec_helper\.rb/).action.should be_nil + expect(described_class.new(/spec_helper\.rb/).action).to be_nil end it "sets the action to the supplied block" do action = lambda { |m| "spec/#{m[1]}_spec.rb" } - described_class.new(%r{^lib/(.*).rb}, action).action.should == action + expect(described_class.new(%r{^lib/(.*).rb}, action).action).to eq(action) end end @@ -56,7 +56,7 @@ before(:all) { @guard.watchers = [described_class.new(/.*_spec\.rb/)] } it "returns the paths that matches the regex" do - described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb'] + expect(described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb'])).to eq(['guard_rocks_spec.rb']) end end @@ -64,7 +64,7 @@ before(:all) { @guard.watchers = [described_class.new('guard_rocks_spec.rb')] } it "returns the path that matches the string" do - described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb']).should == ['guard_rocks_spec.rb'] + expect(described_class.match_files(@guard, ['guard_rocks_spec.rb', 'guard_rocks.rb'])).to eq(['guard_rocks_spec.rb']) end end end @@ -83,27 +83,27 @@ end it "returns a single file specified within the action" do - described_class.match_files(@guard, ['spec_helper.rb']).should == ['spec'] + expect(described_class.match_files(@guard, ['spec_helper.rb'])).to eq(['spec']) end it "returns multiple files specified within the action" do - described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar'] + expect(described_class.match_files(@guard, ['hash.rb'])).to eq(['foo', 'bar']) end it "returns multiple files by combining the results of different actions" do - described_class.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar'] + expect(described_class.match_files(@guard, ['spec_helper.rb', 'array.rb'])).to eq(['spec', 'foo', 'bar']) end it "returns nothing if the action returns something other than a string or an array of strings" do - described_class.match_files(@guard, ['addition.rb']).should == [] + expect(described_class.match_files(@guard, ['addition.rb'])).to eq([]) end it "returns nothing if the action response is empty" do - described_class.match_files(@guard, ['blank.rb']).should == [] + expect(described_class.match_files(@guard, ['blank.rb'])).to eq([]) end it "returns nothing if the action returns nothing" do - described_class.match_files(@guard, ['uptime.rb']).should == [] + expect(described_class.match_files(@guard, ['uptime.rb'])).to eq([]) end end @@ -120,29 +120,29 @@ end it "returns a single file specified within the action" do - described_class.match_files(@guard_any_return, ['spec_helper.rb']).class.should be Array - described_class.match_files(@guard_any_return, ['spec_helper.rb']).empty?.should be_false + expect(described_class.match_files(@guard_any_return, ['spec_helper.rb']).class).to be Array + expect(described_class.match_files(@guard_any_return, ['spec_helper.rb']).empty?).to be_falsey end it "returns multiple files specified within the action" do - described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar'}] + expect(described_class.match_files(@guard_any_return, ['hash.rb'])).to eq([{:foo => 'bar'}]) end it "returns multiple files by combining the results of different actions" do - described_class.match_files(@guard_any_return, ['spec_helper.rb', 'array.rb']).should == ['spec', ['foo', 'bar']] + expect(described_class.match_files(@guard_any_return, ['spec_helper.rb', 'array.rb'])).to eq(['spec', ['foo', 'bar']]) end it "returns the evaluated addition argument in an array" do - described_class.match_files(@guard_any_return, ['addition.rb']).class.should be Array - described_class.match_files(@guard_any_return, ['addition.rb'])[0].should eq 2 + expect(described_class.match_files(@guard_any_return, ['addition.rb']).class).to be Array + expect(described_class.match_files(@guard_any_return, ['addition.rb'])[0]).to eq 2 end it "returns nothing if the action response is empty string" do - described_class.match_files(@guard_any_return, ['blank.rb']).should == [''] + expect(described_class.match_files(@guard_any_return, ['blank.rb'])).to eq(['']) end it "returns nothing if the action returns empty string" do - described_class.match_files(@guard_any_return, ['uptime.rb']).should == [''] + expect(described_class.match_files(@guard_any_return, ['uptime.rb'])).to eq(['']) end end end @@ -161,27 +161,27 @@ end it "returns a substituted single file specified within the action" do - described_class.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb'] + expect(described_class.match_files(@guard, ['lib/my_wonderful_lib.rb'])).to eq(['spec/my_wonderful_lib_spec.rb']) end it "returns multiple files specified within the action" do - described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar'] + expect(described_class.match_files(@guard, ['hash.rb'])).to eq(['foo', 'bar']) end it "returns multiple files by combining the results of different actions" do - described_class.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar'] + expect(described_class.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb'])).to eq(['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']) end it "returns nothing if the action returns something other than a string or an array of strings" do - described_class.match_files(@guard, ['addition.rb']).should == [] + expect(described_class.match_files(@guard, ['addition.rb'])).to eq([]) end it "returns nothing if the action response is empty" do - described_class.match_files(@guard, ['blank.rb']).should == [] + expect(described_class.match_files(@guard, ['blank.rb'])).to eq([]) end it "returns nothing if the action returns nothing" do - described_class.match_files(@guard, ['uptime.rb']).should == [] + expect(described_class.match_files(@guard, ['uptime.rb'])).to eq([]) end end @@ -198,27 +198,27 @@ end it "returns a substituted single file specified within the action" do - described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb'] + expect(described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb'])).to eq(['spec/my_wonderful_lib_spec.rb']) end it "returns a hash specified within the action" do - described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar', :file_name => 'hash.rb'}] + expect(described_class.match_files(@guard_any_return, ['hash.rb'])).to eq([{:foo => 'bar', :file_name => 'hash.rb'}]) end it "returns multiple files by combining the results of different actions" do - described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', ['foo', 'bar', "array.rb"]] + expect(described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb', 'array.rb'])).to eq(['spec/my_wonderful_lib_spec.rb', ['foo', 'bar', "array.rb"]]) end it "returns the evaluated addition argument + the path" do - described_class.match_files(@guard_any_return, ['addition.rb']).should == ["2addition.rb"] + expect(described_class.match_files(@guard_any_return, ['addition.rb'])).to eq(["2addition.rb"]) end it "returns nothing if the action response is empty string" do - described_class.match_files(@guard_any_return, ['blank.rb']).should == [''] + expect(described_class.match_files(@guard_any_return, ['blank.rb'])).to eq(['']) end it "returns nothing if the action returns empty string" do - described_class.match_files(@guard_any_return, ['uptime.rb']).should == [''] + expect(described_class.match_files(@guard_any_return, ['uptime.rb'])).to eq(['']) end end end @@ -227,9 +227,9 @@ before(:all) { @guard.watchers = [described_class.new('evil.rb', lambda { raise "EVIL" })] } it "displays the error and backtrace" do - Guard::UI.should_receive(:error) do |msg| - msg.should include("Problem with watch action!") - msg.should include("EVIL") + expect(Guard::UI).to receive(:error) do |msg| + expect(msg).to include("Problem with watch action!") + expect(msg).to include("EVIL") end described_class.match_files(@guard, ['evil.rb']) @@ -245,11 +245,11 @@ end context "with a watcher that matches a file" do - specify { described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb', 'guard_rocks_spec.rb']).should be_true } + specify { expect(described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb', 'guard_rocks_spec.rb'])).to be_truthy } end context "with no watcher that matches a file" do - specify { described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb']).should be_false } + specify { expect(described_class.match_files?(@guards, ['lib/my_wonderful_lib.rb'])).to be_falsey } end end @@ -259,17 +259,17 @@ subject { described_class.new('guard_rocks_spec.rb') } context "with a watcher that matches a file" do - specify { subject.match('guard_rocks_spec.rb').should eq ['guard_rocks_spec.rb'] } + specify { expect(subject.match('guard_rocks_spec.rb')).to eq ['guard_rocks_spec.rb'] } end context "with a file containing a $" do subject { described_class.new('lib$/guard_rocks_spec.rb') } - specify { subject.match('lib$/guard_rocks_spec.rb').should eq ['lib$/guard_rocks_spec.rb'] } + specify { expect(subject.match('lib$/guard_rocks_spec.rb')).to eq ['lib$/guard_rocks_spec.rb'] } end context "with no watcher that matches a file" do - specify { subject.match('lib/my_wonderful_lib.rb').should be_nil } + specify { expect(subject.match('lib/my_wonderful_lib.rb')).to be_nil } end end @@ -277,11 +277,11 @@ subject { described_class.new('^guard_(rocks)_spec\.rb$') } context "with a watcher that matches a file" do - specify { subject.match('guard_rocks_spec.rb').should eq ['guard_rocks_spec.rb', 'rocks'] } + specify { expect(subject.match('guard_rocks_spec.rb')).to eq ['guard_rocks_spec.rb', 'rocks'] } end context "with no watcher that matches a file" do - specify { subject.match('lib/my_wonderful_lib.rb').should be_nil } + specify { expect(subject.match('lib/my_wonderful_lib.rb')).to be_nil } end end end @@ -290,15 +290,15 @@ subject { described_class.new(/(.*)_spec\.rb/) } context "with a watcher that matches a file" do - specify { subject.match('guard_rocks_spec.rb').should eq ['guard_rocks_spec.rb', 'guard_rocks'] } + specify { expect(subject.match('guard_rocks_spec.rb')).to eq ['guard_rocks_spec.rb', 'guard_rocks'] } end context "with a file containing a $" do - specify { subject.match('lib$/guard_rocks_spec.rb').should eq ['lib$/guard_rocks_spec.rb', 'lib$/guard_rocks'] } + specify { expect(subject.match('lib$/guard_rocks_spec.rb')).to eq ['lib$/guard_rocks_spec.rb', 'lib$/guard_rocks'] } end context "with no watcher that matches a file" do - specify { subject.match('lib/my_wonderful_lib.rb').should be_nil } + specify { expect(subject.match('lib/my_wonderful_lib.rb')).to be_nil } end end @@ -307,11 +307,11 @@ subject { described_class.new('guard_rocks_spec.rb') } context "with a watcher that matches a file" do - specify { subject.match('!guard_rocks_spec.rb').should eq ['!guard_rocks_spec.rb'] } + specify { expect(subject.match('!guard_rocks_spec.rb')).to eq ['!guard_rocks_spec.rb'] } end context "with no watcher that matches a file" do - specify { subject.match('!lib/my_wonderful_lib.rb').should be_nil } + specify { expect(subject.match('!lib/my_wonderful_lib.rb')).to be_nil } end end @@ -319,25 +319,25 @@ subject { described_class.new(/(.*)_spec\.rb/) } context "with a watcher that matches a file" do - specify { subject.match('!guard_rocks_spec.rb').should eq ['!guard_rocks_spec.rb', 'guard_rocks'] } + specify { expect(subject.match('!guard_rocks_spec.rb')).to eq ['!guard_rocks_spec.rb', 'guard_rocks'] } end context "with no watcher that matches a file" do - specify { subject.match('!lib/my_wonderful_lib.rb').should be_nil } + specify { expect(subject.match('!lib/my_wonderful_lib.rb')).to be_nil } end end end end describe ".match_guardfile?" do - before { Guard::Dsl.stub(:guardfile_path) { Dir.pwd + '/Guardfile' } } + before { allow(Guard::Dsl).to receive(:guardfile_path) { Dir.pwd + '/Guardfile' } } context "with files that match the Guardfile" do - specify { described_class.match_guardfile?(['Guardfile', 'guard_rocks_spec.rb']).should be_true } + specify { expect(described_class.match_guardfile?(['Guardfile', 'guard_rocks_spec.rb'])).to be_truthy } end context "with no files that match the Guardfile" do - specify { described_class.match_guardfile?(['guard_rocks.rb', 'guard_rocks_spec.rb']).should be_false } + specify { expect(described_class.match_guardfile?(['guard_rocks.rb', 'guard_rocks_spec.rb'])).to be_falsey } end end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index fa4ef34d3..606119a18 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -2,8 +2,8 @@ describe Guard do before do - ::Guard::Interactor.stub(:fabricate) - Dir.stub(:chdir) + allow(::Guard::Interactor).to receive(:fabricate) + allow(Dir).to receive(:chdir) end describe ".setup" do @@ -11,65 +11,65 @@ subject { ::Guard.setup(options) } it "returns itself for chaining" do - subject.should be ::Guard + expect(subject).to be ::Guard end it "initializes the plugins" do - subject.guards.should eq [] + expect(subject.guards).to eq [] end it "initializes the groups" do - subject.groups[0].name.should eq :default - subject.groups[0].options.should == { } + expect(subject.groups[0].name).to eq :default + expect(subject.groups[0].options).to eq({ }) end it "initializes the options" do - subject.options.should include(:my_opts) + expect(subject.options).to include(:my_opts) end it "initializes the listener" do - subject.listener.should be_kind_of(Listen::Listener) + expect(subject.listener).to be_kind_of(Listen::Listener) end it "respect the watchdir option" do ::Guard.setup(:watchdir => '/usr') - ::Guard.listener.directories.should eq ['/usr'] + expect(::Guard.listener.directories).to eq ['/usr'] end it "changes the current work dir to the watchdir" do - Dir.should_receive(:chdir).with('/tmp') + expect(Dir).to receive(:chdir).with('/tmp') ::Guard.setup(:watchdir => '/tmp') end it "call setup_signal_traps" do - ::Guard.should_receive(:setup_signal_traps) + expect(::Guard).to receive(:setup_signal_traps) subject end it "evaluates the DSL" do - ::Guard::Dsl.should_receive(:evaluate_guardfile).with(options) + expect(::Guard::Dsl).to receive(:evaluate_guardfile).with(options) subject end it "displays an error message when no guard are defined in Guardfile" do - ::Guard::UI.should_receive(:error).with('No guards found in Guardfile, please add at least one.') + expect(::Guard::UI).to receive(:error).with('No guards found in Guardfile, please add at least one.') subject end it "call setup_notifier" do - ::Guard.should_receive(:setup_notifier) + expect(::Guard).to receive(:setup_notifier) subject end it "call setup_interactor" do - ::Guard.should_receive(:setup_interactor) + expect(::Guard).to receive(:setup_interactor) subject end context 'without the group or plugin option' do it "initializes the empty scope" do - subject.scope.should == { :groups => [], :plugins => [] } + expect(subject.scope).to eq({ :groups => [], :plugins => [] }) end end @@ -80,10 +80,10 @@ } } it "initializes the group scope" do - subject.scope[:plugins].should be_empty - subject.scope[:groups].count.should be 2 - subject.scope[:groups][0].name.should eql :backend - subject.scope[:groups][1].name.should eql :frontend + expect(subject.scope[:plugins]).to be_empty + expect(subject.scope[:groups].count).to be 2 + expect(subject.scope[:groups][0].name).to eql :backend + expect(subject.scope[:groups][1].name).to eql :frontend end end @@ -100,21 +100,21 @@ end it "initializes the plugin scope" do - subject.scope[:groups].should be_empty - subject.scope[:plugins].count.should be 2 - subject.scope[:plugins][0].class.should eql ::Guard::Cucumber - subject.scope[:plugins][1].class.should eql ::Guard::Jasmine + expect(subject.scope[:groups]).to be_empty + expect(subject.scope[:plugins].count).to be 2 + expect(subject.scope[:plugins][0].class).to eql ::Guard::Cucumber + expect(subject.scope[:plugins][1].class).to eql ::Guard::Jasmine end end context 'when deprecations should be shown' do let(:options) { { :show_deprecations => true, :guardfile => File.join(@fixture_path, "Guardfile") } } subject { ::Guard.setup(options) } - let(:runner) { mock('runner') } + let(:runner) { double('runner') } it 'calls the runner show deprecations' do - ::Guard::Runner.should_receive(:new).and_return runner - runner.should_receive(:deprecation_warning) + expect(::Guard::Runner).to receive(:new).and_return runner + expect(runner).to receive(:deprecation_warning) subject end end @@ -124,37 +124,37 @@ subject { ::Guard.setup(options) } it "logs command execution if the debug option is true" do - ::Guard.should_receive(:debug_command_execution) + expect(::Guard).to receive(:debug_command_execution) subject end it "sets the log level to :debug if the debug option is true" do subject - ::Guard::UI.options[:level].should eql :debug + expect(::Guard::UI.options[:level]).to eql :debug end end end describe ".setup_signal_traps", :speed => 'slow' do - before { ::Guard::Dsl.stub(:evaluate_guardfile) } + before { allow(::Guard::Dsl).to receive(:evaluate_guardfile) } unless windows? || defined?(JRUBY_VERSION) context 'when receiving SIGUSR1' do context 'when Guard is running' do - before { ::Guard.listener.should_receive(:paused?).and_return false } + before { expect(::Guard.listener).to receive(:paused?).and_return false } it 'pauses Guard' do - ::Guard.should_receive(:pause) + expect(::Guard).to receive(:pause) Process.kill :USR1, Process.pid sleep 1 end end context 'when Guard is already paused' do - before { ::Guard.listener.should_receive(:paused?).and_return true } + before { expect(::Guard.listener).to receive(:paused?).and_return true } it 'does not pauses Guard' do - ::Guard.should_not_receive(:pause) + expect(::Guard).not_to receive(:pause) Process.kill :USR1, Process.pid sleep 1 end @@ -163,20 +163,20 @@ context 'when receiving SIGUSR2' do context 'when Guard is paused' do - before { ::Guard.listener.should_receive(:paused?).and_return true } + before { expect(::Guard.listener).to receive(:paused?).and_return true } it 'un-pause Guard' do - ::Guard.should_receive(:pause) + expect(::Guard).to receive(:pause) Process.kill :USR2, Process.pid sleep 1 end end context 'when Guard is already running' do - before { ::Guard.listener.should_receive(:paused?).and_return false } + before { expect(::Guard.listener).to receive(:paused?).and_return false } it 'does not un-pause Guard' do - ::Guard.should_not_receive(:pause) + expect(::Guard).not_to receive(:pause) Process.kill :USR2, Process.pid sleep 1 end @@ -185,21 +185,21 @@ context 'when receiving SIGINT' do context 'without an interactor' do - before { ::Guard.should_receive(:interactor).and_return nil } + before { expect(::Guard).to receive(:interactor).and_return nil } it 'stops Guard' do - ::Guard.should_receive(:stop) + expect(::Guard).to receive(:stop) Process.kill :INT, Process.pid sleep 1 end end context 'with an interactor' do - let(:interactor) { mock('interactor', :thread => mock('thread')) } - before { ::Guard.should_receive(:interactor).twice.and_return interactor } + let(:interactor) { double('interactor', :thread => double('thread')) } + before { expect(::Guard).to receive(:interactor).twice.and_return interactor } it 'delegates to the Pry thread' do - interactor.thread.should_receive(:raise).with Interrupt + expect(interactor.thread).to receive(:raise).with Interrupt Process.kill :INT, Process.pid sleep 1 end @@ -212,7 +212,7 @@ before { ENV["GUARD_NOTIFY"] = nil } it "turns on the notifier on" do - ::Guard::Notifier.should_receive(:turn_on) + expect(::Guard::Notifier).to receive(:turn_on) ::Guard.setup(:notify => true) end end @@ -221,7 +221,7 @@ before { ENV["GUARD_NOTIFY"] = 'true' } it "turns on the notifier on" do - ::Guard::Notifier.should_receive(:turn_on) + expect(::Guard::Notifier).to receive(:turn_on) ::Guard.setup(:notify => true) end end @@ -230,7 +230,7 @@ before { ENV["GUARD_NOTIFY"] = 'false' } it "turns on the notifier off" do - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) ::Guard.setup(:notify => true) end end @@ -241,7 +241,7 @@ before { ENV["GUARD_NOTIFY"] = nil } it "turns on the notifier off" do - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) ::Guard.setup(:notify => false) end end @@ -250,7 +250,7 @@ before { ENV["GUARD_NOTIFY"] = 'true' } it "turns on the notifier on" do - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) ::Guard.setup(:notify => false) end end @@ -259,7 +259,7 @@ before { ENV["GUARD_NOTIFY"] = 'false' } it "turns on the notifier off" do - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) ::Guard.setup(:notify => false) end end @@ -267,22 +267,22 @@ end describe ".setup_listener" do - let(:listener) { stub.as_null_object } + let(:listener) { double.as_null_object } context "with latency option" do - before { ::Guard.stub(:options).and_return("latency" => 1.5) } + before { allow(::Guard).to receive(:options).and_return("latency" => 1.5) } it "pass option to listener" do - Listen.should_receive(:to).with(anything, { :relative_paths => true, :latency => 1.5 }) { listener } + expect(Listen).to receive(:to).with(anything, { :relative_paths => true, :latency => 1.5 }) { listener } ::Guard.setup_listener end end context "with force_polling option" do - before { ::Guard.stub(:options).and_return("force_polling" => true) } + before { allow(::Guard).to receive(:options).and_return("force_polling" => true) } it "pass option to listener" do - Listen.should_receive(:to).with(anything, { :relative_paths => true, :force_polling => true }) { listener } + expect(Listen).to receive(:to).with(anything, { :relative_paths => true, :force_polling => true }) { listener } ::Guard.setup_listener end end @@ -290,7 +290,7 @@ describe ".setup_notifier" do context "with the notify option enabled" do - before { ::Guard.stub(:options).and_return(:notify => true) } + before { allow(::Guard).to receive(:options).and_return(:notify => true) } context 'without the environment variable GUARD_NOTIFY set' do before { ENV["GUARD_NOTIFY"] = nil } @@ -313,7 +313,7 @@ context "with the notify option disabled" do before do - ::Guard.stub(:options).and_return(:notify => false) + allow(::Guard).to receive(:options).and_return(:notify => false) end context 'without the environment variable GUARD_NOTIFY set' do @@ -383,54 +383,54 @@ end describe '#reload' do - let(:runner) { stub(:run => true) } + let(:runner) { double(:run => true) } subject { ::Guard.setup } before do - ::Guard.stub(:runner) { runner } - ::Guard::Dsl.stub(:reevaluate_guardfile) - ::Guard.stub(:within_preserved_state).and_yield - ::Guard::UI.stub(:info) - ::Guard::UI.stub(:clear) + allow(::Guard).to receive(:runner) { runner } + allow(::Guard::Dsl).to receive(:reevaluate_guardfile) + allow(::Guard).to receive(:within_preserved_state).and_yield + allow(::Guard::UI).to receive(:info) + allow(::Guard::UI).to receive(:clear) end it "clear UI" do - ::Guard::UI.should_receive(:clear) + expect(::Guard::UI).to receive(:clear) subject.reload end context 'with a old scope format' do it 'does not re-evaluate the Guardfile' do - ::Guard::Dsl.should_not_receive(:reevaluate_guardfile) + expect(::Guard::Dsl).not_to receive(:reevaluate_guardfile) subject.reload({ :group => :frontend }) end it 'reloads Guard' do - runner.should_receive(:run).with(:reload, { :groups => [:frontend] }) + expect(runner).to receive(:run).with(:reload, { :groups => [:frontend] }) subject.reload({ :group => :frontend }) end end context 'with a new scope format' do it 'does not re-evaluate the Guardfile' do - ::Guard::Dsl.should_not_receive(:reevaluate_guardfile) + expect(::Guard::Dsl).not_to receive(:reevaluate_guardfile) subject.reload({ :groups => [:frontend] }) end it 'reloads Guard' do - runner.should_receive(:run).with(:reload, { :groups => [:frontend] }) + expect(runner).to receive(:run).with(:reload, { :groups => [:frontend] }) subject.reload({ :groups => [:frontend] }) end end context 'with an empty scope' do it 'does re-evaluate the Guardfile' do - ::Guard::Dsl.should_receive(:reevaluate_guardfile) + expect(::Guard::Dsl).to receive(:reevaluate_guardfile) subject.reload end it 'does not reload Guard' do - runner.should_not_receive(:run).with(:reload, { }) + expect(runner).not_to receive(:run).with(:reload, { }) subject.reload end end @@ -465,58 +465,58 @@ class Guard::FooBaz < Guard::Guard; end it "return @guards without any argument" do - subject.guards.should == subject.instance_variable_get("@guards") + expect(subject.guards).to eq(subject.instance_variable_get("@guards")) end context "find a guard by as string/symbol" do it "find a guard by a string" do - subject.guards('foo-bar').should == @guard_foo_bar_backend + expect(subject.guards('foo-bar')).to eq(@guard_foo_bar_backend) end it "find a guard by a symbol" do - subject.guards(:'foo-bar').should == @guard_foo_bar_backend + expect(subject.guards(:'foo-bar')).to eq(@guard_foo_bar_backend) end it "returns nil if guard is not found" do - subject.guards('foo-foo').should be_nil + expect(subject.guards('foo-foo')).to be_nil end end context "find guards matching a regexp" do it "with matches" do - subject.guards(/^foobar/).should == [@guard_foo_bar_backend, @guard_foo_bar_frontend] + expect(subject.guards(/^foobar/)).to eq([@guard_foo_bar_backend, @guard_foo_bar_frontend]) end it "without matches" do - subject.guards(/foo$/).should == [] + expect(subject.guards(/foo$/)).to eq([]) end end context "find guards by their group" do it "group name is a string" do - subject.guards(:group => 'backend').should == [@guard_foo_bar_backend, @guard_foo_baz_backend] + expect(subject.guards(:group => 'backend')).to eq([@guard_foo_bar_backend, @guard_foo_baz_backend]) end it "group name is a symbol" do - subject.guards(:group => :frontend).should == [@guard_foo_bar_frontend, @guard_foo_baz_frontend] + expect(subject.guards(:group => :frontend)).to eq([@guard_foo_bar_frontend, @guard_foo_baz_frontend]) end it "returns [] if guard is not found" do - subject.guards(:group => :unknown).should == [] + expect(subject.guards(:group => :unknown)).to eq([]) end end context "find guards by their group & name" do it "group name is a string" do - subject.guards(:group => 'backend', :name => 'foo-bar').should == [@guard_foo_bar_backend] + expect(subject.guards(:group => 'backend', :name => 'foo-bar')).to eq([@guard_foo_bar_backend]) end it "group name is a symbol" do - subject.guards(:group => :frontend, :name => :'foo-baz').should == [@guard_foo_baz_frontend] + expect(subject.guards(:group => :frontend, :name => :'foo-baz')).to eq([@guard_foo_baz_frontend]) end it "returns [] if guard is not found" do - subject.guards(:group => :unknown, :name => :'foo-baz').should == [] + expect(subject.guards(:group => :unknown, :name => :'foo-baz')).to eq([]) end end end @@ -531,31 +531,31 @@ class Guard::FooBaz < Guard::Guard; context 'without any argument' do it "return all groups" do - subject.groups.should == subject.instance_variable_get("@groups") + expect(subject.groups).to eq(subject.instance_variable_get("@groups")) end end context "find a group by as string/symbol" do it "find a group by a string" do - subject.groups('backend').should == @group_backend + expect(subject.groups('backend')).to eq(@group_backend) end it "find a group by a symbol" do - subject.groups(:backend).should == @group_backend + expect(subject.groups(:backend)).to eq(@group_backend) end it "returns nil if group is not found" do - subject.groups(:foo).should be_nil + expect(subject.groups(:foo)).to be_nil end end context "find groups matching a regexp" do it "with matches" do - subject.groups(/^back/).should == [@group_backend, @group_backflip] + expect(subject.groups(/^back/)).to eq([@group_backend, @group_backflip]) end it "without matches" do - subject.groups(/back$/).should == [] + expect(subject.groups(/back$/)).to eq([]) end end end @@ -571,9 +571,9 @@ class Guard::FooBaz < Guard::Guard; it "initializes a default group" do subject.setup_groups - subject.groups.should have(1).item - subject.groups[0].name.should eq :default - subject.groups[0].options.should == { } + expect(subject.groups.size).to eq(1) + expect(subject.groups[0].name).to eq :default + expect(subject.groups[0].options).to eq({ }) end end @@ -593,43 +593,43 @@ class Guard::FooBar < Guard::Guard; end it "return @guards without any argument" do - subject.guards.should have(1).item + expect(subject.guards.size).to eq(1) subject.setup_guards - subject.guards.should be_empty + expect(subject.guards).to be_empty end end describe ".start" do before do - ::Guard.stub(:setup) - ::Guard.stub(:listener => mock('listener', :start => true)) - ::Guard.stub(:runner => mock('runner', :run => true)) - ::Guard.stub(:within_preserved_state).and_yield + allow(::Guard).to receive(:setup) + allow(::Guard).to receive(:listener).and_return(double('listener', :start => true)) + allow(::Guard).to receive(:runner).and_return(double('runner', :run => true)) + allow(::Guard).to receive(:within_preserved_state).and_yield end it "setup Guard" do - ::Guard.should_receive(:setup).with(:foo => 'bar') + expect(::Guard).to receive(:setup).with(:foo => 'bar') ::Guard.start(:foo => 'bar') end it "displays an info message" do ::Guard.instance_variable_set('@watchdir', '/foo/bar') - ::Guard::UI.should_receive(:info).with("Guard is now watching at '/foo/bar'") + expect(::Guard::UI).to receive(:info).with("Guard is now watching at '/foo/bar'") ::Guard.start end it "tell the runner to run the :start task" do - ::Guard.runner.should_receive(:run).with(:start) + expect(::Guard.runner).to receive(:run).with(:start) ::Guard.start end it "start the listener" do - ::Guard.listener.should_receive(:start) + expect(::Guard.listener).to receive(:start) ::Guard.start end @@ -637,26 +637,26 @@ class Guard::FooBar < Guard::Guard; describe ".stop" do before do - ::Guard.stub(:setup) - ::Guard.stub(:listener => mock('listener', :stop => true)) - ::Guard.stub(:runner => mock('runner', :run => true)) - ::Guard.stub(:within_preserved_state).and_yield + allow(::Guard).to receive(:setup) + allow(::Guard).to receive(:listener).and_return(double('listener', :stop => true)) + allow(::Guard).to receive(:runner).and_return(double('runner', :run => true)) + allow(::Guard).to receive(:within_preserved_state).and_yield end it "turns the notifier off" do - ::Guard::Notifier.should_receive(:turn_off) + expect(::Guard::Notifier).to receive(:turn_off) ::Guard.stop end it "tell the runner to run the :stop task" do - ::Guard.runner.should_receive(:run).with(:stop) + expect(::Guard.runner).to receive(:run).with(:stop) ::Guard.stop end it "stops the listener" do - ::Guard.listener.should_receive(:stop) + expect(::Guard.listener).to receive(:stop) ::Guard.stop end @@ -664,7 +664,7 @@ class Guard::FooBar < Guard::Guard; it "sets the running state to false" do ::Guard.running = true ::Guard.stop - ::Guard.running.should be_false + expect(::Guard.running).to be_falsey end end @@ -673,7 +673,7 @@ class Guard::FooBar < Guard::Guard; @guard_rspec_class = double('Guard::RSpec') @guard_rspec = double('Guard::RSpec', :is_a? => true) - ::Guard.stub!(:get_guard_class) { @guard_rspec_class } + allow(::Guard).to receive(:get_guard_class) { @guard_rspec_class } ::Guard.setup_guards ::Guard.setup_groups @@ -681,28 +681,28 @@ class Guard::FooBar < Guard::Guard; end it "accepts guard name as string" do - @guard_rspec_class.should_receive(:new).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).and_return(@guard_rspec) ::Guard.add_guard('rspec') end it "accepts guard name as symbol" do - @guard_rspec_class.should_receive(:new).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).and_return(@guard_rspec) ::Guard.add_guard(:rspec) end it "adds guard to the @guards array" do - @guard_rspec_class.should_receive(:new).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).and_return(@guard_rspec) ::Guard.add_guard(:rspec) - ::Guard.guards.should eq [@guard_rspec] + expect(::Guard.guards).to eq [@guard_rspec] end context "with no watchers given" do it "gives an empty array of watchers" do - @guard_rspec_class.should_receive(:new).with([], { }).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).with([], { }).and_return(@guard_rspec) ::Guard.add_guard(:rspec, []) end @@ -710,7 +710,7 @@ class Guard::FooBar < Guard::Guard; context "with watchers given" do it "give the watchers array" do - @guard_rspec_class.should_receive(:new).with([:foo], { }).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).with([:foo], { }).and_return(@guard_rspec) ::Guard.add_guard(:rspec, [:foo]) end @@ -718,7 +718,7 @@ class Guard::FooBar < Guard::Guard; context "with no options given" do it "gives an empty hash of options" do - @guard_rspec_class.should_receive(:new).with([], { }).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).with([], { }).and_return(@guard_rspec) ::Guard.add_guard(:rspec, [], [], { }) end @@ -726,7 +726,7 @@ class Guard::FooBar < Guard::Guard; context "with options given" do it "give the options hash" do - @guard_rspec_class.should_receive(:new).with([], { :foo => true, :group => :backend }).and_return(@guard_rspec) + expect(@guard_rspec_class).to receive(:new).with([], { :foo => true, :group => :backend }).and_return(@guard_rspec) ::Guard.add_guard(:rspec, [], [], { :foo => true, :group => :backend }) end @@ -739,51 +739,51 @@ class Guard::FooBar < Guard::Guard; it "accepts group name as string" do ::Guard.add_group('backend') - ::Guard.groups[0].name.should == :default - ::Guard.groups[1].name.should == :backend + expect(::Guard.groups[0].name).to eq(:default) + expect(::Guard.groups[1].name).to eq(:backend) end it "accepts group name as symbol" do ::Guard.add_group(:backend) - ::Guard.groups[0].name.should == :default - ::Guard.groups[1].name.should == :backend + expect(::Guard.groups[0].name).to eq(:default) + expect(::Guard.groups[1].name).to eq(:backend) end it "accepts options" do ::Guard.add_group(:backend, { :halt_on_fail => true }) - ::Guard.groups[0].options.should eq({ }) - ::Guard.groups[1].options.should eq({ :halt_on_fail => true }) + expect(::Guard.groups[0].options).to eq({ }) + expect(::Guard.groups[1].options).to eq({ :halt_on_fail => true }) end end describe '.within_preserved_state' do subject { ::Guard.setup } - before { subject.interactor = stub('interactor').as_null_object } + before { subject.interactor = double('interactor').as_null_object } it 'disallows running the block concurrently to avoid inconsistent states' do - subject.lock.should_receive(:synchronize) + expect(subject.lock).to receive(:synchronize) subject.within_preserved_state &Proc.new { } end it 'runs the passed block' do @called = false subject.within_preserved_state { @called = true } - @called.should be_true + expect(@called).to be_truthy end context 'with restart interactor enabled' do it 'stops the interactor before running the block and starts it again when done' do - subject.interactor.should_receive(:stop) - subject.interactor.should_receive(:start) + expect(subject.interactor).to receive(:stop) + expect(subject.interactor).to receive(:start) subject.within_preserved_state &Proc.new { } end end context 'without restart interactor enabled' do it 'stops the interactor before running the block' do - subject.interactor.should_receive(:stop) + expect(subject.interactor).to receive(:stop) subject.interactor.should__not_receive(:start) subject.within_preserved_state &Proc.new { } end @@ -798,7 +798,7 @@ class Guard::FooBar < Guard::Guard; end it "reports an error if the class is not found" do - ::Guard::UI.should_receive(:error).twice + expect(::Guard::UI).to receive(:error).twice Guard.get_guard_class('notAGuardClass') end @@ -806,21 +806,21 @@ class Guard::FooBar < Guard::Guard; after(:all) { Guard.instance_eval { remove_const(:Classname) } rescue nil } it "resolves the Guard class from string" do - Guard.should_receive(:require) { |classname| - classname.should eq 'guard/classname' + expect(Guard).to receive(:require) { |classname| + expect(classname).to eq 'guard/classname' class Guard::Classname; end } - Guard.get_guard_class('classname').should == Guard::Classname + expect(Guard.get_guard_class('classname')).to eq(Guard::Classname) end it "resolves the Guard class from symbol" do - Guard.should_receive(:require) { |classname| - classname.should eq 'guard/classname' + expect(Guard).to receive(:require) { |classname| + expect(classname).to eq 'guard/classname' class Guard::Classname; end } - Guard.get_guard_class(:classname).should == Guard::Classname + expect(Guard.get_guard_class(:classname)).to eq(Guard::Classname) end end @@ -828,12 +828,12 @@ class Guard::Classname; after(:all) { Guard.instance_eval { remove_const(:DashedClassName) } rescue nil } it "returns the Guard class" do - Guard.should_receive(:require) { |classname| - classname.should eq 'guard/dashed-class-name' + expect(Guard).to receive(:require) { |classname| + expect(classname).to eq 'guard/dashed-class-name' class Guard::DashedClassName; end } - Guard.get_guard_class('dashed-class-name').should == Guard::DashedClassName + expect(Guard.get_guard_class('dashed-class-name')).to eq(Guard::DashedClassName) end end @@ -841,12 +841,12 @@ class Guard::DashedClassName; after(:all) { Guard.instance_eval { remove_const(:UnderscoreClassName) } rescue nil } it "returns the Guard class" do - Guard.should_receive(:require) { |classname| - classname.should eq 'guard/underscore_class_name' + expect(Guard).to receive(:require) { |classname| + expect(classname).to eq 'guard/underscore_class_name' class Guard::UnderscoreClassName; end } - Guard.get_guard_class('underscore_class_name').should == Guard::UnderscoreClassName + expect(Guard.get_guard_class('underscore_class_name')).to eq(Guard::UnderscoreClassName) end end @@ -854,12 +854,12 @@ class Guard::UnderscoreClassName; after(:all) { Guard.instance_eval { remove_const(:VSpec) } rescue nil } it "returns the Guard class" do - Guard.should_receive(:require) { |classname| - classname.should eq 'guard/vspec' + expect(Guard).to receive(:require) { |classname| + expect(classname).to eq 'guard/vspec' class Guard::VSpec; end } - Guard.get_guard_class('vspec').should == Guard::VSpec + expect(Guard.get_guard_class('vspec')).to eq(Guard::VSpec) end end @@ -872,15 +872,15 @@ class Inline < Guard end end - Guard.should_not_receive(:require) - Guard.get_guard_class('inline').should == Guard::Inline + expect(Guard).not_to receive(:require) + expect(Guard.get_guard_class('inline')).to eq(Guard::Inline) end end context 'when set to fail gracefully' do it 'does not print error messages on fail' do - ::Guard::UI.should_not_receive(:error) - Guard.get_guard_class('notAGuardClass', true).should be_nil + expect(::Guard::UI).not_to receive(:error) + expect(Guard.get_guard_class('notAGuardClass', true)).to be_nil end end end @@ -891,30 +891,30 @@ class Inline < Guard describe '.locate_guard' do context 'Rubygems < 1.8.0' do before do - Gem::Version.should_receive(:create).with(Gem::VERSION) { rubygems_version_1_7_2 } - Gem::Version.should_receive(:create).with('1.8.0') { rubygems_version_1_8_0 } + expect(Gem::Version).to receive(:create).with(Gem::VERSION) { rubygems_version_1_7_2 } + expect(Gem::Version).to receive(:create).with('1.8.0') { rubygems_version_1_8_0 } end it "returns the path of a Guard gem" do - gems_source_index = stub - gems_found = [stub(:full_gem_path => 'gems/guard-rspec')] - Gem.should_receive(:source_index) { gems_source_index } - gems_source_index.should_receive(:find_name).with('guard-rspec') { gems_found } + gems_source_index = double + gems_found = [double(:full_gem_path => 'gems/guard-rspec')] + expect(Gem).to receive(:source_index) { gems_source_index } + expect(gems_source_index).to receive(:find_name).with('guard-rspec') { gems_found } - Guard.locate_guard('rspec').should eq 'gems/guard-rspec' + expect(Guard.locate_guard('rspec')).to eq 'gems/guard-rspec' end end context 'Rubygems >= 1.8.0' do before do - Gem::Version.should_receive(:create).with(Gem::VERSION) { rubygems_version_1_8_0 } - Gem::Version.should_receive(:create).with('1.8.0') { rubygems_version_1_8_0 } + expect(Gem::Version).to receive(:create).with(Gem::VERSION) { rubygems_version_1_8_0 } + expect(Gem::Version).to receive(:create).with('1.8.0') { rubygems_version_1_8_0 } end it "returns the path of a Guard gem" do - Gem::Specification.should_receive(:find_by_name).with('guard-rspec') { stub(:full_gem_path => 'gems/guard-rspec') } + expect(Gem::Specification).to receive(:find_by_name).with('guard-rspec') { double(:full_gem_path => 'gems/guard-rspec') } - Guard.locate_guard('rspec').should eq 'gems/guard-rspec' + expect(Guard.locate_guard('rspec')).to eq 'gems/guard-rspec' end end end @@ -922,41 +922,41 @@ class Inline < Guard describe '.guard_gem_names' do context 'Rubygems < 1.8.0' do before do - Gem::Version.should_receive(:create).with(Gem::VERSION) { rubygems_version_1_7_2 } - Gem::Version.should_receive(:create).with('1.8.0') { rubygems_version_1_8_0 } - gems_source_index = stub - Gem.should_receive(:source_index) { gems_source_index } - gems_source_index.should_receive(:find_name).with(/^guard-/) { [stub(:name => 'guard-rspec')] } + expect(Gem::Version).to receive(:create).with(Gem::VERSION) { rubygems_version_1_7_2 } + expect(Gem::Version).to receive(:create).with('1.8.0') { rubygems_version_1_8_0 } + gems_source_index = double + expect(Gem).to receive(:source_index) { gems_source_index } + expect(gems_source_index).to receive(:find_name).with(/^guard-/) { [double(:name => 'guard-rspec')] } end it 'returns the list of guard gems' do - Guard.guard_gem_names.should include('rspec') + expect(Guard.guard_gem_names).to include('rspec') end end context 'Rubygems >= 1.8.0' do before do - Gem::Version.should_receive(:create).with(Gem::VERSION) { rubygems_version_1_8_0 } - Gem::Version.should_receive(:create).with('1.8.0') { rubygems_version_1_8_0 } + expect(Gem::Version).to receive(:create).with(Gem::VERSION) { rubygems_version_1_8_0 } + expect(Gem::Version).to receive(:create).with('1.8.0') { rubygems_version_1_8_0 } gems = [ - stub(:name => 'guard'), - stub(:name => 'guard-rspec'), - stub(:name => 'gem1', :full_gem_path => '/gem1'), - stub(:name => 'gem2', :full_gem_path => '/gem2'), + double(:name => 'guard'), + double(:name => 'guard-rspec'), + double(:name => 'gem1', :full_gem_path => '/gem1'), + double(:name => 'gem2', :full_gem_path => '/gem2'), ] - File.stub(:exists?).with('/gem1/lib/guard/gem1.rb') { false } - File.stub(:exists?).with('/gem2/lib/guard/gem2.rb') { true } - Gem::Specification.should_receive(:find_all) { gems } + allow(File).to receive(:exists?).with('/gem1/lib/guard/gem1.rb') { false } + allow(File).to receive(:exists?).with('/gem2/lib/guard/gem2.rb') { true } + expect(Gem::Specification).to receive(:find_all) { gems } end it "returns the list of guard gems" do gems = Guard.guard_gem_names - gems.should include('rspec') + expect(gems).to include('rspec') end it "returns the list of embedded guard gems" do gems = Guard.guard_gem_names - gems.should include('gem2') + expect(gems).to include('gem2') end end end @@ -965,7 +965,7 @@ class Inline < Guard subject { ::Guard.setup } before do - Guard.unstub(:debug_command_execution) + allow(Guard).to receive(:debug_command_execution).and_call_original @original_system = Kernel.method(:system) @original_command = Kernel.method(:"`") end @@ -974,25 +974,25 @@ class Inline < Guard Kernel.send(:remove_method, :system, :'`') Kernel.send(:define_method, :system, @original_system.to_proc) Kernel.send(:define_method, :"`", @original_command.to_proc) - Guard.stub(:debug_command_execution) + allow(Guard).to receive(:debug_command_execution) end it "outputs Kernel.#system method parameters" do - ::Guard::UI.should_receive(:debug).with("Command execution: exit 0") + expect(::Guard::UI).to receive(:debug).with("Command execution: exit 0") ::Guard.setup(:debug => true) - system("exit", "0").should be_false + expect(system("exit", "0")).to be_falsey end it "outputs Kernel.#` method parameters" do - ::Guard::UI.should_receive(:debug).with("Command execution: echo test") + expect(::Guard::UI).to receive(:debug).with("Command execution: echo test") ::Guard.setup(:debug => true) - `echo test`.should == "test\n" + expect(`echo test`).to eq("test\n") end it "outputs %x{} method parameters" do - ::Guard::UI.should_receive(:debug).with("Command execution: echo test") + expect(::Guard::UI).to receive(:debug).with("Command execution: echo test") ::Guard.setup(:debug => true) - %x{echo test}.should == "test\n" + expect(%x{echo test}).to eq("test\n") end end @@ -1004,7 +1004,7 @@ class Inline < Guard before { subject.options[:watch_all_modifications] = true } it 'displays a deprecation warning to the user' do - ::Guard::UI.should_receive(:deprecation) + expect(::Guard::UI).to receive(:deprecation) subject.deprecated_options_warning end end @@ -1013,7 +1013,7 @@ class Inline < Guard before { subject.options[:no_vendor] = true } it 'displays a deprecation warning to the user' do - ::Guard::UI.should_receive(:deprecation) + expect(::Guard::UI).to receive(:deprecation) subject.deprecated_options_warning end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0bfe74f4..13f7317cc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ puts "Please do not update/create files while tests are running." RSpec.configure do |config| - config.color_enabled = true + config.color = true config.order = :random config.filter_run :focus => true config.treat_symbols_as_metadata_keys_with_true_values = true @@ -24,14 +24,14 @@ @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__)) # Ensure debug command execution isn't used in the specs - Guard.stub(:debug_command_execution) + allow(Guard).to receive(:debug_command_execution) # Stub all UI methods, so no visible output appears for the UI class - ::Guard::UI.stub(:info) - ::Guard::UI.stub(:warning) - ::Guard::UI.stub(:error) - ::Guard::UI.stub(:debug) - ::Guard::UI.stub(:deprecation) + allow(::Guard::UI).to receive(:info) + allow(::Guard::UI).to receive(:warning) + allow(::Guard::UI).to receive(:error) + allow(::Guard::UI).to receive(:debug) + allow(::Guard::UI).to receive(:deprecation) end config.before(:all) do diff --git a/spec/support/guard_helper.rb b/spec/support/guard_helper.rb index b5393dcb7..5cbb072ff 100644 --- a/spec/support/guard_helper.rb +++ b/spec/support/guard_helper.rb @@ -1,27 +1,27 @@ shared_examples_for 'interactor enabled' do it 'enables the interactor' do - described_class::Interactor.should_receive(:new) + expect(described_class::Interactor).to receive(:new) described_class.setup_interactor end end shared_examples_for 'interactor disabled' do it 'disables the interactor' do - described_class::Interactor.should_not_receive(:new) + expect(described_class::Interactor).not_to receive(:new) described_class.setup_interactor end end shared_examples_for 'notifier enabled' do it 'enables the notifier' do - described_class::Notifier.should_receive(:turn_on) + expect(described_class::Notifier).to receive(:turn_on) described_class.setup_notifier end end shared_examples_for 'notifier disabled' do it 'disables the notifier' do - described_class::Notifier.should_receive(:turn_off) + expect(described_class::Notifier).to receive(:turn_off) described_class.setup_notifier end end