From bfd40d6cf33478ee34ce17dfaa1f8126fb1d35e4 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Sun, 24 Nov 2013 23:03:24 -0800 Subject: [PATCH 1/3] Convert specs to the latest RSpec syntax with Transpec This conversion is done by Transpec 1.4.0 with the following command: transpec -m -s --keep deprecated --keep oneliner * 86 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) * 78 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 25 conversions from: obj.stub(:message => value) to: allow(obj).to receive_messages(:message => value) * 8 conversions from: obj.should_not_receive(:message) to: expect(obj).not_to receive(:message) --- spec/rspec/core/command_line_spec.rb | 24 ++-- spec/rspec/core/configuration_options_spec.rb | 32 +++--- spec/rspec/core/configuration_spec.rb | 104 +++++++++--------- spec/rspec/core/drb_options_spec.rb | 2 +- spec/rspec/core/example_group_spec.rb | 44 ++++---- spec/rspec/core/example_spec.rb | 8 +- spec/rspec/core/filter_manager_spec.rb | 2 +- .../formatters/base_text_formatter_spec.rb | 26 ++--- .../documentation_formatter_spec.rb | 6 +- .../core/formatters/json_formatter_spec.rb | 12 +- .../formatters/progress_formatter_spec.rb | 2 +- spec/rspec/core/metadata_spec.rb | 4 +- spec/rspec/core/option_parser_spec.rb | 10 +- spec/rspec/core/pending_example_spec.rb | 2 +- spec/rspec/core/project_initializer_spec.rb | 22 ++-- spec/rspec/core/rake_task_spec.rb | 6 +- spec/rspec/core/reporter_spec.rb | 22 ++-- spec/rspec/core/ruby_project_spec.rb | 4 +- spec/rspec/core/runner_spec.rb | 46 ++++---- spec/rspec/core/world_spec.rb | 18 +-- 20 files changed, 198 insertions(+), 198 deletions(-) diff --git a/spec/rspec/core/command_line_spec.rb b/spec/rspec/core/command_line_spec.rb index 4d92402949..a3dfaa9ba8 100644 --- a/spec/rspec/core/command_line_spec.rb +++ b/spec/rspec/core/command_line_spec.rb @@ -10,18 +10,18 @@ module RSpec::Core let(:config) { RSpec::configuration } let(:world) { RSpec::world } - before { config.hooks.stub(:run) } + before { allow(config.hooks).to receive(:run) } it "configures streams before command line options" do stdout = StringIO.new - config.stub :load_spec_files - config.stub(:reporter => double.as_null_object) + allow(config).to receive :load_spec_files + allow(config).to receive_messages(:reporter => double.as_null_object) config.output_stream = $stdout # this is necessary to ensure that color works correctly on windows - config.should_receive(:error_stream=).ordered - config.should_receive(:output_stream=).ordered - config.should_receive(:force).at_least(:once).ordered + expect(config).to receive(:error_stream=).ordered + expect(config).to receive(:output_stream=).ordered + expect(config).to receive(:force).at_least(:once).ordered command_line = build_command_line command_line.run err, stdout @@ -60,23 +60,23 @@ module RSpec::Core end context "running hooks" do - before { config.stub :load_spec_files } + before { allow(config).to receive :load_spec_files } it "runs before suite hooks" do - config.hooks.should_receive(:run).with(:before, :suite) + expect(config.hooks).to receive(:run).with(:before, :suite) command_line = build_command_line command_line.run err, out end it "runs after suite hooks" do - config.hooks.should_receive(:run).with(:after, :suite) + expect(config.hooks).to receive(:run).with(:after, :suite) command_line = build_command_line command_line.run err, out end it "runs after suite hooks even after an error" do - config.hooks.should_receive(:run).with(:before, :suite).and_raise "this error" - config.hooks.should_receive(:run).with(:after , :suite) + expect(config.hooks).to receive(:run).with(:before, :suite).and_raise "this error" + expect(config.hooks).to receive(:run).with(:after , :suite) expect do command_line = build_command_line command_line.run err, out @@ -86,7 +86,7 @@ module RSpec::Core end describe "#run with custom output" do - before { config.stub :files_to_run => [] } + before { allow(config).to receive_messages :files_to_run => [] } let(:output_file) { File.new("#{Dir.tmpdir}/command_line_spec_output.txt", 'w') } diff --git a/spec/rspec/core/configuration_options_spec.rb b/spec/rspec/core/configuration_options_spec.rb index 890d551919..d4a18a591b 100644 --- a/spec/rspec/core/configuration_options_spec.rb +++ b/spec/rspec/core/configuration_options_spec.rb @@ -23,8 +23,8 @@ it "sends libs before requires" do opts = config_options_object(*%w[--require a/path -I a/lib]) config = double("config").as_null_object - config.should_receive(:libs=).ordered - config.should_receive(:setup_load_path_and_require).ordered + expect(config).to receive(:libs=).ordered + expect(config).to receive(:setup_load_path_and_require).ordered opts.configure(config) end @@ -39,24 +39,24 @@ it "sets up load path and requires before formatter" do opts = config_options_object(*%w[--require a/path -f a/formatter]) config = double("config").as_null_object - config.should_receive(:setup_load_path_and_require).ordered - config.should_receive(:add_formatter).ordered + expect(config).to receive(:setup_load_path_and_require).ordered + expect(config).to receive(:add_formatter).ordered opts.configure(config) end it "sends default_path before files_or_directories_to_run" do opts = config_options_object(*%w[--default_path spec]) config = double("config").as_null_object - config.should_receive(:force).with(:default_path => 'spec').ordered - config.should_receive(:files_or_directories_to_run=).ordered + expect(config).to receive(:force).with(:default_path => 'spec').ordered + expect(config).to receive(:files_or_directories_to_run=).ordered opts.configure(config) end it "sends pattern before files_or_directories_to_run" do opts = config_options_object(*%w[--pattern **/*.spec]) config = double("config").as_null_object - config.should_receive(:force).with(:pattern => '**/*.spec').ordered - config.should_receive(:files_or_directories_to_run=).ordered + expect(config).to receive(:force).with(:pattern => '**/*.spec').ordered + expect(config).to receive(:files_or_directories_to_run=).ordered opts.configure(config) end @@ -77,7 +77,7 @@ it "forces color_enabled" do opts = config_options_object(*%w[--color]) config = RSpec::Core::Configuration.new - config.should_receive(:force).with(:color => true) + expect(config).to receive(:force).with(:color => true) opts.configure(config) end @@ -93,7 +93,7 @@ it "forces #{config_key}" do opts = config_options_object(cli_option, cli_value) config = RSpec::Core::Configuration.new - config.should_receive(:force) do |pair| + expect(config).to receive(:force) do |pair| expect(pair.keys.first).to eq(config_key) expect(pair.values.first).to eq(config_value) end @@ -105,8 +105,8 @@ with_env_vars 'SPEC_OPTS' => "--require file_from_env" do opts = config_options_object(*%w[--require file_from_opts]) config = RSpec::Core::Configuration.new - config.should_receive(:require).with("file_from_opts") - config.should_receive(:require).with("file_from_env") + expect(config).to receive(:require).with("file_from_opts") + expect(config).to receive(:require).with("file_from_env") opts.configure(config) end end @@ -115,7 +115,7 @@ with_env_vars 'SPEC_OPTS' => "-I dir_from_env" do opts = config_options_object(*%w[-I dir_from_opts]) config = RSpec::Core::Configuration.new - config.should_receive(:libs=).with(["dir_from_opts", "dir_from_env"]) + expect(config).to receive(:libs=).with(["dir_from_opts", "dir_from_env"]) opts.configure(config) end end @@ -296,7 +296,7 @@ end it "provides no files or directories if spec directory does not exist" do - FileTest.stub(:directory?).with("spec").and_return false + allow(FileTest).to receive(:directory?).with("spec").and_return false expect(parse_options()).to include(:files_or_directories_to_run => []) end end @@ -304,8 +304,8 @@ describe "default_path" do it "gets set before files_or_directories_to_run" do config = double("config").as_null_object - config.should_receive(:force).with(:default_path => 'foo').ordered - config.should_receive(:files_or_directories_to_run=).ordered + expect(config).to receive(:force).with(:default_path => 'foo').ordered + expect(config).to receive(:files_or_directories_to_run=).ordered opts = config_options_object("--default_path", "foo") opts.configure(config) end diff --git a/spec/rspec/core/configuration_spec.rb b/spec/rspec/core/configuration_spec.rb index 8cc656d09a..0fbee288a8 100644 --- a/spec/rspec/core/configuration_spec.rb +++ b/spec/rspec/core/configuration_spec.rb @@ -8,10 +8,10 @@ module RSpec::Core let(:config) { Configuration.new } describe "RSpec.configuration with a block" do - before { RSpec.stub(:warn_deprecation) } + before { allow(RSpec).to receive(:warn_deprecation) } it "is deprecated" do - RSpec.should_receive(:warn_deprecation) + expect(RSpec).to receive(:warn_deprecation) RSpec.configuration {} end end @@ -88,7 +88,7 @@ def absolute_path_to(dir) end it 'stores the required files' do - config.should_receive(:require).with('a/path') + expect(config).to receive(:require).with('a/path') config.setup_load_path_and_require ['a/path'] expect(config.requires).to eq ['a/path'] end @@ -105,27 +105,27 @@ def absolute_path_to(dir) describe "#load_spec_files" do it "loads files using load" do config.files_to_run = ["foo.bar", "blah_spec.rb"] - config.should_receive(:load).twice + expect(config).to receive(:load).twice config.load_spec_files end it "loads each file once, even if duplicated in list" do config.files_to_run = ["a_spec.rb", "a_spec.rb"] - config.should_receive(:load).once + expect(config).to receive(:load).once config.load_spec_files end end describe "#mock_framework" do it "defaults to :rspec" do - config.should_receive(:require).with('rspec/core/mocking_adapters/rspec') + expect(config).to receive(:require).with('rspec/core/mocking_adapters/rspec') config.mock_framework end end describe "#mock_framework="do it "delegates to mock_with" do - config.should_receive(:mock_with).with(:rspec) + expect(config).to receive(:mock_with).with(:rspec) config.mock_framework = :rspec end end @@ -134,7 +134,7 @@ def absolute_path_to(dir) it "yields a config object if the framework_module supports it" do custom_config = Struct.new(:custom_setting).new mod = Module.new - mod.stub(:configuration => custom_config) + allow(mod).to receive_messages(:configuration => custom_config) config.send m, mod do |mod_config| mod_config.custom_setting = true @@ -154,14 +154,14 @@ def absolute_path_to(dir) end describe "#mock_with" do - before { config.stub(:require) } + before { allow(config).to receive(:require) } it_behaves_like "a configurable framework adapter", :mock_with it "allows rspec-mocks to be configured with a provided block" do mod = Module.new - RSpec::Mocks.configuration.should_receive(:add_stub_and_should_receive_to).with(mod) + expect(RSpec::Mocks.configuration).to receive(:add_stub_and_should_receive_to).with(mod) config.mock_with :rspec do |c| c.add_stub_and_should_receive_to mod @@ -177,13 +177,13 @@ def absolute_path_to(dir) end it 'uses the named adapter' do - config.should_receive(:require).with("rspec/core/mocking_adapters/mocha") + expect(config).to receive(:require).with("rspec/core/mocking_adapters/mocha") stub_const("RSpec::Core::MockingAdapters::Mocha", Module.new) config.mock_with :mocha end it "uses the null adapter when given :nothing" do - config.should_receive(:require).with('rspec/core/mocking_adapters/null').and_call_original + expect(config).to receive(:require).with('rspec/core/mocking_adapters/null').and_call_original config.mock_with :nothing end @@ -201,7 +201,7 @@ def absolute_path_to(dir) context 'when there are already some example groups defined' do it 'raises an error since this setting must be applied before any groups are defined' do - RSpec.world.stub(:example_groups).and_return([double.as_null_object]) + allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object]) stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha)) expect { config.mock_with :mocha @@ -210,14 +210,14 @@ def absolute_path_to(dir) it 'does not raise an error if the default `mock_with :rspec` is re-configured' do config.mock_framework # called by RSpec when configuring the first example group - RSpec.world.stub(:example_groups).and_return([double.as_null_object]) + allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object]) config.mock_with :rspec end it 'does not raise an error if re-setting the same config' do stub_const("RSpec::Core::MockingAdapters::Mocha", double(:framework_name => :mocha)) groups = [] - RSpec.world.stub(:example_groups => groups) + allow(RSpec.world).to receive_messages(:example_groups => groups) config.mock_with :mocha groups << double.as_null_object config.mock_with :mocha @@ -227,14 +227,14 @@ def absolute_path_to(dir) describe "#expectation_framework" do it "defaults to :rspec" do - config.should_receive(:require).with('rspec/expectations') + expect(config).to receive(:require).with('rspec/expectations') config.expectation_frameworks end end describe "#expectation_framework=" do it "delegates to expect_with=" do - config.should_receive(:expect_with).with(:rspec) + expect(config).to receive(:expect_with).with(:rspec) config.expectation_framework = :rspec end end @@ -242,7 +242,7 @@ def absolute_path_to(dir) describe "#expect_with" do before do stub_const("Test::Unit::Assertions", Module.new) - config.stub(:require) + allow(config).to receive(:require) end it_behaves_like "a configurable framework adapter", :expect_with @@ -253,7 +253,7 @@ def absolute_path_to(dir) ].each do |framework, required_file| context "with #{framework}" do it "requires #{required_file}" do - config.should_receive(:require).with(required_file) + expect(config).to receive(:require).with(required_file) config.expect_with framework end end @@ -280,7 +280,7 @@ def absolute_path_to(dir) context 'when there are already some example groups defined' do it 'raises an error since this setting must be applied before any groups are defined' do - RSpec.world.stub(:example_groups).and_return([double.as_null_object]) + allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object]) expect { config.expect_with :rspec }.to raise_error(/must be configured before any example groups are defined/) @@ -288,13 +288,13 @@ def absolute_path_to(dir) it 'does not raise an error if the default `expect_with :rspec` is re-configured' do config.expectation_frameworks # called by RSpec when configuring the first example group - RSpec.world.stub(:example_groups).and_return([double.as_null_object]) + allow(RSpec.world).to receive(:example_groups).and_return([double.as_null_object]) config.expect_with :rspec end it 'does not raise an error if re-setting the same config' do groups = [] - RSpec.world.stub(:example_groups => groups) + allow(RSpec.world).to receive_messages(:example_groups => groups) config.expect_with :stdlib groups << double.as_null_object config.expect_with :stdlib @@ -305,7 +305,7 @@ def absolute_path_to(dir) describe "#expecting_with_rspec?" do before do stub_const("Test::Unit::Assertions", Module.new) - config.stub(:require) + allow(config).to receive(:require) end it "returns false by default" do @@ -402,34 +402,34 @@ def absolute_path_to(dir) context "with default default_path" do it "loads files in the default path when run by rspec" do - config.stub(:command) { 'rspec' } + allow(config).to receive(:command) { 'rspec' } config.files_or_directories_to_run = [] expect(config.files_to_run).not_to be_empty end it "loads files in the default path when run with DRB (e.g., spork)" do - config.stub(:command) { 'spork' } - RSpec::Core::Runner.stub(:running_in_drb?) { true } + allow(config).to receive(:command) { 'spork' } + allow(RSpec::Core::Runner).to receive(:running_in_drb?) { true } config.files_or_directories_to_run = [] expect(config.files_to_run).not_to be_empty end it "does not load files in the default path when run by ruby" do - config.stub(:command) { 'ruby' } + allow(config).to receive(:command) { 'ruby' } config.files_or_directories_to_run = [] expect(config.files_to_run).to be_empty end end def specify_consistent_ordering_of_files_to_run - File.stub(:directory?).with('a') { true } + allow(File).to receive(:directory?).with('a') { true } orderings = [ %w[ a/1.rb a/2.rb a/3.rb ], %w[ a/2.rb a/1.rb a/3.rb ], %w[ a/3.rb a/2.rb a/1.rb ] ].map do |files| - Dir.should_receive(:[]).with(/^\{?a/) { files } + expect(Dir).to receive(:[]).with(/^\{?a/) { files } yield config.files_to_run end @@ -457,7 +457,7 @@ def specify_consistent_ordering_of_files_to_run context 'when given multiple file paths' do it 'orders the files in a consistent ordering, regardless of the given order' do - File.stub(:directory?) { false } # fake it into thinking these a full file paths + allow(File).to receive(:directory?) { false } # fake it into thinking these a full file paths files = ['a/b/c_spec.rb', 'c/b/a_spec.rb'] config.files_or_directories_to_run = *files @@ -698,7 +698,7 @@ def metadata_hash(*args) config.output_stream = output config.tty = true - config.output_stream.stub :tty? => true + allow(config.output_stream).to receive_messages :tty? => true expect(config.send(color_option)).to be_truthy expect(config.send(color_option, output)).to be_truthy @@ -711,7 +711,7 @@ def metadata_hash(*args) config.output_stream = output config.tty = true - config.output_stream.stub :tty? => false + allow(config.output_stream).to receive_messages :tty? => false expect(config.send(color_option)).to be_truthy expect(config.send(color_option, output)).to be_truthy @@ -724,7 +724,7 @@ def metadata_hash(*args) config.output_stream = output config.tty = false - config.output_stream.stub :tty? => true + allow(config.output_stream).to receive_messages :tty? => true expect(config.send(color_option)).to be_truthy expect(config.send(color_option, output)).to be_truthy @@ -737,7 +737,7 @@ def metadata_hash(*args) config.output_stream = output config.tty = false - config.output_stream.stub :tty? => false + allow(config.output_stream).to receive_messages :tty? => false expect(config.send(color_option)).to be_falsey expect(config.send(color_option, output)).to be_falsey @@ -748,7 +748,7 @@ def metadata_hash(*args) before do @original_host = RbConfig::CONFIG['host_os'] RbConfig::CONFIG['host_os'] = 'mingw' - config.stub(:require) + allow(config).to receive(:require) end after do @@ -760,14 +760,14 @@ def metadata_hash(*args) it "enables colors" do config.output_stream = StringIO.new - config.output_stream.stub :tty? => true + allow(config.output_stream).to receive_messages :tty? => true config.send "#{color_option}=", true expect(config.send(color_option)).to be_truthy end it "leaves output stream intact" do config.output_stream = $stdout - config.stub(:require) do |what| + allow(config).to receive(:require) do |what| config.output_stream = 'foo' if what =~ /Win32/ end config.send "#{color_option}=", true @@ -781,13 +781,13 @@ def metadata_hash(*args) end it "warns to install ANSICON" do - config.stub(:require) { raise LoadError } + allow(config).to receive(:require) { raise LoadError } expect_warning_with_call_site(__FILE__, __LINE__ + 1, /You must use ANSICON/) config.send "#{color_option}=", true end it "sets color_enabled to false" do - config.stub(:require) { raise LoadError } + allow(config).to receive(:require) { raise LoadError } config.send "#{color_option}=", true config.color_enabled = true expect(config.send(color_option)).to be_falsey @@ -799,7 +799,7 @@ def metadata_hash(*args) it "prefers incoming cli_args" do config.output_stream = StringIO.new - config.output_stream.stub :tty? => true + allow(config.output_stream).to receive_messages :tty? => true config.force :color => true config.color = false expect(config.color).to be_truthy @@ -808,7 +808,7 @@ def metadata_hash(*args) describe '#formatter=' do it "delegates to add_formatter (better API for user-facing configuration)" do - config.should_receive(:add_formatter).with('these','options') + expect(config).to receive(:add_formatter).with('these','options') config.add_formatter('these','options') end end @@ -849,7 +849,7 @@ def metadata_hash(*args) end it "requires a formatter file based on its fully qualified name" do - config.should_receive(:require).with('rspec/custom_formatter') do + expect(config).to receive(:require).with('rspec/custom_formatter') do stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter)) end config.add_formatter "RSpec::CustomFormatter" @@ -857,7 +857,7 @@ def metadata_hash(*args) end it "raises NameError if class is unresolvable" do - config.should_receive(:require).with('rspec/custom_formatter3') + expect(config).to receive(:require).with('rspec/custom_formatter3') expect(lambda { config.add_formatter "RSpec::CustomFormatter3" }).to raise_error(NameError) end @@ -1076,7 +1076,7 @@ def metadata_hash(*args) include_context "isolate load path mutation" it "adds directories to the LOAD_PATH" do - $LOAD_PATH.should_receive(:unshift).with("a/dir") + expect($LOAD_PATH).to receive(:unshift).with("a/dir") config.libs = ["a/dir"] end end @@ -1091,16 +1091,16 @@ def metadata_hash(*args) end describe "#requires=" do - before { RSpec.should_receive :deprecate } + before { expect(RSpec).to receive :deprecate } it "requires the configured files" do - config.should_receive(:require).with('foo').ordered - config.should_receive(:require).with('bar').ordered + expect(config).to receive(:require).with('foo').ordered + expect(config).to receive(:require).with('bar').ordered config.requires = ['foo', 'bar'] end it "stores require paths" do - config.should_receive(:require).with("a/path") + expect(config).to receive(:require).with("a/path") config.requires = ["a/path"] expect(config.requires).to eq ['a/path'] end @@ -1159,7 +1159,7 @@ def metadata_hash(*args) context "with :alias => " do it "is deprecated" do - RSpec::should_receive(:deprecate).with(/:alias option/, :replacement => ":alias_with") + expect(RSpec)::to receive(:deprecate).with(/:alias option/, :replacement => ":alias_with") config.add_setting :custom_option config.add_setting :another_custom_option, :alias => :custom_option end @@ -1379,7 +1379,7 @@ def use_seed_on(registry) end it 'sets up random ordering' do - RSpec.stub(:configuration => config) + allow(RSpec).to receive_messages(:configuration => config) global_ordering = config.ordering_registry.fetch(:global) expect(global_ordering).to be_an_instance_of(Ordering::Random) end @@ -1393,7 +1393,7 @@ def use_seed_on(registry) end it 'sets up random ordering' do - RSpec.stub(:configuration => config) + allow(RSpec).to receive_messages(:configuration => config) global_ordering = config.ordering_registry.fetch(:global) expect(global_ordering).to be_an_instance_of(Ordering::Random) end @@ -1410,7 +1410,7 @@ def use_seed_on(registry) end it 'clears the random ordering' do - RSpec.stub(:configuration => config) + allow(RSpec).to receive_messages(:configuration => config) list = [1, 2, 3, 4] ordering_strategy = config.ordering_registry.fetch(:global) expect(ordering_strategy.order(list)).to eq([1, 2, 3, 4]) diff --git a/spec/rspec/core/drb_options_spec.rb b/spec/rspec/core/drb_options_spec.rb index f00ab78ff7..5950a116e2 100644 --- a/spec/rspec/core/drb_options_spec.rb +++ b/spec/rspec/core/drb_options_spec.rb @@ -6,7 +6,7 @@ describe "#drb_argv" do it "preserves extra arguments" do - File.stub(:exist?) { false } + allow(File).to receive(:exist?) { false } expect(config_options_object(*%w[ a --drb b --color c ]).drb_argv).to match_array %w[ --color a b c ] end diff --git a/spec/rspec/core/example_group_spec.rb b/spec/rspec/core/example_group_spec.rb index 4bd72d2ea0..d1b0033151 100644 --- a/spec/rspec/core/example_group_spec.rb +++ b/spec/rspec/core/example_group_spec.rb @@ -282,12 +282,12 @@ def ascending_numbers before do filter_manager = FilterManager.new filter_manager.include filter_metadata - world.stub(:filter_manager => filter_manager) + allow(world).to receive_messages(:filter_manager => filter_manager) end it "includes examples in groups matching filter" do group = ExampleGroup.describe("does something", spec_metadata) - group.stub(:world) { world } + allow(group).to receive(:world) { world } all_examples = [ group.example("first"), group.example("second") ] expect(group.filtered_examples).to eq(all_examples) @@ -295,7 +295,7 @@ def ascending_numbers it "includes examples directly matching filter" do group = ExampleGroup.describe("does something") - group.stub(:world) { world } + allow(group).to receive(:world) { world } filtered_examples = [ group.example("first", spec_metadata), group.example("second", spec_metadata) @@ -310,12 +310,12 @@ def ascending_numbers before do filter_manager = FilterManager.new filter_manager.exclude filter_metadata - world.stub(:filter_manager => filter_manager) + allow(world).to receive_messages(:filter_manager => filter_manager) end it "excludes examples in groups matching filter" do group = ExampleGroup.describe("does something", spec_metadata) - group.stub(:world) { world } + allow(group).to receive(:world) { world } [ group.example("first"), group.example("second") ] expect(group.filtered_examples).to be_empty @@ -323,7 +323,7 @@ def ascending_numbers it "excludes examples directly matching filter" do group = ExampleGroup.describe("does something") - group.stub(:world) { world } + allow(group).to receive(:world) { world } [ group.example("first", spec_metadata), group.example("second", spec_metadata) @@ -404,7 +404,7 @@ def ascending_numbers context "with no filters" do it "returns all" do group = ExampleGroup.describe - group.stub(:world) { world } + allow(group).to receive(:world) { world } example = group.example("does something") expect(group.filtered_examples).to eq([example]) end @@ -414,9 +414,9 @@ def ascending_numbers it "returns none" do filter_manager = FilterManager.new filter_manager.include :awesome => false - world.stub(:filter_manager => filter_manager) + allow(world).to receive_messages(:filter_manager => filter_manager) group = ExampleGroup.describe - group.stub(:world) { world } + allow(group).to receive(:world) { world } group.example("does something") expect(group.filtered_examples).to eq([]) end @@ -838,7 +838,7 @@ def define_and_run_group(define_outer_example = false) before(:each) do hooks_run = [] - RSpec.configuration.reporter.stub(:message) + allow(RSpec.configuration.reporter).to receive(:message) end let(:group) do @@ -858,8 +858,8 @@ def define_and_run_group(define_outer_example = false) end it "rescues any error(s) and prints them out" do - RSpec.configuration.reporter.should_receive(:message).with(/An error in an after\(:all\) hook/) - RSpec.configuration.reporter.should_receive(:message).with(/A different hook raising an error/) + expect(RSpec.configuration.reporter).to receive(:message).with(/An error in an after\(:all\) hook/) + expect(RSpec.configuration.reporter).to receive(:message).with(/A different hook raising an error/) group.run end @@ -971,7 +971,7 @@ def define_and_run_group(define_outer_example = false) example('ex 1') { expect(1).to eq(1) } example('ex 2') { expect(1).to eq(1) } end - group.stub(:filtered_examples) { group.examples } + allow(group).to receive(:filtered_examples) { group.examples } expect(group.run(reporter)).to be_truthy end @@ -980,7 +980,7 @@ def define_and_run_group(define_outer_example = false) example('ex 1') { expect(1).to eq(1) } example('ex 2') { expect(1).to eq(2) } end - group.stub(:filtered_examples) { group.examples } + allow(group).to receive(:filtered_examples) { group.examples } expect(group.run(reporter)).to be_falsey end @@ -989,9 +989,9 @@ def define_and_run_group(define_outer_example = false) example('ex 1') { expect(1).to eq(2) } example('ex 2') { expect(1).to eq(1) } end - group.stub(:filtered_examples) { group.examples } + allow(group).to receive(:filtered_examples) { group.examples } group.filtered_examples.each do |example| - example.should_receive(:run) + expect(example).to receive(:run) end expect(group.run(reporter)).to be_falsey end @@ -1077,7 +1077,7 @@ def define_and_run_group(define_outer_example = false) context "with fail_fast? => true" do let(:group) do group = RSpec::Core::ExampleGroup.describe - group.stub(:fail_fast?) { true } + allow(group).to receive(:fail_fast?) { true } group end @@ -1104,18 +1104,18 @@ def define_and_run_group(define_outer_example = false) let(:group) { RSpec::Core::ExampleGroup.describe } before do - RSpec.stub(:wants_to_quit) { true } - RSpec.stub(:clear_remaining_example_groups) + allow(RSpec).to receive(:wants_to_quit) { true } + allow(RSpec).to receive(:clear_remaining_example_groups) end it "returns without starting the group" do - reporter.should_not_receive(:example_group_started) + expect(reporter).not_to receive(:example_group_started) group.run(reporter) end context "at top level" do it "purges remaining groups" do - RSpec.should_receive(:clear_remaining_example_groups) + expect(RSpec).to receive(:clear_remaining_example_groups) group.run(reporter) end end @@ -1123,7 +1123,7 @@ def define_and_run_group(define_outer_example = false) context "in a nested group" do it "does not purge remaining groups" do nested_group = group.describe - RSpec.should_not_receive(:clear_remaining_example_groups) + expect(RSpec).not_to receive(:clear_remaining_example_groups) nested_group.run(reporter) end end diff --git a/spec/rspec/core/example_spec.rb b/spec/rspec/core/example_spec.rb index 314c34b4a1..bbde0936b3 100644 --- a/spec/rspec/core/example_spec.rb +++ b/spec/rspec/core/example_spec.rb @@ -62,7 +62,7 @@ def capture_stdout describe "when there is no explicit description" do def expect_with(*frameworks) - RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec)) + allow(RSpec.configuration).to receive(:expecting_with_rspec?).and_return(frameworks.include?(:rspec)) if frameworks.include?(:stdlib) example_group.class_eval do @@ -139,7 +139,7 @@ def assert(val) before(:each) { expect_with :stdlib } it "does not attempt to get the generated description from RSpec::Matchers" do - RSpec::Matchers.should_not_receive(:generated_description) + expect(RSpec::Matchers).not_to receive(:generated_description) example_group.example { assert 5 == 5 } example_group.run end @@ -296,7 +296,7 @@ def run_and_capture_reported_message(group) # We can't use should_receive(:message).with(/.../) here, # because if that fails, it would fail within our example-under-test, # and since there's already two errors, it would just be reported again. - RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg } + allow(RSpec.configuration.reporter).to receive(:message) { |msg| reported_msg = msg } group.run reported_msg end @@ -483,7 +483,7 @@ def run_and_capture_reported_message(group) group = RSpec::Core::ExampleGroup.describe example = group.example example.__send__ :start, reporter - Time.stub(:now => Time.utc(2012, 10, 1)) + allow(Time).to receive_messages(:now => Time.utc(2012, 10, 1)) example.__send__ :finish, reporter expect(example.metadata[:execution_result][:run_time]).to be < 0.2 end diff --git a/spec/rspec/core/filter_manager_spec.rb b/spec/rspec/core/filter_manager_spec.rb index e22a1e1de3..905d0ceed9 100644 --- a/spec/rspec/core/filter_manager_spec.rb +++ b/spec/rspec/core/filter_manager_spec.rb @@ -105,7 +105,7 @@ def opposite(name) describe "#prune" do def filterable_object_with(args = {}) object = double('a filterable object') - object.stub(:any_apply?) { |f| Metadata.new(args).any_apply?(f) } + allow(object).to receive(:any_apply?) { |f| Metadata.new(args).any_apply?(f) } object end diff --git a/spec/rspec/core/formatters/base_text_formatter_spec.rb b/spec/rspec/core/formatters/base_text_formatter_spec.rb index af92f99f65..8ef693c62b 100644 --- a/spec/rspec/core/formatters/base_text_formatter_spec.rb +++ b/spec/rspec/core/formatters/base_text_formatter_spec.rb @@ -34,7 +34,7 @@ describe "#dump_failures" do let(:group) { RSpec::Core::ExampleGroup.describe("group name") } - before { RSpec.configuration.stub(:color_enabled?) { false } } + before { allow(RSpec.configuration).to receive(:color_enabled?) { false } } def run_all_and_dump_failures group.run(formatter) @@ -53,7 +53,7 @@ def run_all_and_dump_failures context "with an exception without a message" do it "does not throw NoMethodError" do exception_without_message = Exception.new() - exception_without_message.stub(:message) { nil } + allow(exception_without_message).to receive(:message) { nil } group.example("example name") { raise exception_without_message } expect { run_all_and_dump_failures }.not_to raise_error end @@ -68,7 +68,7 @@ def run_all_and_dump_failures context "with an exception that has an exception instance as its message" do it "does not raise NoMethodError" do gonzo_exception = RuntimeError.new - gonzo_exception.stub(:message) { gonzo_exception } + allow(gonzo_exception).to receive(:message) { gonzo_exception } group.example("example name") { raise gonzo_exception } expect { run_all_and_dump_failures }.not_to raise_error end @@ -101,7 +101,7 @@ def run_all_and_dump_failures context "with a failed message expectation (rspec-mocks)" do it "does not show the error class" do - group.example("example name") { "this".should_receive("that") } + group.example("example name") { expect("this").to receive("that") } run_all_and_dump_failures expect(output.string).not_to match(/RSpec/m) end @@ -150,7 +150,7 @@ def run_all_and_dump_failures describe "#dump_pending" do let(:group) { RSpec::Core::ExampleGroup.describe("group name") } - before { RSpec.configuration.stub(:color_enabled?) { false } } + before { allow(RSpec.configuration).to receive(:color_enabled?) { false } } def run_all_and_dump_pending group.run(formatter) @@ -158,7 +158,7 @@ def run_all_and_dump_pending end context "with show_failures_in_pending_blocks setting enabled" do - before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { true } } + before { allow(RSpec.configuration).to receive(:show_failures_in_pending_blocks?) { true } } it "preserves formatting" do group.example("example name") { pending { expect("this").to eq("that") } } @@ -172,7 +172,7 @@ def run_all_and_dump_pending context "with an exception without a message" do it "does not throw NoMethodError" do exception_without_message = Exception.new() - exception_without_message.stub(:message) { nil } + allow(exception_without_message).to receive(:message) { nil } group.example("example name") { pending { raise exception_without_message } } expect { run_all_and_dump_pending }.not_to raise_error end @@ -243,7 +243,7 @@ def run_all_and_dump_pending end context "with show_failures_in_pending_blocks setting disabled" do - before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { false } } + before { allow(RSpec.configuration).to receive(:show_failures_in_pending_blocks?) { false } } it "does not output the failure information" do group.example("example name") { pending { expect("this").to eq("that") } } @@ -265,8 +265,8 @@ def run_all_and_dump_pending end group.run(double('reporter').as_null_object) - formatter.stub(:examples) { group.examples } - RSpec.configuration.stub(:profile_examples) { 10 } + allow(formatter).to receive(:examples) { group.examples } + allow(RSpec.configuration).to receive(:profile_examples) { 10 } end it "names the example" do @@ -304,11 +304,11 @@ def run_all_and_dump_pending before do group.run(rpt) - RSpec.configuration.stub(:profile_examples) { 10 } + allow(RSpec.configuration).to receive(:profile_examples) { 10 } end context "with one example group" do - before { formatter.stub(:examples) { group.examples } } + before { allow(formatter).to receive(:examples) { group.examples } } it "doesn't profile a single example group" do formatter.dump_profile_slowest_example_groups @@ -324,7 +324,7 @@ def run_all_and_dump_pending end group2.run(rpt) - formatter.stub(:examples) { group.examples + group2.examples } + allow(formatter).to receive(:examples) { group.examples + group2.examples } end it "prints the slowest example groups" do diff --git a/spec/rspec/core/formatters/documentation_formatter_spec.rb b/spec/rspec/core/formatters/documentation_formatter_spec.rb index 3647f46570..2bb8e41e7f 100644 --- a/spec/rspec/core/formatters/documentation_formatter_spec.rb +++ b/spec/rspec/core/formatters/documentation_formatter_spec.rb @@ -17,7 +17,7 @@ module RSpec::Core::Formatters ] output = StringIO.new - RSpec.configuration.stub(:color_enabled?) { false } + allow(RSpec.configuration).to receive(:color_enabled?) { false } formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output) @@ -29,7 +29,7 @@ module RSpec::Core::Formatters it "represents nested group using hierarchy tree" do output = StringIO.new - RSpec.configuration.stub(:color_enabled?) { false } + allow(RSpec.configuration).to receive(:color_enabled?) { false } formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output) @@ -64,7 +64,7 @@ module RSpec::Core::Formatters it "strips whitespace for each row" do output = StringIO.new - RSpec.configuration.stub(:color_enabled?) { false } + allow(RSpec.configuration).to receive(:color_enabled?) { false } formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output) diff --git a/spec/rspec/core/formatters/json_formatter_spec.rb b/spec/rspec/core/formatters/json_formatter_spec.rb index e608e1247c..40f9350019 100644 --- a/spec/rspec/core/formatters/json_formatter_spec.rb +++ b/spec/rspec/core/formatters/json_formatter_spec.rb @@ -28,7 +28,7 @@ pending_line = __LINE__ - 4 now = Time.now - Time.stub(:now).and_return(now) + allow(Time).to receive(:now).and_return(now) reporter.report(2) do |r| group.run(r) end @@ -119,8 +119,8 @@ end group.run(double('reporter').as_null_object) - formatter.stub(:examples) { group.examples } - RSpec.configuration.stub(:profile_examples) { 10 } + allow(formatter).to receive(:examples) { group.examples } + allow(RSpec.configuration).to receive(:profile_examples) { 10 } end it "names the example" do @@ -150,12 +150,12 @@ let(:rpt) { double('reporter').as_null_object } before do - RSpec.configuration.stub(:profile_examples) { 10 } + allow(RSpec.configuration).to receive(:profile_examples) { 10 } group.run(rpt) end context "with one example group" do - before { formatter.stub(:examples) { group.examples } } + before { allow(formatter).to receive(:examples) { group.examples } } it "doesn't profile a single example group" do formatter.dump_profile_slowest_example_groups @@ -171,7 +171,7 @@ end group2.run(rpt) - formatter.stub(:examples) { group.examples + group2.examples } + allow(formatter).to receive(:examples) { group.examples + group2.examples } end it "provides the slowest example groups" do diff --git a/spec/rspec/core/formatters/progress_formatter_spec.rb b/spec/rspec/core/formatters/progress_formatter_spec.rb index d9477d5f55..b9f6cc5dd1 100644 --- a/spec/rspec/core/formatters/progress_formatter_spec.rb +++ b/spec/rspec/core/formatters/progress_formatter_spec.rb @@ -7,7 +7,7 @@ @output = StringIO.new @formatter = RSpec::Core::Formatters::ProgressFormatter.new(@output) @formatter.start(2) - @formatter.stub(:color_enabled?).and_return(false) + allow(@formatter).to receive(:color_enabled?).and_return(false) end it "produces line break on start dump" do diff --git a/spec/rspec/core/metadata_spec.rb b/spec/rspec/core/metadata_spec.rb index 7cffd534d1..0b8dba10cc 100644 --- a/spec/rspec/core/metadata_spec.rb +++ b/spec/rspec/core/metadata_spec.rb @@ -50,7 +50,7 @@ module Core let(:next_example_metadata) { group_metadata.for_example('next_example', :caller => ["foo_spec.rb:#{example_line_number + 2}"]) } let(:world) { World.new } - before { RSpec.stub(:world) { world } } + before { allow(RSpec).to receive(:world) { world } } shared_examples_for "matching by line number" do let(:preceeding_declaration_lines) {{ @@ -61,7 +61,7 @@ module Core (example_metadata[:line_number] + 2) => example_metadata[:line_number] + 2, }} before do - world.should_receive(:preceding_declaration_line).at_least(:once).and_return do |v| + expect(world).to receive(:preceding_declaration_line).at_least(:once).and_return do |v| preceeding_declaration_lines[v] end end diff --git a/spec/rspec/core/option_parser_spec.rb b/spec/rspec/core/option_parser_spec.rb index 13145e7160..38e4514225 100644 --- a/spec/rspec/core/option_parser_spec.rb +++ b/spec/rspec/core/option_parser_spec.rb @@ -5,13 +5,13 @@ module RSpec::Core let(:output_file){ mock File } before do - RSpec.stub(:deprecate) - File.stub(:open).with("foo.txt",'w') { (output_file) } + allow(RSpec).to receive(:deprecate) + allow(File).to receive(:open).with("foo.txt",'w') { (output_file) } end it "does not parse empty args" do parser = Parser.new - OptionParser.should_not_receive(:new) + expect(OptionParser).not_to receive(:new) parser.parse([]) end @@ -19,7 +19,7 @@ module RSpec::Core parser = Parser.new option = "--my_wrong_arg" - parser.should_receive(:abort) do |msg| + expect(parser).to receive(:abort) do |msg| expect(msg).to include('use --help', option) end @@ -28,7 +28,7 @@ module RSpec::Core describe "--formatter" do it "is deprecated" do - RSpec.should_receive(:deprecate) + expect(RSpec).to receive(:deprecate) Parser.parse(%w[--formatter doc]) end diff --git a/spec/rspec/core/pending_example_spec.rb b/spec/rspec/core/pending_example_spec.rb index c7554707f4..bda20629e4 100644 --- a/spec/rspec/core/pending_example_spec.rb +++ b/spec/rspec/core/pending_example_spec.rb @@ -168,7 +168,7 @@ def run_example(*pending_args) context "that fails due to a failed message expectation" do def run_example(*pending_args) - super(*pending_args) { "foo".should_receive(:bar) } + super(*pending_args) { expect("foo").to receive(:bar) } end it "passes" do diff --git a/spec/rspec/core/project_initializer_spec.rb b/spec/rspec/core/project_initializer_spec.rb index 0a7d20911e..2d189dade7 100644 --- a/spec/rspec/core/project_initializer_spec.rb +++ b/spec/rspec/core/project_initializer_spec.rb @@ -9,13 +9,13 @@ module RSpec::Core let(:command_line_config) { ProjectInitializer.new } before do - command_line_config.stub(:puts) - command_line_config.stub(:gets => 'no') + allow(command_line_config).to receive(:puts) + allow(command_line_config).to receive_messages(:gets => 'no') end context "with no .rspec file" do it "says it's creating .rspec " do - command_line_config.should_receive(:puts).with(/create\s+\.rspec/) + expect(command_line_config).to receive(:puts).with(/create\s+\.rspec/) command_line_config.run end @@ -28,7 +28,7 @@ module RSpec::Core context "with a .rspec file" do it "says .rspec exists" do FileUtils.touch('.rspec') - command_line_config.should_receive(:puts).with(/exist\s+\.rspec/) + expect(command_line_config).to receive(:puts).with(/exist\s+\.rspec/) command_line_config.run end @@ -41,7 +41,7 @@ module RSpec::Core context "with no spec/spec_helper.rb file" do it "says it's creating spec/spec_helper.rb " do - command_line_config.should_receive(:puts).with(/create\s+spec\/spec_helper.rb/) + expect(command_line_config).to receive(:puts).with(/create\s+spec\/spec_helper.rb/) command_line_config.run end @@ -56,7 +56,7 @@ module RSpec::Core it "says spec/spec_helper.rb exists" do FileUtils.touch('spec/spec_helper.rb') - command_line_config.should_receive(:puts).with(/exist\s+spec\/spec_helper.rb/) + expect(command_line_config).to receive(:puts).with(/exist\s+spec\/spec_helper.rb/) command_line_config.run end @@ -75,18 +75,18 @@ module RSpec::Core end it "asks whether to delete the file" do - command_line_config.should_receive(:puts).with(/delete/) + expect(command_line_config).to receive(:puts).with(/delete/) command_line_config.run end it "removes it if confirmed" do - command_line_config.stub(:gets => 'yes') + allow(command_line_config).to receive_messages(:gets => 'yes') command_line_config.run expect(File.exist?('lib/tasks/rspec.rake')).to be_falsey end it "leaves it if not confirmed" do - command_line_config.stub(:gets => 'no') + allow(command_line_config).to receive_messages(:gets => 'no') command_line_config.run expect(File.exist?('lib/tasks/rspec.rake')).to be_truthy end @@ -96,8 +96,8 @@ module RSpec::Core context "given an arg" do it "warns if arg received (no longer necessary)" do config = ProjectInitializer.new("another_arg") - config.stub(:puts) - config.stub(:gets => 'no') + allow(config).to receive(:puts) + allow(config).to receive_messages(:gets => 'no') config.run end end diff --git a/spec/rspec/core/rake_task_spec.rb b/spec/rspec/core/rake_task_spec.rb index 2d8c42d029..f64a444ea6 100644 --- a/spec/rspec/core/rake_task_spec.rb +++ b/spec/rspec/core/rake_task_spec.rb @@ -28,7 +28,7 @@ def spec_command expect(args[:files]).to eq "first_spec.rb" end - task.should_receive(:run_task) { true } + expect(task).to receive(:run_task) { true } expect(Rake.application.invoke_task("rake_task_args[first_spec.rb]")).to be_truthy end end @@ -59,7 +59,7 @@ def specify_consistent_ordering_of_files_to_run(pattern, task) %w[ a/2.rb a/1.rb a/3.rb ], %w[ a/3.rb a/2.rb a/1.rb ] ].map do |files| - FileList.should_receive(:[]).with(pattern) { files } + expect(FileList).to receive(:[]).with(pattern) { files } task.__send__(:files_to_run) end @@ -87,7 +87,7 @@ def specify_consistent_ordering_of_files_to_run(pattern, task) # since the config block is deferred til task invocation, must fake # calling the task so the expected pattern is picked up - task.should_receive(:run_task) { true } + expect(task).to receive(:run_task) { true } expect(Rake.application.invoke_task(task.name)).to be_truthy specify_consistent_ordering_of_files_to_run('a/*.rb', task) diff --git a/spec/rspec/core/reporter_spec.rb b/spec/rspec/core/reporter_spec.rb index 2191279f47..b6ad45a2e2 100644 --- a/spec/rspec/core/reporter_spec.rb +++ b/spec/rspec/core/reporter_spec.rb @@ -15,7 +15,7 @@ def reporter_for(*formatters) %w[start_dump dump_pending dump_failures dump_summary close].each do |message| it "sends #{message} to the formatter(s) that respond to message" do - formatter.as_null_object.should_receive(message) + expect(formatter.as_null_object).to receive(message) reporter.finish end @@ -31,7 +31,7 @@ def reporter_for(*formatters) example = double("example") reporter = reporter_for(formatter) - formatter.should_receive(:example_started). + expect(formatter).to receive(:example_started). with(example) reporter.example_started(example) @@ -41,8 +41,8 @@ def reporter_for(*formatters) order = [] formatter = double("formatter").as_null_object - formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" } - formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" } + allow(formatter).to receive(:example_group_started) { |group| order << "Started: #{group.description}" } + allow(formatter).to receive(:example_group_finished) { |group| order << "Finished: #{group.description}" } group = ExampleGroup.describe("root") group.describe("context 1") do @@ -68,8 +68,8 @@ def reporter_for(*formatters) context "given an example group with no examples" do it "does not pass example_group_started or example_group_finished to formatter" do formatter = double("formatter").as_null_object - formatter.should_not_receive(:example_group_started) - formatter.should_not_receive(:example_group_finished) + expect(formatter).not_to receive(:example_group_started) + expect(formatter).not_to receive(:example_group_finished) group = ExampleGroup.describe("root") @@ -84,8 +84,8 @@ def reporter_for(*formatters) reporter = reporter_for(*formatters) formatters.each do |formatter| - formatter. - should_receive(:example_started). + expect(formatter). + to receive(:example_started). with(example) end @@ -117,7 +117,7 @@ def reporter_for(*formatters) end it 'will send notifications when a subscribed event is triggered' do - listener.should_receive(:start).with(42) + expect(listener).to receive(:start).with(42) reporter.start 42 end end @@ -127,10 +127,10 @@ def reporter_for(*formatters) formatter = double(:formatter).as_null_object reporter = reporter_for formatter reporter.start 1 - Time.stub(:now => ::Time.utc(2012, 10, 1)) + allow(Time).to receive_messages(:now => ::Time.utc(2012, 10, 1)) duration = nil - formatter.stub(:dump_summary) do |dur, _, _, _| + allow(formatter).to receive(:dump_summary) do |dur, _, _, _| duration = dur end diff --git a/spec/rspec/core/ruby_project_spec.rb b/spec/rspec/core/ruby_project_spec.rb index c2096b38d2..805614b9f5 100644 --- a/spec/rspec/core/ruby_project_spec.rb +++ b/spec/rspec/core/ruby_project_spec.rb @@ -8,14 +8,14 @@ module Core context "with ancestor containing spec directory" do it "returns ancestor containing the spec directory" do - RubyProject.stub(:ascend_until).and_return('foodir') + allow(RubyProject).to receive(:ascend_until).and_return('foodir') expect(RubyProject.determine_root).to eq("foodir") end end context "without ancestor containing spec directory" do it "returns current working directory" do - RubyProject.stub(:find_first_parent_containing).and_return(nil) + allow(RubyProject).to receive(:find_first_parent_containing).and_return(nil) expect(RubyProject.determine_root).to eq(".") end end diff --git a/spec/rspec/core/runner_spec.rb b/spec/rspec/core/runner_spec.rb index 2cd5a82ff7..923d4af77f 100644 --- a/spec/rspec/core/runner_spec.rb +++ b/spec/rspec/core/runner_spec.rb @@ -6,12 +6,12 @@ module RSpec::Core describe 'invocation' do before do # Simulate invoking the suite like exe/rspec does. - RSpec::Core::Runner.stub(:run) + allow(RSpec::Core::Runner).to receive(:run) RSpec::Core::Runner.invoke end it 'does not autorun after having been invoked' do - RSpec::Core::Runner.should_not_receive(:at_exit) + expect(RSpec::Core::Runner).not_to receive(:at_exit) RSpec::Core::Runner.autorun end @@ -23,19 +23,19 @@ module RSpec::Core describe 'at_exit' do it 'sets an at_exit hook if none is already set' do - RSpec::Core::Runner.stub(:autorun_disabled?).and_return(false) - RSpec::Core::Runner.stub(:installed_at_exit?).and_return(false) - RSpec::Core::Runner.stub(:running_in_drb?).and_return(false) - RSpec::Core::Runner.stub(:invoke) - RSpec::Core::Runner.should_receive(:at_exit) + allow(RSpec::Core::Runner).to receive(:autorun_disabled?).and_return(false) + allow(RSpec::Core::Runner).to receive(:installed_at_exit?).and_return(false) + allow(RSpec::Core::Runner).to receive(:running_in_drb?).and_return(false) + allow(RSpec::Core::Runner).to receive(:invoke) + expect(RSpec::Core::Runner).to receive(:at_exit) RSpec::Core::Runner.autorun end it 'does not set the at_exit hook if it is already set' do - RSpec::Core::Runner.stub(:autorun_disabled?).and_return(false) - RSpec::Core::Runner.stub(:installed_at_exit?).and_return(true) - RSpec::Core::Runner.stub(:running_in_drb?).and_return(false) - RSpec::Core::Runner.should_receive(:at_exit).never + allow(RSpec::Core::Runner).to receive(:autorun_disabled?).and_return(false) + allow(RSpec::Core::Runner).to receive(:installed_at_exit?).and_return(true) + allow(RSpec::Core::Runner).to receive(:running_in_drb?).and_return(false) + expect(RSpec::Core::Runner).to receive(:at_exit).never RSpec::Core::Runner.autorun end end @@ -61,7 +61,7 @@ module RSpec::Core end it "returns false if no drb server is running" do - ::DRb.stub(:current_server).and_raise(::DRb::DRbServerNotFound) + allow(::DRb).to receive(:current_server).and_raise(::DRb::DRbServerNotFound) expect(RSpec::Core::Runner.running_in_drb?).to be_falsey end @@ -94,16 +94,16 @@ module RSpec::Core let(:out) { StringIO.new } it "tells RSpec to reset" do - CommandLine.stub(:new => double.as_null_object) - RSpec.configuration.stub(:files_to_run => [], :warn => nil) - RSpec.should_receive(:reset) + allow(CommandLine).to receive_messages(:new => double.as_null_object) + allow(RSpec.configuration).to receive_messages(:files_to_run => [], :warn => nil) + expect(RSpec).to receive(:reset) RSpec::Core::Runner.run([], err, out) end context "with --drb or -X" do before(:each) do @options = RSpec::Core::ConfigurationOptions.new(%w[--drb --drb-port 8181 --color]) - RSpec::Core::ConfigurationOptions.stub(:new) { @options } + allow(RSpec::Core::ConfigurationOptions).to receive(:new) { @options } end def run_specs @@ -113,9 +113,9 @@ def run_specs context 'and a DRb server is running' do it "builds a DRbCommandLine and runs the specs" do drb_proxy = double(RSpec::Core::DRbCommandLine, :run => true) - drb_proxy.should_receive(:run).with(err, out) + expect(drb_proxy).to receive(:run).with(err, out) - RSpec::Core::DRbCommandLine.should_receive(:new).and_return(drb_proxy) + expect(RSpec::Core::DRbCommandLine).to receive(:new).and_return(drb_proxy) run_specs end @@ -123,12 +123,12 @@ def run_specs context 'and a DRb server is not running' do before(:each) do - RSpec::Core::DRbCommandLine.should_receive(:new).and_raise(DRb::DRbConnError) + expect(RSpec::Core::DRbCommandLine).to receive(:new).and_raise(DRb::DRbConnError) end it "outputs a message" do - RSpec.configuration.stub(:files_to_run) { [] } - err.should_receive(:puts).with( + allow(RSpec.configuration).to receive(:files_to_run) { [] } + expect(err).to receive(:puts).with( "No DRb server is running. Running in local process instead ..." ) run_specs @@ -136,9 +136,9 @@ def run_specs it "builds a CommandLine and runs the specs" do process_proxy = double(RSpec::Core::CommandLine, :run => 0) - process_proxy.should_receive(:run).with(err, out) + expect(process_proxy).to receive(:run).with(err, out) - RSpec::Core::CommandLine.should_receive(:new).and_return(process_proxy) + expect(RSpec::Core::CommandLine).to receive(:new).and_return(process_proxy) run_specs end diff --git a/spec/rspec/core/world_spec.rb b/spec/rspec/core/world_spec.rb index bd9654f1bf..cd8d4386db 100644 --- a/spec/rspec/core/world_spec.rb +++ b/spec/rspec/core/world_spec.rb @@ -85,14 +85,14 @@ module RSpec::Core describe "#announce_filters" do let(:reporter) { double('reporter').as_null_object } - before { world.stub(:reporter) { reporter } } + before { allow(world).to receive(:reporter) { reporter } } context "with no examples" do - before { world.stub(:example_count) { 0 } } + before { allow(world).to receive(:example_count) { 0 } } context "with no filters" do it "announces" do - reporter.should_receive(:message). + expect(reporter).to receive(:message). with("No examples found.") world.announce_filters end @@ -101,7 +101,7 @@ module RSpec::Core context "with an inclusion filter" do it "announces" do configuration.filter_run_including :foo => 'bar' - reporter.should_receive(:message). + expect(reporter).to receive(:message). with(/All examples were filtered out/) world.announce_filters end @@ -109,9 +109,9 @@ module RSpec::Core context "with an inclusion filter and run_all_when_everything_filtered" do it "announces" do - configuration.stub(:run_all_when_everything_filtered?) { true } + allow(configuration).to receive(:run_all_when_everything_filtered?) { true } configuration.filter_run_including :foo => 'bar' - reporter.should_receive(:message). + expect(reporter).to receive(:message). with(/All examples were filtered out/) world.announce_filters end @@ -120,7 +120,7 @@ module RSpec::Core context "with an exclusion filter" do it "announces" do configuration.filter_run_excluding :foo => 'bar' - reporter.should_receive(:message). + expect(reporter).to receive(:message). with(/All examples were filtered out/) world.announce_filters end @@ -128,11 +128,11 @@ module RSpec::Core end context "with examples" do - before { world.stub(:example_count) { 1 } } + before { allow(world).to receive(:example_count) { 1 } } context "with no filters" do it "does not announce" do - reporter.should_not_receive(:message) + expect(reporter).not_to receive(:message) world.announce_filters end end From 9b57e0c92c039fd7ecbf9784032fce63ad581da7 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Tue, 26 Nov 2013 12:47:15 -0800 Subject: [PATCH 2/3] Hand convert a few things transpec could not convert. --- spec/rspec/core/example_spec.rb | 2 +- spec/rspec/core/formatters/base_text_formatter_spec.rb | 2 +- spec/rspec/core/memoized_helpers_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/rspec/core/example_spec.rb b/spec/rspec/core/example_spec.rb index bbde0936b3..e78a723fe2 100644 --- a/spec/rspec/core/example_spec.rb +++ b/spec/rspec/core/example_spec.rb @@ -325,7 +325,7 @@ def run_and_capture_reported_message(group) group = RSpec::Core::ExampleGroup.describe do example do foo = double - foo.should_receive(:bar) + expect(foo).to receive(:bar) raise "boom" end end diff --git a/spec/rspec/core/formatters/base_text_formatter_spec.rb b/spec/rspec/core/formatters/base_text_formatter_spec.rb index 8ef693c62b..028c5deebd 100644 --- a/spec/rspec/core/formatters/base_text_formatter_spec.rb +++ b/spec/rspec/core/formatters/base_text_formatter_spec.rb @@ -196,7 +196,7 @@ def run_all_and_dump_pending context "with a failed message expectation (rspec-mocks)" do it "does not show the error class" do - group.example("example name") { pending { "this".should_receive("that") } } + group.example("example name") { pending { expect("this").to receive("that") } } run_all_and_dump_pending expect(output.string).not_to match(/RSpec/m) end diff --git a/spec/rspec/core/memoized_helpers_spec.rb b/spec/rspec/core/memoized_helpers_spec.rb index 88261e9e94..0dee317f09 100644 --- a/spec/rspec/core/memoized_helpers_spec.rb +++ b/spec/rspec/core/memoized_helpers_spec.rb @@ -73,7 +73,7 @@ def subject_value_for(describe_arg, &block) it "is evaluated once per example" do group = ExampleGroup.describe(Array) group.before do - Object.should_receive(:this_question?).once.and_return(falsy_value) + expect(Object).to receive(:this_question?).once.and_return(falsy_value) end group.subject do Object.this_question? From bf7f49170a76294efc6e930006dfdb0b77568e21 Mon Sep 17 00:00:00 2001 From: Myron Marston Date: Tue, 26 Nov 2013 12:45:10 -0800 Subject: [PATCH 3/3] Enforce the new syntax. --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e83419466a..0468b0df84 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -144,6 +144,10 @@ def without_env_vars(*vars) expectations.syntax = :expect end + c.mock_with :rspec do |mocks| + mocks.syntax = :expect + end + # runtime options c.color = !in_editor? c.filter_run :focus