Module: Quo::Rspec::Helpers

Includes:
Testing::FakeHelpers
Defined in:
lib/quo/rspec/helpers.rb,
sig/generated/quo/rspec/helpers.rbs

Overview

Test helpers for stubbing query objects in RSpec

Instance Method Summary collapse

Methods included from Testing::FakeHelpers

#build_fake_class

Instance Method Details

#fake_query(query_class, with: nil, results: [], total_count: nil, page_count: nil, &block) ⇒ void

This method returns an undefined value.

Parameters:

  • query_class (Object)
  • with: (Object) (defaults to: nil)
  • results: (Object) (defaults to: [])
  • total_count: (Object) (defaults to: nil)
  • page_count: (Object) (defaults to: nil)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quo/rspec/helpers.rb', line 15

def fake_query(query_class, with: nil, results: [], total_count: nil, page_count: nil, &block)
  unless query_class < Quo::Query
    raise ArgumentError, "Not a Query class: #{query_class}"
  end

  klass = build_fake_class(query_class)
  fake = ->(*kwargs) {
    klass.new(results: results, total_count: total_count, page_count: page_count)
  }
  expectation = allow(query_class).to receive(:new)
  expectation = expectation.with(with) if with
  expectation.and_invoke(fake)
end