Simplify get/getg rspec

bug/bundler_fix
Jon Hart 2015-01-16 09:48:24 -08:00
parent c6121f0a37
commit e7566944df
No known key found for this signature in database
GPG Key ID: 2FA9F0A3AFA8E9D3
1 changed files with 32 additions and 79 deletions

View File

@ -99,65 +99,37 @@ describe Msf::Ui::Console::CommandDispatcher::Core do
it { is_expected.to respond_to :cmd_get } it { is_expected.to respond_to :cmd_get }
it { is_expected.to respond_to :cmd_getg } it { is_expected.to respond_to :cmd_getg }
describe "#cmd_get" do def set_and_test_variable(name, framework_value, module_value, framework_re, module_re)
describe "without arguments" do # set the current module
it "should show a help message" do allow(core).to receive(:active_module).and_return(mod)
core.cmd_get # always assume set variables validate (largely irrelevant because ours are random)
@output.join.should =~ /Usage: get / allow(driver).to receive(:on_variable_set).and_return(true)
end # the specified global value
core.cmd_setg(name, framework_value) if framework_value
# set the specified local value
core.cmd_set(name, module_value) if module_value
# test the global value if specified
if framework_re
@output = []
core.cmd_getg(name)
@output.join.should =~ framework_re
end end
describe "with arguments" do # test the local value if specified
let(:name) { ::Rex::Text.rand_text_alpha(10).upcase } if module_re
@output = []
context "with an active module" do core.cmd_get(name)
let(:mod) do @output.join.should =~ module_re
mod = ::Msf::Module.new
mod.send(:initialize, {})
mod
end
it "should show no value if not set in the framework or module" do
allow(core).to receive(:active_module).and_return(mod)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_get(name)
@output.join.should =~ /^#{name} => $/
end
it "should show no value when only the framework has this variable" do
allow(core).to receive(:active_module).and_return(mod)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_setg(name, 'FRAMEWORK')
@output = []
core.cmd_get(name)
@output.join.should =~ /^#{name} => $/
end
it "should show the module's value when only the module has this variable" do
allow(core).to receive(:active_module).and_return(mod)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_set(name, 'MODULE')
@output = []
core.cmd_get(name)
@output.join.should =~ /^#{name} => MODULE$/
end
it "should show the module's value when both the module and the framework have this variable" do
allow(core).to receive(:active_module).and_return(mod)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_setg(name, 'FRAMEWORK')
core.cmd_set(name, 'MODULE')
@output = []
core.cmd_get(name)
@output.join.should =~ /^#{name} => MODULE$/
end
end
end end
end end
describe "#cmd_getg" do describe "#cmd_get and #cmd_getg" do
describe "without arguments" do describe "without arguments" do
it "should show a help message" do it "should show the correct help message" do
core.cmd_get
@output.join.should =~ /Usage: get /
@output = []
core.cmd_getg core.cmd_getg
@output.join.should =~ /Usage: getg / @output.join.should =~ /Usage: getg /
end end
@ -174,38 +146,19 @@ describe Msf::Ui::Console::CommandDispatcher::Core do
end end
it "should show no value if not set in the framework or module" do it "should show no value if not set in the framework or module" do
allow(core).to receive(:active_module).and_return(mod) set_and_test_variable(name, nil, nil, /^#{name} => $/, /^#{name} => $/)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_getg(name)
@output.join.should =~ /^#{name} => $/
end end
it "should show no value when only the module has this variable" do it "should show the correct value when only the module has this variable" do
allow(core).to receive(:active_module).and_return(mod) set_and_test_variable(name, nil, 'MODULE', /^#{name} => $/, /^#{name} => MODULE$/)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_set(name, 'MODULE')
@output = []
core.cmd_getg(name)
@output.join.should =~ /^#{name} => $/
end end
it "should show the framework's value when only the framework has this variable" do it "should show the correct value when only the framework has this variable" do
allow(core).to receive(:active_module).and_return(mod) set_and_test_variable(name, 'FRAMEWORK', nil, /^#{name} => FRAMEWORK$/, /^#{name} => $/)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_setg(name, 'FRAMEWORK')
@output = []
core.cmd_getg(name)
@output.join.should =~ /^#{name} => FRAMEWORK$/
end end
it "should show the framework's value when both the module and the framework have this variable" do it "should show the correct value when both the module and the framework have this variable" do
allow(core).to receive(:active_module).and_return(mod) set_and_test_variable(name, 'FRAMEWORK', 'MODULE', /^#{name} => FRAMEWORK$/, /^#{name} => MODULE$/)
allow(driver).to receive(:on_variable_set).and_return(true)
core.cmd_setg(name, 'FRAMEWORK')
core.cmd_set(name, 'MODULE')
@output = []
core.cmd_getg(name)
@output.join.should =~ /^#{name} => FRAMEWORK$/
end end
end end
end end