Module: Wayfinding::RSpecHelpers

Defined in:
lib/wayfinding/rspec.rb

Overview

Spec helpers for applications consuming Wayfinding.

require "wayfinding/rspec"

Each example runs inside Wayfinding.preserve!, so destinations registered in a spec are rolled back afterwards. Use #stub_destination rather than mocking Wayfinding itself.

Instance Method Summary collapse

Instance Method Details

#stub_destination(name, path = nil, **attributes, &resolver) ⇒ Object

Register a destination that resolves to a fixed value, with no engine or route helpers involved.

stub_destination(:home, "/homes/1")
stub_destination(:home) { |home| "/homes/#{home.id}" }


19
20
21
22
23
# File 'lib/wayfinding/rspec.rb', line 19

def stub_destination(name, path = nil, **attributes, &resolver)
  resolver ||= proc { |*, **| path }

  Wayfinding.register(name: name, **attributes, &resolver)
end