Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
refactor: change to follow the GitLab's testing best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Sep 29, 2018
1 parent 775263f commit 467666c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 74 deletions.
10 changes: 0 additions & 10 deletions spec/helpers.rb

This file was deleted.

71 changes: 7 additions & 64 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,25 @@
require 'coveralls'
Coveralls.wear!

require 'rack/test'

require_relative '../app/config/environment'
require 'helpers'
require_relative "./support/helpers/helpers"

require 'rack/test'
require_relative "./support/shared_contexts/huntup_shared_context"
require_relative "./support/shared_contexts/rackapp_shared_context"
require_relative "./support/shared_contexts/spyup_shared_context"

RSpec.configure do |config|
config.include Rack::Test::Methods
config.include Helpers
config.include Spec::Support::Helpers
config.order = 'default'
config.shared_context_metadata_behavior = :apply_to_host_groups
end

# Suppress STDOUT output
RSpec.configure do |config|
config.before do
allow($stdout).to receive(:puts)
end
end

def app
@app
end

def mock_app(&builder)
@app = Rack::Builder.new(&builder)
end

RSpec.shared_context "rackapp testing", shared_context: :metadata do
before :all do
@spyup_log = StringIO.new
spyup_logger = LogStashLogger.new(type: :io, io: @spyup_log)

@huntup_log = StringIO.new
huntup_logger = LogStashLogger.new(type: :io, io: @huntup_log)

mock_app do
use Rack::SpyUp do |mw|
mw.logger = spyup_logger
end
use Rack::HuntUp do |mw|
mw.logger = huntup_logger
end
run SleepWarm::Application.new
end
end
end

RSpec.shared_context "spyup testing", shared_context: :metadata do
before :all do
@spyup_log = StringIO.new
spyup_logger = LogStashLogger.new(type: :io, io: @spyup_log)

mock_app do
use Rack::SpyUp do |mw|
mw.logger = spyup_logger
end
run SleepWarm::Application.new
end
end
end

RSpec.shared_context "huntup testing", shared_context: :metadata do
before :all do
@huntup_log = StringIO.new
huntup_logger = LogStashLogger.new(type: :io, io: @huntup_log)

mock_app do
use Rack::HuntUp do |mw|
mw.logger = huntup_logger
end
run SleepWarm::Application.new
end
end
end

RSpec.configure do |config|
config.include_context "rackapp testing", include_shared: true
config.include_context "spyup testing", include_shared: true
config.include_context "huntup testing", include_shared: true
Expand Down
22 changes: 22 additions & 0 deletions spec/support/helpers/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "json"

module Spec
module Support
module Helpers
def mock_app(&builder)
@app = Rack::Builder.new(&builder)
end

def app
@app
end

def io_to_queue(io)
io.rewind
io.readlines.map { |line| JSON.parse line }
end
end
end
end
15 changes: 15 additions & 0 deletions spec/support/shared_contexts/huntup_shared_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

RSpec.shared_context "huntup testing", shared_context: :metadata do
before :all do
@huntup_log = StringIO.new
huntup_logger = LogStashLogger.new(type: :io, io: @huntup_log)

mock_app do
use Rack::HuntUp do |mw|
mw.logger = huntup_logger
end
run SleepWarm::Application.new
end
end
end
21 changes: 21 additions & 0 deletions spec/support/shared_contexts/rackapp_shared_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.shared_context "rackapp testing", shared_context: :metadata do
before :all do
@spyup_log = StringIO.new
spyup_logger = LogStashLogger.new(type: :io, io: @spyup_log)

@huntup_log = StringIO.new
huntup_logger = LogStashLogger.new(type: :io, io: @huntup_log)

mock_app do
use Rack::SpyUp do |mw|
mw.logger = spyup_logger
end
use Rack::HuntUp do |mw|
mw.logger = huntup_logger
end
run SleepWarm::Application.new
end
end
end
15 changes: 15 additions & 0 deletions spec/support/shared_contexts/spyup_shared_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

RSpec.shared_context "spyup testing", shared_context: :metadata do
before :all do
@spyup_log = StringIO.new
spyup_logger = LogStashLogger.new(type: :io, io: @spyup_log)

mock_app do
use Rack::SpyUp do |mw|
mw.logger = spyup_logger
end
run SleepWarm::Application.new
end
end
end

0 comments on commit 467666c

Please sign in to comment.