rspec-middlewares
A set of helpful middlewares for useage with rspec.
Useage
> gem install rspec-middlewares
In spec-helper.rb
or rails_helper.rb
.
require 'middleware'
require 'rspec-middlewares'
require 'vcr'
Rspec.configure do |config|
config.around(:each) do |test|
stack = Middleware::Builder.new do |builder|
if test.[:timezone].present?
builder.use RspecMiddlewares::Timezone, timezone: test.[:timezone]
end
if test.[:current_time].present?
builder.use RspecMiddlewares::Timecop, current_time: test.[:current_time]
end
if test.[:freeze_time].present?
builder.use RspecMiddlewares::Timecop, freeze_time: test.[:freeze_time]
end
if test.[:record].present?
builder.use RspecMiddlewares::VCR,
cassette_name: test.[:cassette_name],
record: test.[:record],
match_requests_on: test.[:match_requests_on]
end
builder.use TestMiddlewares::Sidekiq if test.[:run_jobs]
builder.use TestMiddlewares::Main
end
stack.call test: test
end
end
Then in your tests
require 'rails_helper'
describe MyTest,
record: :all,
match_requests_on: [:method, :host, :path] do
# each of your tests will now be run with the VCR middleware enabled.
end
Related
https://github.com/Ibsciss/ruby-middleware https://github.com/vcr/vcr