Sha256: c9e8f8a23c5c9caf5f2026bd8315998b45d60be0a22099bb165cbf1e23c3fe1b
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true require 'wcc/contentful' require_relative './test' module WCC::Contentful::RSpec include WCC::Contentful::Test::Double include WCC::Contentful::Test::Factory ## # Builds out a fake Contentful entry for the given content type, and then # stubs the Model API to return that content type for `.find` and `.find_by` # query methods. def contentful_stub(content_type, **attrs) const = WCC::Contentful::Model.resolve_constant(content_type.to_s) instance = contentful_create(content_type, **attrs) allow(WCC::Contentful::Model).to receive(:find) .with(instance.id) .and_return(instance) allow(WCC::Contentful::Model).to receive(:find) .with(instance.id, anything) .and_return(instance) allow(const).to receive(:find) { |id, options| WCC::Contentful::Model.find(id, options) } attrs.each do |k, v| allow(const).to receive(:find_by) .with(hash_including(k => v)) .and_return(instance) end instance end end if defined?(RSpec) RSpec.configure do |config| config.include WCC::Contentful::RSpec end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wcc-contentful-0.4.0.pre.rc | lib/wcc/contentful/rspec.rb |
wcc-contentful-0.4.0.pre.beta | lib/wcc/contentful/rspec.rb |