|
15 | 15 |
|
16 | 16 | it "should default to iptables provider if /sbin/iptables[-save] exists" do
|
17 | 17 | # Stub lookup for /sbin/iptables & /sbin/iptables-save
|
18 |
| - exists.any_instance.stubs(:which).with("iptables"). |
19 |
| - returns "/sbin/iptables" |
20 |
| - exists.any_instance.stubs(:which).with("iptables-save"). |
21 |
| - returns "/sbin/iptables-save" |
| 18 | + allow(exists).to receive(:which).with("iptables"). |
| 19 | + and_return "/sbin/iptables" |
| 20 | + allow(exists).to receive(:which).with("iptables-save"). |
| 21 | + and_return "/sbin/iptables-save" |
22 | 22 |
|
23 | 23 | # Every other command should return false so we don't pick up any
|
24 | 24 | # other providers
|
25 |
| - exists.any_instance.stubs(:which).with() { |value| |
| 25 | + allow(exists).to receive(:which).with() { |value| |
26 | 26 | ! ["iptables","iptables-save"].include?(value)
|
27 |
| - }.returns false |
| 27 | + }.and_return false |
28 | 28 |
|
29 | 29 | # Create a resource instance and make sure the provider is iptables
|
30 | 30 | resource = Puppet::Type.type(:firewall).new({
|
31 | 31 | :name => '000 test foo',
|
32 | 32 | })
|
33 |
| - resource.provider.class.to_s.should == "Puppet::Type::Firewall::ProviderIptables" |
| 33 | + expect(resource.provider.class.to_s).to eq("Puppet::Type::Firewall::ProviderIptables") |
34 | 34 | end
|
35 | 35 | end
|
36 | 36 |
|
|
45 | 45 |
|
46 | 46 | before :each do
|
47 | 47 | Puppet::Type::Firewall.stubs(:defaultprovider).returns provider
|
48 |
| - provider.stubs(:command).with(:iptables_save).returns "/sbin/iptables-save" |
| 48 | + allow(provider).to receive(:command).with(:iptables_save).and_return "/sbin/iptables-save" |
49 | 49 |
|
50 | 50 | # Stub iptables version
|
51 |
| - Facter.fact(:iptables_version).stubs(:value).returns("1.4.2") |
| 51 | + allow(Facter.fact(:iptables_version)).to receive(:value).and_return("1.4.2") |
52 | 52 |
|
53 |
| - Puppet::Util::Execution.stubs(:execute).returns "" |
54 |
| - Puppet::Util.stubs(:which).with("iptables-save"). |
55 |
| - returns "/sbin/iptables-save" |
| 53 | + allow(Puppet::Util::Execution).to receive(:execute).and_return "" |
| 54 | + allow(Puppet::Util).to receive(:which).with("iptables-save"). |
| 55 | + and_return "/sbin/iptables-save" |
56 | 56 | end
|
57 | 57 |
|
58 | 58 | it 'should be able to get a list of existing rules' do
|
59 | 59 | provider.instances.each do |rule|
|
60 |
| - rule.should be_instance_of(provider) |
61 |
| - rule.properties[:provider].to_s.should == provider.name.to_s |
| 60 | + expect(rule).to be_instance_of(provider) |
| 61 | + expect(rule.properties[:provider].to_s).to eq(provider.name.to_s) |
62 | 62 | end
|
63 | 63 | end
|
64 | 64 |
|
65 | 65 | it 'should ignore lines with fatal errors' do
|
66 |
| - Puppet::Util::Execution.stubs(:execute).with(['/sbin/iptables-save']). |
67 |
| - returns("FATAL: Could not load /lib/modules/2.6.18-028stab095.1/modules.dep: No such file or directory") |
| 66 | + allow(Puppet::Util::Execution).to receive(:execute).with(['/sbin/iptables-save']). |
| 67 | + and_return("FATAL: Could not load /lib/modules/2.6.18-028stab095.1/modules.dep: No such file or directory") |
68 | 68 |
|
69 |
| - provider.instances.length.should == 0 |
| 69 | + expect(provider.instances.length).to be_zero |
70 | 70 | end
|
71 | 71 |
|
72 | 72 | # Load in ruby hash for test fixtures.
|
|
80 | 80 | # If this option is enabled, make sure the parameters exactly match
|
81 | 81 | if data[:compare_all] then
|
82 | 82 | it "the parameter hash keys should be the same as returned by rules_to_hash" do
|
83 |
| - resource.keys.should =~ data[:params].keys |
| 83 | + expect(resource.keys).to match_array(data[:params].keys) |
84 | 84 | end
|
85 | 85 | end
|
86 | 86 |
|
|
89 | 89 | it "the parameter '#{param_name.to_s}' should match #{param_value.inspect}" do
|
90 | 90 | # booleans get cludged to string "true"
|
91 | 91 | if param_value == true then
|
92 |
| - resource[param_name].should == "true" |
| 92 | + expect(resource[param_name]).to be_true |
93 | 93 | else
|
94 |
| - resource[param_name].should == data[:params][param_name] |
| 94 | + expect(resource[param_name]).to eq(data[:params][param_name]) |
95 | 95 | end
|
96 | 96 | end
|
97 | 97 | end
|
|
107 | 107 | let(:instance) { provider.new(resource) }
|
108 | 108 |
|
109 | 109 | it 'general_args should be valid' do
|
110 |
| - instance.general_args.flatten.should == data[:args] |
| 110 | + expect(instance.general_args.flatten).to eq(data[:args]) |
111 | 111 | end
|
112 | 112 | end
|
113 | 113 | end
|
|
121 | 121 | let(:instance) { provider.new(resource) }
|
122 | 122 |
|
123 | 123 | it 'rule name contains a MD5 sum of the line' do
|
124 |
| - resource[:name].should == "9000 #{Digest::MD5.hexdigest(resource[:line])}" |
| 124 | + expect(resource[:name]).to eq("9000 #{Digest::MD5.hexdigest(resource[:line])}") |
125 | 125 | end
|
126 | 126 | end
|
127 | 127 |
|
128 | 128 | describe 'when creating resources' do
|
129 | 129 | let(:instance) { provider.new(resource) }
|
130 | 130 |
|
131 | 131 | it 'insert_args should be an array' do
|
132 |
| - instance.insert_args.class.should == Array |
| 132 | + expect(instance.insert_args.class).to eq(Array) |
133 | 133 | end
|
134 | 134 | end
|
135 | 135 |
|
136 | 136 | describe 'when modifying resources' do
|
137 | 137 | let(:instance) { provider.new(resource) }
|
138 | 138 |
|
139 | 139 | it 'update_args should be an array' do
|
140 |
| - instance.update_args.class.should == Array |
| 140 | + expect(instance.update_args.class).to eq(Array) |
141 | 141 | end
|
142 | 142 | end
|
143 | 143 |
|
|
153 | 153 | end
|
154 | 154 |
|
155 | 155 | it 'delete_args is an array' do
|
156 |
| - instance.delete_args.class.should == Array |
| 156 | + expect(instance.delete_args.class).to eq(Array) |
157 | 157 | end
|
158 | 158 |
|
159 | 159 | it 'delete_args is the same as the rule string when joined' do
|
160 |
| - instance.delete_args.join(' ').should == sample_rule.gsub(/\-A/, |
161 |
| - '-t filter -D') |
| 160 | + expect(instance.delete_args.join(' ')).to eq(sample_rule.gsub(/\-A/, |
| 161 | + '-t filter -D')) |
162 | 162 | end
|
163 | 163 | end
|
164 | 164 | end
|
0 commit comments