Skip to content

Commit cb08e5b

Browse files
committed
Fix specs
1 parent c33a4a7 commit cb08e5b

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

spec/tools/jsobfu_spec.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'spec_helper'
2+
13
load Metasploit::Framework.root.join('tools/jsobfu.rb').to_path
24

35
require 'stringio'
@@ -19,34 +21,38 @@
1921
end
2022

2123
describe '#run' do
22-
23-
def get_stdout(&block)
24-
out = $stdout
25-
$stdout = fake = StringIO.new
26-
begin
27-
yield
28-
ensure
29-
$stdout = out
30-
end
31-
fake.string
32-
end
33-
3424
let(:default_opts) {
3525
{ :input => fname, :iteration => 1 }
3626
}
3727

3828
before(:each) do
3929
allow(Jsobfu::OptsConsole).to receive(:parse).with(any_args).and_return(default_opts)
4030
allow(File).to receive(:open).with(fname, 'rb').and_yield(StringIO.new(js))
31+
@out = $stdout
32+
$stdout = StringIO.new
33+
$stdout.string = ''
34+
end
35+
36+
after(:each) do
37+
$stdout = @out
4138
end
4239

4340
context 'when a javascript file is given' do
44-
it 'returns the obfuscated version of the js code' do
45-
output = get_stdout { subject.run }
46-
expect(output).to include('String.fromCharCode')
41+
it 'returns an String' do
42+
subject.run
43+
expect($stdout.string).to be_a(String)
44+
end
45+
46+
it 'returns a non empty String' do
47+
subject.run
48+
expect($stdout.string).not_to be_empty
4749
end
48-
end
4950

51+
it 'returns an String different than the original' do
52+
subject.run
53+
expect($stdout.string).not_to eq(js)
54+
end
55+
end
5056
end
5157
end
5258

0 commit comments

Comments
 (0)