Skip to content

Commit

Permalink
test: change to follow GitLab's testing best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Sep 30, 2018
1 parent 052cd81 commit 1aaa08c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
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

0 comments on commit 1aaa08c

Please sign in to comment.