diff options
author | Claire McQuin <claire@getchef.com> | 2014-10-29 15:14:22 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-10-29 15:59:04 -0700 |
commit | 5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch) | |
tree | 14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/shell | |
parent | b92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff) | |
download | chef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz |
Update to RSpec 3.
Diffstat (limited to 'spec/unit/shell')
-rw-r--r-- | spec/unit/shell/model_wrapper_spec.rb | 26 | ||||
-rw-r--r-- | spec/unit/shell/shell_ext_spec.rb | 64 | ||||
-rw-r--r-- | spec/unit/shell/shell_session_spec.rb | 48 |
3 files changed, 69 insertions, 69 deletions
diff --git a/spec/unit/shell/model_wrapper_spec.rb b/spec/unit/shell/model_wrapper_spec.rb index eae3b2b581..d6da2dcffc 100644 --- a/spec/unit/shell/model_wrapper_spec.rb +++ b/spec/unit/shell/model_wrapper_spec.rb @@ -32,12 +32,12 @@ describe Shell::ModelWrapper do end it "uses the explicit model symbol" do - @wrapper.model_symbol.should == :client + expect(@wrapper.model_symbol).to eq(:client) end end it "determines the model symbol from the class name" do - @wrapper.model_symbol.should == :node + expect(@wrapper.model_symbol).to eq(:node) end describe "when listing objects" do @@ -48,16 +48,16 @@ describe Shell::ModelWrapper do @node_2.name("yummy") @server_response = {:node_1 => @node_1, :node_2 => @node_2} @wrapper = Shell::ModelWrapper.new(Chef::Node) - Chef::Node.stub(:list).and_return(@server_response) + allow(Chef::Node).to receive(:list).and_return(@server_response) end it "lists fully inflated objects without the resource IDs" do - @wrapper.all.should have(2).nodes - @wrapper.all.should include(@node_1, @node_2) + expect(@wrapper.all.size).to eq(2) + expect(@wrapper.all).to include(@node_1, @node_2) end it "maps the listed nodes when given a block" do - @wrapper.all {|n| n.name }.sort.reverse.should == %w{yummy sammich} + expect(@wrapper.all {|n| n.name }.sort.reverse).to eq(%w{yummy sammich}) end end @@ -72,23 +72,23 @@ describe Shell::ModelWrapper do # Creating a Chef::Search::Query object tries to read the private key... @searcher = double("Chef::Search::Query #{__FILE__}:#{__LINE__}") - Chef::Search::Query.stub(:new).and_return(@searcher) + allow(Chef::Search::Query).to receive(:new).and_return(@searcher) end it "falls back to listing the objects when the 'query' is :all" do - Chef::Node.stub(:list).and_return(@server_response) - @wrapper.find(:all).should include(@node_1, @node_2) + allow(Chef::Node).to receive(:list).and_return(@server_response) + expect(@wrapper.find(:all)).to include(@node_1, @node_2) end it "searches for objects using the given query string" do - @searcher.should_receive(:search).with(:node, 'name:app*').and_yield(@node_1).and_yield(@node_2) - @wrapper.find("name:app*").should include(@node_1, @node_2) + expect(@searcher).to receive(:search).with(:node, 'name:app*').and_yield(@node_1).and_yield(@node_2) + expect(@wrapper.find("name:app*")).to include(@node_1, @node_2) end it "creates a 'AND'-joined query string from a HASH" do # Hash order woes - @searcher.should_receive(:search).with(:node, 'name:app* AND name:app*').and_yield(@node_1).and_yield(@node_2) - @wrapper.find(:name=>"app*",'name'=>"app*").should include(@node_1, @node_2) + expect(@searcher).to receive(:search).with(:node, 'name:app* AND name:app*').and_yield(@node_1).and_yield(@node_2) + expect(@wrapper.find(:name=>"app*",'name'=>"app*")).to include(@node_1, @node_2) end end diff --git a/spec/unit/shell/shell_ext_spec.rb b/spec/unit/shell/shell_ext_spec.rb index 8485b66d23..9521ae646b 100644 --- a/spec/unit/shell/shell_ext_spec.rb +++ b/spec/unit/shell/shell_ext_spec.rb @@ -23,7 +23,7 @@ describe Shell::Extensions do before do @shell_client = TestableShellSession.instance - Shell.stub(:session).and_return(@shell_client) + allow(Shell).to receive(:session).and_return(@shell_client) @job_manager = TestJobManager.new @root_context = Object.new @root_context.instance_eval(&ObjectTestHarness) @@ -37,98 +37,98 @@ describe Shell::Extensions do irb_context = double("context", :main => target_context_obj) irb_session = double("irb session", :context => irb_context) @job_manager.jobs = [[:thread, irb_session]] - @root_context.stub(:jobs).and_return(@job_manager) + allow(@root_context).to receive(:jobs).and_return(@job_manager) @root_context.ensure_session_select_defined - @root_context.jobs.select_shell_session(target_context_obj).should == irb_session - @root_context.jobs.select_shell_session(:idontexist).should be_nil + expect(@root_context.jobs.select_shell_session(target_context_obj)).to eq(irb_session) + expect(@root_context.jobs.select_shell_session(:idontexist)).to be_nil end it "finds, then switches to a session" do @job_manager.jobs = [] - @root_context.stub(:ensure_session_select_defined) - @root_context.stub(:jobs).and_return(@job_manager) - @job_manager.should_receive(:select_shell_session).and_return(:the_shell_session) - @job_manager.should_receive(:switch).with(:the_shell_session) + allow(@root_context).to receive(:ensure_session_select_defined) + allow(@root_context).to receive(:jobs).and_return(@job_manager) + expect(@job_manager).to receive(:select_shell_session).and_return(:the_shell_session) + expect(@job_manager).to receive(:switch).with(:the_shell_session) @root_context.find_or_create_session_for(:foo) end it "creates a new session if an existing one isn't found" do @job_manager.jobs = [] - @root_context.stub(:jobs).and_return(@job_manager) - @job_manager.stub(:select_shell_session).and_return(nil) - @root_context.should_receive(:irb).with(:foo) + allow(@root_context).to receive(:jobs).and_return(@job_manager) + allow(@job_manager).to receive(:select_shell_session).and_return(nil) + expect(@root_context).to receive(:irb).with(:foo) @root_context.find_or_create_session_for(:foo) end it "switches to recipe context" do - @root_context.should respond_to(:recipe_mode) + expect(@root_context).to respond_to(:recipe_mode) @shell_client.recipe = :monkeyTime - @root_context.should_receive(:find_or_create_session_for).with(:monkeyTime) + expect(@root_context).to receive(:find_or_create_session_for).with(:monkeyTime) @root_context.recipe_mode end it "switches to attribute context" do - @root_context.should respond_to(:attributes_mode) + expect(@root_context).to respond_to(:attributes_mode) @shell_client.node = "monkeyNodeTime" - @root_context.should_receive(:find_or_create_session_for).with("monkeyNodeTime") + expect(@root_context).to receive(:find_or_create_session_for).with("monkeyNodeTime") @root_context.attributes_mode end it "has a help command" do - @root_context.should respond_to(:help) + expect(@root_context).to respond_to(:help) end it "turns irb tracing on and off" do - @root_context.should respond_to(:trace) - @root_context.conf.should_receive(:use_tracer=).with(true) - @root_context.stub(:tracing?) + expect(@root_context).to respond_to(:trace) + expect(@root_context.conf).to receive(:use_tracer=).with(true) + allow(@root_context).to receive(:tracing?) @root_context.tracing :on end it "says if tracing is on or off" do - @root_context.conf.stub(:use_tracer).and_return(true) - @root_context.should_receive(:puts).with("tracing is on") + allow(@root_context.conf).to receive(:use_tracer).and_return(true) + expect(@root_context).to receive(:puts).with("tracing is on") @root_context.tracing? end it "prints node attributes" do node = double("node", :attribute => {:foo => :bar}) @shell_client.node = node - @root_context.should_receive(:pp).with({:foo => :bar}) + expect(@root_context).to receive(:pp).with({:foo => :bar}) @root_context.ohai - @root_context.should_receive(:pp).with(:bar) + expect(@root_context).to receive(:pp).with(:bar) @root_context.ohai(:foo) end it "resets the recipe and reloads ohai data" do - @shell_client.should_receive(:reset!) + expect(@shell_client).to receive(:reset!) @root_context.reset end it "turns irb echo on and off" do - @root_context.conf.should_receive(:echo=).with(true) + expect(@root_context.conf).to receive(:echo=).with(true) @root_context.echo :on end it "says if echo is on or off" do - @root_context.conf.stub(:echo).and_return(true) - @root_context.should_receive(:puts).with("echo is on") + allow(@root_context.conf).to receive(:echo).and_return(true) + expect(@root_context).to receive(:puts).with("echo is on") @root_context.echo? end it "gives access to the stepable iterator" do - Shell::StandAloneSession.instance.stub(:reset!) - Shell.session.stub(:rebuild_context) + allow(Shell::StandAloneSession.instance).to receive(:reset!) + allow(Shell.session).to receive(:rebuild_context) events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(Chef::Node.new, {}, events) run_context.resource_collection.instance_variable_get(:@resource_list).instance_variable_set(:@iterator, :the_iterator) Shell.session.run_context = run_context - @root_context.chef_run.should == :the_iterator + expect(@root_context.chef_run).to eq(:the_iterator) end it "lists directory contents" do entries = %w{. .. someFile} - Dir.should_receive(:entries).with("/tmp").and_return(entries) + expect(Dir).to receive(:entries).with("/tmp").and_return(entries) @root_context.ls "/tmp" end @@ -145,7 +145,7 @@ describe Shell::Extensions do it "gives a list of the resources" do resource = @recipe_object.file("foo") - @recipe_object.should_receive(:pp).with(["file[foo]"]) + expect(@recipe_object).to receive(:pp).with(["file[foo]"]) @recipe_object.resources end diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index f49c9fc805..d72e3fa1bb 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -42,7 +42,7 @@ end describe Shell::ShellSession do it "is a singleton object" do - Shell::ShellSession.should include(Singleton) + expect(Shell::ShellSession).to include(Singleton) end end @@ -66,13 +66,13 @@ describe Shell::ClientSession do @session.instance_variable_set(:@client, @client) @expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, []) - @node.run_list.should_receive(:expand).with(@node.chef_environment).and_return(@expansion) - Chef::REST.should_receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest) + expect(@node.run_list).to receive(:expand).with(@node.chef_environment).and_return(@expansion) + expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(@chef_rest) @session.rebuild_context end it "passes the shell CLI args to the client" do - Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + expect(Chef::Client).to receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) @session.send(:rebuild_node) end @@ -90,30 +90,30 @@ describe Shell::StandAloneSession do end it "has a run_context" do - @session.run_context.should equal(@run_context) + expect(@session.run_context).to equal(@run_context) end it "returns a collection based on it's standalone recipe file" do - @session.resource_collection.should == @recipe.run_context.resource_collection + expect(@session.resource_collection).to eq(@recipe.run_context.resource_collection) end it "gives nil for the definitions (for now)" do - @session.definitions.should be_nil + expect(@session.definitions).to be_nil end it "gives nil for the cookbook_loader" do - @session.cookbook_loader.should be_nil + expect(@session.cookbook_loader).to be_nil end it "runs chef with the standalone recipe" do - @session.stub(:node_built?).and_return(true) - Chef::Log.stub(:level) + allow(@session).to receive(:node_built?).and_return(true) + allow(Chef::Log).to receive(:level) chef_runner = double("Chef::Runner.new", :converge => :converged) # pre-heat resource collection cache @session.resource_collection - Chef::Runner.should_receive(:new).with(@session.recipe.run_context).and_return(chef_runner) - @recipe.run_chef.should == :converged + expect(Chef::Runner).to receive(:new).with(@session.recipe.run_context).and_return(chef_runner) + expect(@recipe.run_chef).to eq(:converged) end it "passes the shell CLI args to the client" do @@ -123,7 +123,7 @@ describe Shell::StandAloneSession do :build_node => true, :register => true, :sync_cookbooks => {}) - Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + expect(Chef::Client).to receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) @session.send(:rebuild_node) end @@ -147,39 +147,39 @@ describe Shell::SoloSession do end it "returns a collection based on it's compilation object and the extra recipe provided by chef-shell" do - @session.stub(:node_built?).and_return(true) + allow(@session).to receive(:node_built?).and_return(true) kitteh = Chef::Resource::Cat.new("keyboard") @recipe.run_context.resource_collection << kitteh - @session.resource_collection.should include(kitteh) + expect(@session.resource_collection).to include(kitteh) end it "returns definitions from its compilation object" do - @session.definitions.should == @run_context.definitions + expect(@session.definitions).to eq(@run_context.definitions) end it "keeps json attribs and passes them to the node for consumption" do @session.node_attributes = {"besnard_lakes" => "are_the_dark_horse"} - @session.node.besnard_lakes.should == "are_the_dark_horse" + expect(@session.node.besnard_lakes).to eq("are_the_dark_horse") #pending "1) keep attribs in an ivar 2) pass them to the node 3) feed them to the node on reset" end it "generates its resource collection from the compiled cookbooks and the ad hoc recipe" do - @session.stub(:node_built?).and_return(true) + allow(@session).to receive(:node_built?).and_return(true) kitteh_cat = Chef::Resource::Cat.new("kitteh") @run_context.resource_collection << kitteh_cat keyboard_cat = Chef::Resource::Cat.new("keyboard_cat") @recipe.run_context.resource_collection << keyboard_cat #@session.rebuild_collection - @session.resource_collection.should include(kitteh_cat, keyboard_cat) + expect(@session.resource_collection).to include(kitteh_cat, keyboard_cat) end it "runs chef with a resource collection from the compiled cookbooks" do - @session.stub(:node_built?).and_return(true) - Chef::Log.stub(:level) + allow(@session).to receive(:node_built?).and_return(true) + allow(Chef::Log).to receive(:level) chef_runner = double("Chef::Runner.new", :converge => :converged) - Chef::Runner.should_receive(:new).with(an_instance_of(Chef::RunContext)).and_return(chef_runner) + expect(Chef::Runner).to receive(:new).with(an_instance_of(Chef::RunContext)).and_return(chef_runner) - @recipe.run_chef.should == :converged + expect(@recipe.run_chef).to eq(:converged) end it "passes the shell CLI args to the client" do @@ -189,7 +189,7 @@ describe Shell::SoloSession do :build_node => true, :register => true, :sync_cookbooks => {}) - Chef::Client.should_receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) + expect(Chef::Client).to receive(:new).with(nil, Chef::Config[:shell_config]).and_return(@client) @session.send(:rebuild_node) end |