From 15990d9e25cb42f4934a3b316339cd955eb2f23a Mon Sep 17 00:00:00 2001 From: Cezary Baginski Date: Sat, 6 Dec 2014 21:51:59 +0100 Subject: [PATCH] Convert specs to RSpec 2.99.2 syntax with Transpec This conversion is done by Transpec 2.3.8 with the following command: transpec * 103 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 24 conversions from: obj.should to: expect(obj).to * 23 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) * 7 conversions from: obj.should_not_receive(:message) to: expect(obj).not_to receive(:message) * 6 conversions from: be_false to: be_falsey * 6 conversions from: be_true to: be_truthy * 5 conversions from: == expected to: eq(expected) * 5 conversions from: obj.unstub(:message) to: allow(obj).to receive(:message).and_call_original * 1 conversion from: obj.should have(n).watchers to: expect(obj.watchers.size).to eq(n) For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/guard/coffeescript/formatter_spec.rb | 10 +- spec/guard/coffeescript/inspector_spec.rb | 36 ++-- spec/guard/coffeescript/runner_spec.rb | 206 +++++++++++----------- spec/guard/coffeescript/version_spec.rb | 2 +- spec/guard/coffeescript_spec.rb | 66 +++---- spec/spec_helper.rb | 12 +- 6 files changed, 166 insertions(+), 166 deletions(-) diff --git a/spec/guard/coffeescript/formatter_spec.rb b/spec/guard/coffeescript/formatter_spec.rb index cb23374..9110e58 100644 --- a/spec/guard/coffeescript/formatter_spec.rb +++ b/spec/guard/coffeescript/formatter_spec.rb @@ -8,21 +8,21 @@ describe '.info' do it 'shows an info message' do - ui.should_receive(:info).with('Info message', { :reset => true }) + expect(ui).to receive(:info).with('Info message', { :reset => true }) formatter.info('Info message', { :reset => true }) end end describe '.debug' do it 'shows a debug message' do - ui.should_receive(:debug).with('Debug message', { :reset => true }) + expect(ui).to receive(:debug).with('Debug message', { :reset => true }) formatter.debug('Debug message', { :reset => true }) end end describe '.error' do it 'shows a colorized error message' do - ui.should_receive(:error).with("\e[0;31mError message\e[0m", { :reset => true }) + expect(ui).to receive(:error).with("\e[0;31mError message\e[0m", { :reset => true }) formatter.error('Error message', { :reset => true }) end end @@ -30,14 +30,14 @@ describe '.success' do it 'shows a colorized success message with a timestamp' do expected_success_message = %r{^\e\[0;32m\d{2}:\d{2}:\d{2} (AM|PM) Success message\e\[0m$} - ui.should_receive(:info).with(expected_success_message, { :reset => true }) + expect(ui).to receive(:info).with(expected_success_message, { :reset => true }) formatter.success('Success message', { :reset => true }) end end describe '.notify' do it 'shows an info message' do - notifier.should_receive(:notify).with('Notify message', { :image => :failed }) + expect(notifier).to receive(:notify).with('Notify message', { :image => :failed }) formatter.notify('Notify message', { :image => :failed }) end end diff --git a/spec/guard/coffeescript/inspector_spec.rb b/spec/guard/coffeescript/inspector_spec.rb index e097966..411cbd5 100644 --- a/spec/guard/coffeescript/inspector_spec.rb +++ b/spec/guard/coffeescript/inspector_spec.rb @@ -5,36 +5,36 @@ describe 'clean' do it 'removes duplicate files' do - File.should_receive(:exists?).with("a.coffee").and_return true - File.should_receive(:exists?).with("b.coffee.md").and_return true - File.should_receive(:exists?).with("c.litcoffee").and_return true - inspector.clean(['a.coffee', 'a.coffee', 'b.coffee.md', 'b.coffee.md', 'c.litcoffee', 'c.litcoffee']) - .should == ['a.coffee', 'b.coffee.md', 'c.litcoffee'] + expect(File).to receive(:exists?).with("a.coffee").and_return true + expect(File).to receive(:exists?).with("b.coffee.md").and_return true + expect(File).to receive(:exists?).with("c.litcoffee").and_return true + expect(inspector.clean(['a.coffee', 'a.coffee', 'b.coffee.md', 'b.coffee.md', 'c.litcoffee', 'c.litcoffee'])) + .to eq(['a.coffee', 'b.coffee.md', 'c.litcoffee']) end it 'remove nil files' do - File.should_receive(:exists?).with("a.coffee").and_return true - File.should_receive(:exists?).with("b.coffee.md").and_return true - File.should_receive(:exists?).with("c.litcoffee").and_return true - inspector.clean(['a.coffee', 'b.coffee.md', 'c.litcoffee', nil]) - .should == ['a.coffee', 'b.coffee.md', 'c.litcoffee'] + expect(File).to receive(:exists?).with("a.coffee").and_return true + expect(File).to receive(:exists?).with("b.coffee.md").and_return true + expect(File).to receive(:exists?).with("c.litcoffee").and_return true + expect(inspector.clean(['a.coffee', 'b.coffee.md', 'c.litcoffee', nil])) + .to eq(['a.coffee', 'b.coffee.md', 'c.litcoffee']) end describe 'without the :missing_ok option' do it 'removes non-coffee files that do not exist' do - File.should_receive(:exists?).with("a.coffee").and_return true - File.should_receive(:exists?).with("c.litcoffee").and_return true - File.should_receive(:exists?).with("d.coffee.md").and_return true - File.should_receive(:exists?).with("doesntexist.coffee").and_return false - inspector.clean(['a.coffee', 'b.txt', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md']) - .should == ['a.coffee', 'c.litcoffee', 'd.coffee.md'] + expect(File).to receive(:exists?).with("a.coffee").and_return true + expect(File).to receive(:exists?).with("c.litcoffee").and_return true + expect(File).to receive(:exists?).with("d.coffee.md").and_return true + expect(File).to receive(:exists?).with("doesntexist.coffee").and_return false + expect(inspector.clean(['a.coffee', 'b.txt', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md'])) + .to eq(['a.coffee', 'c.litcoffee', 'd.coffee.md']) end end describe 'with the :missing_ok options' do it 'removes non-coffee files' do - inspector.clean(['a.coffee', 'b.txt', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md'], { :missing_ok => true }) - .should == ['a.coffee', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md'] + expect(inspector.clean(['a.coffee', 'b.txt', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md'], { :missing_ok => true })) + .to eq(['a.coffee', 'doesntexist.coffee', 'c.litcoffee', 'd.coffee.md']) end end diff --git a/spec/guard/coffeescript/runner_spec.rb b/spec/guard/coffeescript/runner_spec.rb index 5d90a54..3cd258c 100644 --- a/spec/guard/coffeescript/runner_spec.rb +++ b/spec/guard/coffeescript/runner_spec.rb @@ -6,27 +6,27 @@ let(:formatter) { Guard::CoffeeScript::Formatter } before do - runner.stub(:compile).and_return '' - formatter.stub(:notify) + allow(runner).to receive(:compile).and_return '' + allow(formatter).to receive(:notify) - FileUtils.stub(:mkdir_p) - FileUtils.stub(:remove_file) - File.stub(:open) + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:remove_file) + allow(File).to receive(:open) end describe '#run' do context 'without the :noop option' do it 'shows a start notification' do - formatter.should_receive(:info).once.with('Compile a.coffee, b.coffee.md, c.litcoffee', { :reset => true }) - formatter.should_receive(:success).once.with('Successfully generated ') + expect(formatter).to receive(:info).once.with('Compile a.coffee, b.coffee.md, c.litcoffee', { :reset => true }) + expect(formatter).to receive(:success).once.with('Successfully generated ') runner.run(['a.coffee', 'b.coffee.md', 'c.litcoffee'], []) end end context 'with the :noop option' do it 'shows a start notification' do - formatter.should_receive(:info).once.with('Verify a.coffee, b.coffee.md, c.litcoffee', { :reset => true }) - formatter.should_receive(:success).once.with('Successfully verified ') + expect(formatter).to receive(:info).once.with('Verify a.coffee, b.coffee.md, c.litcoffee', { :reset => true }) + expect(formatter).to receive(:success).once.with('Successfully verified ') runner.run(['a.coffee', 'b.coffee.md', 'c.litcoffee'], [], { :noop => true }) end end @@ -36,64 +36,64 @@ context 'without the :noop option' do it 'compiles the CoffeeScripts to the output and replace .{coffee,coffee.md,litcoffee} with .js' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/target") - File.should_receive(:open).with("#{ @project_path }/target/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/target/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/target/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/target") + expect(File).to receive(:open).with("#{ @project_path }/target/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/target/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/target/c.js", 'w') runner.run(['src/a.coffee', 'src/b.coffee.md', 'src/c.litcoffee'], [watcher], { :output => 'target' }) end it 'compiles the CoffeeScripts to the output and replace .js.{coffee,coffee.md,litcoffee} with .js' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/target") - File.should_receive(:open).with("#{ @project_path }/target/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/target/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/target/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/target") + expect(File).to receive(:open).with("#{ @project_path }/target/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/target/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/target/c.js", 'w') runner.run(['src/a.js.coffee', 'src/b.js.coffee.md', 'src/c.litcoffee'], [watcher], { :output => 'target' }) end end context 'without the :output option' do it 'compiles the CoffeeScripts to the same dir like the file and replace .{coffee,coffee.md,litcoffee} with .js' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/src") - File.should_receive(:open).with("#{ @project_path }/src/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/src/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/src/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/src") + expect(File).to receive(:open).with("#{ @project_path }/src/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/c.js", 'w') runner.run(['src/a.coffee', 'src/b.coffee.md', 'src/c.litcoffee'], [watcher]) end it 'compiles the CoffeeScripts to the same dir like the file and replace .js.{coffee,coffee.md,litcoffee} with .js' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/src") - File.should_receive(:open).with("#{ @project_path }/src/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/src/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/src/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/src") + expect(File).to receive(:open).with("#{ @project_path }/src/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/c.js", 'w') runner.run(['src/a.js.coffee', 'src/b.js.coffee.md', 'src/c.js.litcoffee'], [watcher]) end end context 'with the :noop option' do it 'does not write the output file' do - FileUtils.should_not_receive(:mkdir_p).with("#{ @project_path }/target") - File.should_not_receive(:open).with("#{ @project_path }/target/a.js", 'w') - File.should_not_receive(:open).with("#{ @project_path }/target/b.js", 'w') - File.should_not_receive(:open).with("#{ @project_path }/target/c.js", 'w') + expect(FileUtils).not_to receive(:mkdir_p).with("#{ @project_path }/target") + expect(File).not_to receive(:open).with("#{ @project_path }/target/a.js", 'w') + expect(File).not_to receive(:open).with("#{ @project_path }/target/b.js", 'w') + expect(File).not_to receive(:open).with("#{ @project_path }/target/c.js", 'w') runner.run(['src/a.js.coffee', 'src/b.js.coffee.md', 'src/c.js.litcoffee'], [watcher], { :output => 'target', :noop => true }) end end context 'with the :source_map option' do it 'compiles the source map to the same dir like the file and replace .{coffee,coffee.md,litcoffee} with .js.map' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/src") - File.should_receive(:open).with("#{ @project_path }/src/a.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/src/b.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/src/c.js.map", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/src") + expect(File).to receive(:open).with("#{ @project_path }/src/a.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/b.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/c.js.map", 'w') runner.run(['src/a.coffee', 'src/b.coffee.md', 'src/c.litcoffee'], [watcher], :source_map => true) end it 'compiles the source map to the same dir like the file and replace .js.{coffee,coffee.md,litcoffee} with .js.map' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/src") - File.should_receive(:open).with("#{ @project_path }/src/a.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/src/b.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/src/c.js.map", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/src") + expect(File).to receive(:open).with("#{ @project_path }/src/a.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/b.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/src/c.js.map", 'w') runner.run(['src/a.js.coffee', 'src/b.js.coffee.md', 'src/c.js.litcoffee'], [watcher], :source_map => true) end @@ -104,19 +104,19 @@ let(:watcher) { Guard::Watcher.new(%r{src/.+\.(?:coffee|coffee\.md|litcoffee)$}) } before do - runner.unstub(:compile) - ::CoffeeScript.stub(:compile) - File.should_receive(:read).with('src/a.coffee').and_return 'a = -> 1' - File.should_receive(:read).with('src/b.coffee').and_return 'b = -> 2' + allow(runner).to receive(:compile).and_call_original + allow(::CoffeeScript).to receive(:compile) + expect(File).to receive(:read).with('src/a.coffee').and_return 'a = -> 1' + expect(File).to receive(:read).with('src/b.coffee').and_return 'b = -> 2' end it 'should compile files in the list without the outer function wrapper' do - ::CoffeeScript.should_receive(:compile).with 'a = -> 1', hash_including(:bare => true) + expect(::CoffeeScript).to receive(:compile).with 'a = -> 1', hash_including(:bare => true) runner.run(['src/a.coffee', 'src/b.coffee'], [watcher], { :output => 'target', :bare => ['a.coffee'] }) end it 'should compile files not in the list with the outer function wrapper' do - ::CoffeeScript.should_receive(:compile).with 'b = -> 2', hash_including(:bare => false) + expect(::CoffeeScript).to receive(:compile).with 'b = -> 2', hash_including(:bare => false) runner.run(['src/a.coffee', 'src/b.coffee'], [watcher], { :output => 'target', :bare => ['a.coffee'] }) end end @@ -125,20 +125,20 @@ let(:watcher) { Guard::Watcher.new('^app/coffeescripts/(.+)\.(?:coffee|coffee\.md|litcoffee)$') } it 'compiles the CoffeeScripts to the output and creates nested directories' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y") - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y") + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/c.js", 'w') runner.run(['app/coffeescripts/x/y/a.coffee', 'app/coffeescripts/x/y/b.coffee.md', 'app/coffeescripts/x/y/c.litcoffee'], [watcher], { :output => 'javascripts', :shallow => false }) end context 'with the :source_map option' do it 'generates the source map to the output and creates nested directories' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y") - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/a.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/b.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/x/y/c.js.map", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/javascripts/x/y") + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/a.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/b.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/x/y/c.js.map", 'w') runner.run(['app/coffeescripts/x/y/a.coffee', 'app/coffeescripts/x/y/b.coffee.md', 'app/coffeescripts/x/y/c.litcoffee'], [watcher], { :output => 'javascripts', :shallow => false, :source_map => true }) end @@ -149,20 +149,20 @@ let(:watcher) { Guard::Watcher.new('^app/coffeescripts/(.+)\.(?:coffee|coffee\.md|litcoffee)$') } it 'compiles the CoffeeScripts to the output without creating nested directories' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts") - File.should_receive(:open).with("#{ @project_path }/javascripts/a.js", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/b.js", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/c.js", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/javascripts") + expect(File).to receive(:open).with("#{ @project_path }/javascripts/a.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/b.js", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/c.js", 'w') runner.run(['app/coffeescripts/x/y/a.coffee', 'app/coffeescripts/x/y/b.coffee.md', 'app/coffeescripts/x/y/c.litcoffee'], [watcher], { :output => 'javascripts', :shallow => true }) end context 'with the :source_map option' do it 'generates the source map to the output without creating nested directories' do - FileUtils.should_receive(:mkdir_p).with("#{ @project_path }/javascripts") - File.should_receive(:open).with("#{ @project_path }/javascripts/a.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/b.js.map", 'w') - File.should_receive(:open).with("#{ @project_path }/javascripts/c.js.map", 'w') + expect(FileUtils).to receive(:mkdir_p).with("#{ @project_path }/javascripts") + expect(File).to receive(:open).with("#{ @project_path }/javascripts/a.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/b.js.map", 'w') + expect(File).to receive(:open).with("#{ @project_path }/javascripts/c.js.map", 'w') runner.run(['app/coffeescripts/x/y/a.coffee', 'app/coffeescripts/x/y/b.coffee.md', 'app/coffeescripts/x/y/c.litcoffee'], [watcher], { :output => 'javascripts', :shallow => true, :source_map => true }) end @@ -171,18 +171,18 @@ context 'with the :source_map option' do before do - runner.unstub(:compile) - ::CoffeeScript.stub(:compile) - File.stub(:read) { |file| file } + allow(runner).to receive(:compile).and_call_original + allow(::CoffeeScript).to receive(:compile) + allow(File).to receive(:read) { |file| file } end after do - runner.stub(:compile).and_return '' - ::CoffeeScript.unstub(:compile) + allow(runner).to receive(:compile).and_return '' + allow(::CoffeeScript).to receive(:compile).and_call_original end it 'compiles with source map file options set' do - ::CoffeeScript.should_receive(:compile).with 'src/a.coffee', hash_including({ + expect(::CoffeeScript).to receive(:compile).with 'src/a.coffee', hash_including({ :sourceMap => true, :generatedFile => 'a.js', :sourceFiles => ['a.coffee'], @@ -192,27 +192,27 @@ end it 'accepts a different source_root' do - ::CoffeeScript.should_receive(:compile).with 'src/a.coffee', hash_including(:sourceRoot => 'foo') + expect(::CoffeeScript).to receive(:compile).with 'src/a.coffee', hash_including(:sourceRoot => 'foo') runner.run(['src/a.coffee'], [watcher], { :output => 'target', :source_map => true, :source_root => 'foo' }) end end context 'with literate coffeescript' do before do - runner.unstub(:compile) - ::CoffeeScript.stub(:compile) - File.stub(:read) { |file| file } + allow(runner).to receive(:compile).and_call_original + allow(::CoffeeScript).to receive(:compile) + allow(File).to receive(:read) { |file| file } end after do - runner.stub(:compile).and_return '' - ::CoffeeScript.unstub(:compile) + allow(runner).to receive(:compile).and_return '' + allow(::CoffeeScript).to receive(:compile).and_call_original end it 'compiles with the :literate option set' do - ::CoffeeScript.should_receive(:compile).with 'a.coffee', hash_not_including(:literate => true) - ::CoffeeScript.should_receive(:compile).with 'b.coffee.md', hash_including(:literate => true) - ::CoffeeScript.should_receive(:compile).with 'c.litcoffee', hash_including(:literate => true) + expect(::CoffeeScript).to receive(:compile).with 'a.coffee', hash_not_including(:literate => true) + expect(::CoffeeScript).to receive(:compile).with 'b.coffee.md', hash_including(:literate => true) + expect(::CoffeeScript).to receive(:compile).with 'c.litcoffee', hash_including(:literate => true) runner.run(['a.coffee', 'b.coffee.md', 'c.litcoffee'], [watcher], { :output => 'javascripts' }) end end @@ -220,9 +220,9 @@ context 'with compilation errors' do context 'without the :noop option' do it 'shows the error messages' do - runner.should_receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:notify).with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", + expect(runner).to receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:notify).with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", :title => 'CoffeeScript results', :image => :failed, :priority => 2) @@ -232,9 +232,9 @@ context 'with the :noop option' do it 'shows the error messages' do - runner.should_receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:notify).with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", + expect(runner).to receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:error).once.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:notify).with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", :title => 'CoffeeScript results', :image => :failed, :priority => 2) @@ -244,8 +244,8 @@ context 'with the :error_to_js option' do it 'write the error message as javascript file' do - runner.should_receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") - runner.should_receive(:write_javascript_file).once.with("throw \"a.coffee: Parse error on line 2: Unexpected 'UNARY'\";", nil, 'a.coffee', 'javascripts', kind_of(Hash)) + expect(runner).to receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") + expect(runner).to receive(:write_javascript_file).once.with("throw \"a.coffee: Parse error on line 2: Unexpected 'UNARY'\";", nil, 'a.coffee', 'javascripts', kind_of(Hash)) runner.run(['a.coffee'], [watcher], { :output => 'javascripts', :error_to_js => true }) end @@ -255,8 +255,8 @@ context 'without compilation errors' do context 'without the :noop option' do it 'shows a success messages' do - formatter.should_receive(:success).once.with('Successfully generated javascripts/a.js') - formatter.should_receive(:notify).with('Successfully generated javascripts/a.js', + expect(formatter).to receive(:success).once.with('Successfully generated javascripts/a.js') + expect(formatter).to receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results') runner.run(['a.coffee'], [watcher], { :output => 'javascripts' }) end @@ -264,8 +264,8 @@ context 'with the :noop option' do it 'shows a success messages' do - formatter.should_receive(:success).once.with('Successfully verified javascripts/a.js') - formatter.should_receive(:notify).with('Successfully verified javascripts/a.js', + expect(formatter).to receive(:success).once.with('Successfully verified javascripts/a.js') + expect(formatter).to receive(:notify).with('Successfully verified javascripts/a.js', :title => 'CoffeeScript results') runner.run(['a.coffee'], [watcher], { :output => 'javascripts', :noop => true }) @@ -276,8 +276,8 @@ let(:watcher) { Guard::Watcher.new('^app/coffeescripts/.+\.(?:coffee|coffee\.md|litcoffee)$') } it 'does not show the success message' do - formatter.should_not_receive(:success).with('Successfully generated javascripts/a.js') - formatter.should_not_receive(:notify).with('Successfully generated javascripts/a.js', + expect(formatter).not_to receive(:success).with('Successfully generated javascripts/a.js') + expect(formatter).not_to receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results') runner.run(['app/coffeescripts/x/y/a.coffee'], [watcher], { :output => 'javascripts', :hide_success => true }) @@ -287,9 +287,9 @@ context 'with :hide_success over multiple runs' do it 'shows the failure message every time' do - runner.should_receive(:compile).twice.and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:error).twice.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") - formatter.should_receive(:notify).twice.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", + expect(runner).to receive(:compile).twice.and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:error).twice.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'") + expect(formatter).to receive(:notify).twice.with("a.coffee: Parse error on line 2: Unexpected 'UNARY'", :title => 'CoffeeScript results', :image => :failed, :priority => 2) @@ -298,13 +298,13 @@ end it 'shows the success message only when previous attempt was failure' do - runner.should_receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") + expect(runner).to receive(:compile).and_raise ::CoffeeScript::CompilationError.new("Parse error on line 2: Unexpected 'UNARY'") runner.run(['a.coffee'], [watcher], { :output => 'javascripts', :hide_success => true }) - runner.stub(:compile).and_return '' - formatter.should_receive(:success).with('Successfully generated javascripts/a.js') - formatter.should_receive(:notify).with('Successfully generated javascripts/a.js', + allow(runner).to receive(:compile).and_return '' + expect(formatter).to receive(:success).with('Successfully generated javascripts/a.js') + expect(formatter).to receive(:notify).with('Successfully generated javascripts/a.js', :title => 'CoffeeScript results') runner.run(['a.coffee'], [watcher], { :output => 'javascripts', :hide_success => true }) @@ -317,21 +317,21 @@ let(:watcher) { Guard::Watcher.new(%r{src/.+\.(?:coffee|coffee\.md|litcoffee)$}) } before do - File.should_receive(:exists?).with('target/a.js').and_return true - File.should_receive(:exists?).with('target/b.js').and_return true - File.should_receive(:exists?).with('target/c.js').and_return true + expect(File).to receive(:exists?).with('target/a.js').and_return true + expect(File).to receive(:exists?).with('target/b.js').and_return true + expect(File).to receive(:exists?).with('target/c.js').and_return true end it 'removes the files' do - FileUtils.should_receive(:remove_file).with('target/a.js') - FileUtils.should_receive(:remove_file).with('target/b.js') - FileUtils.should_receive(:remove_file).with('target/c.js') + expect(FileUtils).to receive(:remove_file).with('target/a.js') + expect(FileUtils).to receive(:remove_file).with('target/b.js') + expect(FileUtils).to receive(:remove_file).with('target/c.js') runner.remove(['src/a.coffee', 'src/b.coffee.md', 'src/c.litcoffee'], [watcher], { :output => 'target' }) end it 'shows a notification' do - formatter.should_receive(:success).once.with('Removed target/a.js, target/b.js, target/c.js') - formatter.should_receive(:notify).with('Removed target/a.js, target/b.js, target/c.js', + expect(formatter).to receive(:success).once.with('Removed target/a.js, target/b.js, target/c.js') + expect(formatter).to receive(:notify).with('Removed target/a.js, target/b.js, target/c.js', :title => 'CoffeeScript results') runner.remove(['src/a.coffee', 'src/b.coffee.md', 'src/c.litcoffee'], [watcher], { :output => 'target' }) diff --git a/spec/guard/coffeescript/version_spec.rb b/spec/guard/coffeescript/version_spec.rb index f41c4f5..70bd325 100644 --- a/spec/guard/coffeescript/version_spec.rb +++ b/spec/guard/coffeescript/version_spec.rb @@ -3,7 +3,7 @@ describe Guard::CoffeeScriptVersion do describe 'VERSION' do it 'defines the version' do - Guard::CoffeeScriptVersion::VERSION.should match /\d+.\d+.\d+/ + expect(Guard::CoffeeScriptVersion::VERSION).to match /\d+.\d+.\d+/ end end end diff --git a/spec/guard/coffeescript_spec.rb b/spec/guard/coffeescript_spec.rb index c4530fe..fd9c7da 100644 --- a/spec/guard/coffeescript_spec.rb +++ b/spec/guard/coffeescript_spec.rb @@ -10,40 +10,40 @@ let(:defaults) { Guard::CoffeeScript::DEFAULT_OPTIONS } before do - inspector.stub(:clean) - runner.stub(:run) - runner.stub(:remove) + allow(inspector).to receive(:clean) + allow(runner).to receive(:run) + allow(runner).to receive(:remove) end describe '#initialize' do context 'when no options are provided' do it 'sets a default :watchers option' do - guard.watchers.should be_a Array - guard.watchers.should be_empty + expect(guard.watchers).to be_a Array + expect(guard.watchers).to be_empty end it 'sets a default :wrap option' do - guard.options[:bare].should be_false + expect(guard.options[:bare]).to be_falsey end it 'sets a default :shallow option' do - guard.options[:shallow].should be_false + expect(guard.options[:shallow]).to be_falsey end it 'sets a default :hide_success option' do - guard.options[:hide_success].should be_false + expect(guard.options[:hide_success]).to be_falsey end it 'sets a default :noop option' do - guard.options[:noop].should be_false + expect(guard.options[:noop]).to be_falsey end it 'sets a default :all_on_start option' do - guard.options[:all_on_start].should be_false + expect(guard.options[:all_on_start]).to be_falsey end it 'sets the provided :source_maps option' do - guard.options[:source_map].should be_false + expect(guard.options[:source_map]).to be_falsey end end @@ -62,31 +62,31 @@ }) } it 'sets the provided :watchers option' do - guard.watchers.should == [watcher] + expect(guard.watchers).to eq([watcher]) end it 'sets the provided :bare option' do - guard.options[:bare].should be_true + expect(guard.options[:bare]).to be_truthy end it 'sets the provided :shallow option' do - guard.options[:shallow].should be_true + expect(guard.options[:shallow]).to be_truthy end it 'sets the provided :hide_success option' do - guard.options[:hide_success].should be_true + expect(guard.options[:hide_success]).to be_truthy end it 'sets the provided :noop option' do - guard.options[:noop].should be_true + expect(guard.options[:noop]).to be_truthy end it 'sets the provided :all_on_start option' do - guard.options[:all_on_start].should be_true + expect(guard.options[:all_on_start]).to be_truthy end it 'sets the provided :source_maps option' do - guard.options[:source_map].should be_true + expect(guard.options[:source_map]).to be_truthy end end @@ -94,16 +94,16 @@ let(:guard) { Guard::CoffeeScript.new( { :input => 'app/coffeescripts' }) } it 'creates a watcher' do - guard.should have(1).watchers + expect(guard.watchers.size).to eq(1) end it 'watches all *.{coffee,coffee.md,litcoffee} files' do - guard.watchers.first.pattern.should eql %r{^app/coffeescripts/(.+\.(?:coffee|coffee\.md|litcoffee))$} + expect(guard.watchers.first.pattern).to eql %r{^app/coffeescripts/(.+\.(?:coffee|coffee\.md|litcoffee))$} end context 'without an output option' do it 'sets the output directory to the input directory' do - guard.options[:output].should eql 'app/coffeescripts' + expect(guard.options[:output]).to eql 'app/coffeescripts' end end @@ -112,7 +112,7 @@ :output => 'public/javascripts' }) } it 'keeps the output directory' do - guard.options[:output].should eql 'public/javascripts' + expect(guard.options[:output]).to eql 'public/javascripts' end end end @@ -120,7 +120,7 @@ describe '#start' do it 'calls #run_all' do - guard.should_not_receive(:run_all) + expect(guard).not_to receive(:run_all) guard.start end @@ -128,7 +128,7 @@ let(:guard) { Guard::CoffeeScript.new( :all_on_start => true) } it 'calls #run_all' do - guard.should_receive(:run_all) + expect(guard).to receive(:run_all) guard.start end end @@ -138,38 +138,38 @@ let(:guard) { Guard::CoffeeScript.new( { :watchers => [Guard::Watcher.new('^x/.+\.(?:coffee|coffee\.md|litcoffee)$')] } ) } before do - Dir.stub(:glob).and_return ['x/a.coffee', 'x/b.coffee', 'y/c.coffee', 'x/d.coffeeemd', 'x/e.litcoffee'] + allow(Dir).to receive(:glob).and_return ['x/a.coffee', 'x/b.coffee', 'y/c.coffee', 'x/d.coffeeemd', 'x/e.litcoffee'] end it 'runs the run_on_modifications with all watched CoffeeScripts' do - guard.should_receive(:run_on_modifications).with(['x/a.coffee', 'x/b.coffee', 'x/e.litcoffee']) + expect(guard).to receive(:run_on_modifications).with(['x/a.coffee', 'x/b.coffee', 'x/e.litcoffee']) guard.run_all end end describe '#run_on_modifications' do it 'throws :task_has_failed when an error occurs' do - inspector.should_receive(:clean).with(['a.coffee', 'b.coffee']).and_return ['a.coffee'] - runner.should_receive(:run).with(['a.coffee'], [], defaults).and_return [[], false] + expect(inspector).to receive(:clean).with(['a.coffee', 'b.coffee']).and_return ['a.coffee'] + expect(runner).to receive(:run).with(['a.coffee'], [], defaults).and_return [[], false] expect { guard.run_on_modifications(['a.coffee', 'b.coffee']) }.to throw_symbol :task_has_failed end it 'starts the Runner with the cleaned files' do - inspector.should_receive(:clean).with(['a.coffee', 'b.coffee']).and_return ['a.coffee'] - runner.should_receive(:run).with(['a.coffee'], [], defaults).and_return [['a.js'], true] + expect(inspector).to receive(:clean).with(['a.coffee', 'b.coffee']).and_return ['a.coffee'] + expect(runner).to receive(:run).with(['a.coffee'], [], defaults).and_return [['a.js'], true] guard.run_on_modifications(['a.coffee', 'b.coffee']) end end describe '#run_on_removals' do it 'cleans the paths accepting missing files' do - inspector.should_receive(:clean).with(['a.coffee', 'b.coffee'], { :missing_ok => true }) + expect(inspector).to receive(:clean).with(['a.coffee', 'b.coffee'], { :missing_ok => true }) guard.run_on_removals(['a.coffee', 'b.coffee']) end it 'removes the files' do - inspector.should_receive(:clean).and_return ['a.coffee', 'b.coffee'] - runner.should_receive(:remove).with(['a.coffee', 'b.coffee'], guard.watchers, guard.options) + expect(inspector).to receive(:clean).and_return ['a.coffee', 'b.coffee'] + expect(runner).to receive(:remove).with(['a.coffee', 'b.coffee'], guard.watchers, guard.options) guard.run_on_removals(['a.coffee', 'b.coffee']) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d81991..1ab62f0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,12 +11,12 @@ ENV["GUARD_ENV"] = 'test' @project_path = Pathname.new(File.expand_path('../../', __FILE__)) - Guard::UI.stub(:info) - Guard::UI.stub(:debug) - Guard::UI.stub(:error) - Guard::UI.stub(:success) - Guard::UI.stub(:warning) - Guard::UI.stub(:notify) + allow(Guard::UI).to receive(:info) + allow(Guard::UI).to receive(:debug) + allow(Guard::UI).to receive(:error) + allow(Guard::UI).to receive(:success) + allow(Guard::UI).to receive(:warning) + allow(Guard::UI).to receive(:notify) end config.after(:each) do