Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change to follow GitLab's testing best practices #16

Merged
merged 1 commit into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
]
end
end
describe "#self.define" do
describe ".define" do
it "should load variables via a given block" do
expect(@plugin.author).to eq("Caleb Anderson")
expect(@plugin.version).to eq("0.3")
Expand Down
14 changes: 3 additions & 11 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
require "vcr"
require "webmock"

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"
Expand All @@ -21,17 +23,7 @@
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
config.include Spec::Support::Helpers
end

VCR.configure do |config|
Expand Down
17 changes: 17 additions & 0 deletions spec/support/helpers/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
10 changes: 4 additions & 6 deletions spec/whatweb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@
it "has a version number" do
expect(subject::VERSION).not_to be nil
end
context "without the aggressive mode" do
describe "#execute_plugins" do
describe ".execute_plugins" do
context "without the aggressive mode" do
it "should return a Hash" do
results = subject.execute_plugins "https://www.webscantest.com"
expect(results).to be_a(Hash)
expect(results.dig("Title").first.dig(:string)).to eq("Test Site")
end
end
end
context "with the aggressive mode" do
describe "#execute_plugins" do
context "with the aggressive mode" do
it "should return a Hash" do
allow_any_instance_of(WhatWeb::Plugin).to receive(:randstr).and_return("fqeewoohxevinxslnplhjbymmeplmkwl")
results = subject.execute_plugins("https://www.webscantest.com", is_aggressive: true)
expect(results).to be_a(Hash)
end
end
end
describe "#plugin_names" do
describe ".plugin_names" do
it "should return an Array " do
array = subject.plugin_names
expect(array).to be_an(Array)
Expand Down