PageRenderTime 34ms CodeModel.GetById 15ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/spec/lib/msf/core/data_store_spec.rb

https://github.com/debbiemezyene/metasploit-framework
Ruby | 79 lines | 65 code | 12 blank | 2 comment | 11 complexity | 17813279df7515ddad09022162187d97 MD5 | raw file
 1# -*- coding:binary -*-
 2
 3require 'spec_helper'
 4require 'msf/core/data_store'
 5
 6shared_examples "datastore" do
 7  it "should have options" do
 8    subject["foo"].should == "bar"
 9    subject["fizz"].should == "buzz"
10  end
11  it "should have case-insensitive keys" do
12    # Sorted by gray code, just for fun
13    subject["foo"].should == "bar"
14    subject["Foo"].should == "bar"
15    subject["FOo"].should == "bar"
16    subject["fOo"].should == "bar"
17    subject["fOO"].should == "bar"
18    subject["FOO"].should == "bar"
19    subject["FoO"].should == "bar"
20    subject["foO"].should == "bar"
21  end
22  context "#to_h" do
23    it "should return a Hash with correct values" do
24      subject.to_h.should == { "foo" => "bar", "fizz" => "buzz" }
25    end
26  end
27end
28
29describe Msf::DataStore do
30
31  describe "#import_option" do
32    subject do
33      s = described_class.new
34      s.import_option("foo", "bar")
35      s.import_option("fizz", "buzz")
36      s
37    end
38    it_behaves_like "datastore"
39  end
40
41  describe "#import_options_from_hash" do
42    subject do
43      hash = { "foo" => "bar", "fizz" => "buzz" }
44      s = described_class.new
45      s.import_options_from_hash(hash)
46      s
47    end
48    it_behaves_like "datastore"
49  end
50
51  describe "#import_options_from_s" do
52    subject do
53      str = "foo=bar fizz=buzz"
54      s = described_class.new
55      s.import_options_from_s(str)
56      s
57    end
58    it_behaves_like "datastore"
59  end
60
61  describe "#from_file" do
62    subject do
63      ini_instance = double
64      ini_instance.stub(:group?).and_return(true)
65      ini_instance.stub(:[]).and_return( { "foo" => "bar", "fizz" => "buzz" } )
66
67      ini = stub_const("Rex::Parser::Ini", Class.new)
68      ini.stub(:from_file).and_return(ini_instance)
69
70      s = described_class.new
71      s.from_file("path")
72      s
73    end
74
75    it_behaves_like "datastore"
76  end
77
78
79end