Sha256: 5dc6023dcf0bbc06addbd184ace7e0c6cf9d999417d84e23e4c98bb9196bd1bd
Contents?: true
Size: 1.6 KB
Versions: 1
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true module Receptacle module TestSupport # provides helpful method to toggle strategies during testing # # can be used in rspec like this # # require 'receptacle/test_support'y # RSpec.configure do |c| # c.include Receptacle::TestSupport # end # # RSpec.describe(UserRepository) do # around do |example| # with_strategy(strategy){example.run} # end # let(:strategy) { UserRepository::Strategy::MySQL } # ... # end # # or similar with minitest # # require 'receptacle/test_support' # class UserRepositoryTest < Minitest::Test # def described_class # UserRepository # end # def repo_exists(strategy) # with_strategy(strategy) do # assert described_class.exists(id: 5) # end # end # def test_mysql # repo_exists(UserRepository::Strategy::MySQL) # end # def test_fake # repo_exists(UserRepository::Strategy::Fake) # end # end def with_strategy(strategy, repo = described_class) original_strategy = repo.strategy repo.strategy strategy yield repo.strategy original_strategy end # rspec mocks/stubs don't like the lazy defined delegate methods use this to # make sure the methods are already defined def ensure_method_delegators(repo) Receptacle::Registration.repositories[repo].methods.each do |method_name| repo.__build_method(method_name) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
receptacle-0.1.1 | lib/receptacle/test_support.rb |