Skip to content

Commit

Permalink
test: add CLI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Jul 9, 2019
1 parent 948715d commit 02c96a0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

RSpec.describe RogueOne::CLI do
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end
result
end

describe "#report" do
let(:mock) { double("detector") }
let(:report) { { "verdict" => "benign one", "landing_pages" => [] } }

before do
allow(mock).to receive(:report).and_return(report)
allow(RogueOne::Detector).to receive(:new).and_return(mock)
end

it do
stdout = capture(:stdout) { described_class.start %w(report 1.1.1.1) }
json = JSON.parse(stdout)
expect(json).to eq(report)
end

context "with ping error" do
before do
allow(RogueOne::Ping).to receive(:pong?).and_raise("error")
end

it do
stdout = capture(:stdout) { described_class.start %w(report 1.1.1.1) }
json = JSON.parse(stdout)
expect(json).to eq("error" => "error")
end
end
end
end

0 comments on commit 02c96a0

Please sign in to comment.