diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-09-01 11:44:03 -0700 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-09-01 11:45:57 -0700 |
commit | 738945562bc3b7884b45b71dc0302050d96f897f (patch) | |
tree | 152aaac21e0954271d74dd4bfe24f25ec95e0a3c | |
parent | 1375318db8d92f88f4c5814bb31b9252d445bc7c (diff) | |
download | chef-738945562bc3b7884b45b71dc0302050d96f897f.tar.gz |
Move code to where it is used and remove top level constants.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r-- | spec/unit/shell/shell_ext_spec.rb | 49 | ||||
-rw-r--r-- | spec/unit/shell/shell_session_spec.rb | 22 | ||||
-rw-r--r-- | spec/unit/shell_spec.rb | 35 |
3 files changed, 62 insertions, 44 deletions
diff --git a/spec/unit/shell/shell_ext_spec.rb b/spec/unit/shell/shell_ext_spec.rb index aca88df500..b2f32efb6a 100644 --- a/spec/unit/shell/shell_ext_spec.rb +++ b/spec/unit/shell/shell_ext_spec.rb @@ -19,14 +19,57 @@ require "spec_helper" describe Shell::Extensions do + let(:test_shell_session) do + Class.new(Shell::ShellSession) do + def rebuild_node + nil + end + + def rebuild_collection + nil + end + + def loading + nil + end + + def loading_complete + nil + end + end + end + + let(:test_job_manager) do + Class.new do + attr_accessor :jobs + end + end + + let(:object_test_harness) do + Proc.new do + extend Shell::Extensions::ObjectCoreExtensions + + def conf=(new_conf) + @conf = new_conf + end + + def conf + @conf + end + + desc "rspecin'" + def rspec_method; end + end + end + describe "extending object for top level methods" do before do - @shell_client = TestableShellSession.instance + @shell_client = test_shell_session.instance allow(Shell).to receive(:session).and_return(@shell_client) - @job_manager = TestJobManager.new + @job_manager = test_job_manager.new @root_context = Object.new - @root_context.instance_eval(&ObjectTestHarness) + @root_context.instance_eval(&object_test_harness) Shell::Extensions.extend_context_object(@root_context) @root_context.conf = double("irbconf") end diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index c98989491d..55a8c89cd0 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -18,32 +18,10 @@ require "spec_helper" require "ostruct" -class TestableShellSession < Shell::ShellSession - - def rebuild_node - nil - end - - def rebuild_collection - nil - end - - def loading - nil - end - - def loading_complete - nil - end - -end - describe Shell::ShellSession do - it "is a singleton object" do expect(Shell::ShellSession).to include(Singleton) end - end describe Shell::ClientSession do diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 6dba848084..18b622698e 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -18,26 +18,23 @@ require "spec_helper" require "ostruct" -ObjectTestHarness = Proc.new do - extend Shell::Extensions::ObjectCoreExtensions - - def conf=(new_conf) - @conf = new_conf - end - - def conf - @conf - end +describe Shell do + let(:object_test_harness) do + Proc.new do + extend Shell::Extensions::ObjectCoreExtensions - desc "rspecin'" - def rspec_method; end -end + def conf=(new_conf) + @conf = new_conf + end -class TestJobManager - attr_accessor :jobs -end + def conf + @conf + end -describe Shell do + desc "rspecin'" + def rspec_method; end + end + end before do Shell.irb_conf = {} @@ -66,7 +63,7 @@ describe Shell do conf = OpenStruct.new conf.main = Object.new - conf.main.instance_eval(&ObjectTestHarness) + conf.main.instance_eval(&object_test_harness) Shell.irb_conf[:IRB_RC].call(conf) expect(conf.prompt_c).to eq("chef > ") expect(conf.return_format).to eq(" => %s \n") @@ -107,7 +104,7 @@ describe Shell do before do @chef_object = Object.new - @chef_object.instance_eval(&ObjectTestHarness) + @chef_object.instance_eval(&object_test_harness) end it "creates help text for methods with descriptions" do |