diff --git a/spec/plugin/cert_spec.rb b/spec/plugin/cert_spec.rb index 20486c1..5d2cb1f 100644 --- a/spec/plugin/cert_spec.rb +++ b/spec/plugin/cert_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Cert, :vcr do subject { Ryo::Plugin::Cert } - describe "#discover" do + describe ".discover" do it "should return a Hash" do results = subject.discover "github.com" expect(results).to be_an(Hash) diff --git a/spec/plugin/dir_spec.rb b/spec/plugin/dir_spec.rb index 8f660f9..9d1b3c0 100644 --- a/spec/plugin/dir_spec.rb +++ b/spec/plugin/dir_spec.rb @@ -3,7 +3,7 @@ RSpec.describe Ryo::Plugin::Dir do include_context "http_server" - describe "#discover" do + describe ".discover" do subject { Ryo::Plugin::Dir } it "should return an Array" do results = subject.discover "http://#{host}:#{port}" diff --git a/spec/plugin/dns_spec.rb b/spec/plugin/dns_spec.rb index 97764e2..44f305d 100644 --- a/spec/plugin/dns_spec.rb +++ b/spec/plugin/dns_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::DNS, :vcr do subject { Ryo::Plugin::DNS } - describe "#discover" do + describe ".discover" do it "should return a Hash" do results = subject.discover "https:/www.example.com/" expect(results).to be_an(Hash) diff --git a/spec/plugin/shodan_spec.rb b/spec/plugin/shodan_spec.rb index 45126e0..5fa0a00 100644 --- a/spec/plugin/shodan_spec.rb +++ b/spec/plugin/shodan_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Shodan, :vcr do subject { Ryo::Plugin::Shodan } - describe "#discover" do + describe ".discover" do context "when given a valid API KEY" do it "should return a Hash" do results = subject.discover "1.1.1.1" diff --git a/spec/plugin/subdomain/dnsdumpster_spec.rb b/spec/plugin/subdomain/dnsdumpster_spec.rb index 0a019ae..5074ef8 100644 --- a/spec/plugin/subdomain/dnsdumpster_spec.rb +++ b/spec/plugin/subdomain/dnsdumpster_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Subdomain::DNSDumpster, :vcr do subject { Ryo::Plugin::Subdomain::DNSDumpster } - describe "#discover" do + describe ".discover" do context "when given an existing domain" do it "should return a list of subdomains of a given domain" do subdomains = subject.discover("example.com") diff --git a/spec/plugin/subdomain/findsubdomain_spec.rb b/spec/plugin/subdomain/findsubdomain_spec.rb index eed34dd..cde7e9a 100644 --- a/spec/plugin/subdomain/findsubdomain_spec.rb +++ b/spec/plugin/subdomain/findsubdomain_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Subdomain::FindSubDomains, :vcr do subject { Ryo::Plugin::Subdomain::FindSubDomains } - describe "#discover" do + describe ".discover" do context "when given an existing domain" do it "should return a list of subdomains of a given domain" do subdomains = subject.discover("test.com") diff --git a/spec/plugin/subdomain/subdomain_spec.rb b/spec/plugin/subdomain/subdomain_spec.rb index 73ae847..e8be98f 100644 --- a/spec/plugin/subdomain/subdomain_spec.rb +++ b/spec/plugin/subdomain/subdomain_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Subdomain, :vcr do subject { Ryo::Plugin::Subdomain } - describe "#discover" do + describe ".discover" do context "when given an existing domain" do it "should return a list of subdomains of a given domain" do subdomains = subject.discover("test.com") diff --git a/spec/plugin/tech_spec.rb b/spec/plugin/tech_spec.rb index c055b62..b016b48 100644 --- a/spec/plugin/tech_spec.rb +++ b/spec/plugin/tech_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Tech, :vcr do subject { Ryo::Plugin::Tech } - describe "#discover" do + describe ".discover" do it "should return a Hash" do results = subject.discover "https://www.webscantest.com/" expect(results).to be_an(Hash) diff --git a/spec/plugin/whois_spec.rb b/spec/plugin/whois_spec.rb index 601a27e..158fae2 100644 --- a/spec/plugin/whois_spec.rb +++ b/spec/plugin/whois_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Ryo::Plugin::Whois, :vcr do subject { Ryo::Plugin::Whois } - describe "#discover" do + describe ".discover" do it "should return a Hash" do results = subject.discover "example.com" expect(results).to be_an(Hash) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1d9c9f1..aca8e36 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,15 +1,18 @@ +# frozen_string_literal: true + require "bundler/setup" require 'coveralls' Coveralls.wear! require "dotenv/load" -require "glint" require "vcr" -require "webrick" require "ryo" +require_relative "./support/shared_contexts/http_server_shared_context" +require_relative "./support/helpers/helpers" + RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" @@ -21,55 +24,9 @@ c.syntax = :expect end - 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 -end - -def server - server = Glint::Server.new do |port| - http = WEBrick::HTTPServer.new( - BindAddress: "0.0.0.0", - Port: port, - Logger: WEBrick::Log.new(File.open(File::NULL, "w")), - AccessLog: [] - ) - http.mount_proc("/admin.asp") do |_, res| - body = "test" - - res.status = 200 - res.content_length = body.size - res.content_type = 'text/plain' - res.body = body - end - trap(:INT) { http.shutdown } - trap(:TERM) { http.shutdown } - http.start - end - Glint::Server.info[:http_server] = { - host: "0.0.0.0", - port: server.port - } - server -end - -RSpec.shared_context "http_server" do - before(:all) { - @server = server - @server.start - } - after(:all) { @server.stop } + config.include_context "http_server" - let(:host) { "0.0.0.0" } - let(:port) { @server.port } + config.include Spec::Support::Helpers end VCR.configure do |config| diff --git a/spec/support/helpers/helpers.rb b/spec/support/helpers/helpers.rb new file mode 100644 index 0000000..a3db4b9 --- /dev/null +++ b/spec/support/helpers/helpers.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Spec + module Support + module Helpers + 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 + end + end +end diff --git a/spec/support/shared_contexts/http_server_shared_context.rb b/spec/support/shared_contexts/http_server_shared_context.rb new file mode 100644 index 0000000..2a2ff1d --- /dev/null +++ b/spec/support/shared_contexts/http_server_shared_context.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require "glint" +require "webrick" + +RSpec.shared_context "http_server" do + def server + server = Glint::Server.new do |port| + http = WEBrick::HTTPServer.new( + BindAddress: "0.0.0.0", + Port: port, + Logger: WEBrick::Log.new(File.open(File::NULL, "w")), + AccessLog: [] + ) + http.mount_proc("/admin.asp") do |_, res| + body = "test" + + res.status = 200 + res.content_length = body.size + res.content_type = 'text/plain' + res.body = body + end + trap(:INT) { http.shutdown } + trap(:TERM) { http.shutdown } + http.start + end + Glint::Server.info[:http_server] = { + host: "0.0.0.0", + port: server.port + } + server + end + + before(:all) { + @server = server + @server.start + } + after(:all) { @server.stop } + + let(:host) { "0.0.0.0" } + let(:port) { @server.port } +end