Class: Inertia::RSpec::TestResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia/rspec.rb

Overview

Wraps an Inertia response for test assertions.

Examples:

Accessing response data

require "inertia/rspec"

RSpec.describe UsersController, type: :request do
  it "renders user posts" do
    get "posts"

    expect(inertia.component).to eq("Posts/Index")
    expect(inertia.props).to have_key(:posts)
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ TestResponse

Returns a new instance of TestResponse.

Parameters:

  • data (Hash)

    the raw Inertia response data



22
23
24
# File 'lib/inertia/rspec.rb', line 22

def initialize(data)
  @data = data
end

Instance Method Details

#componentString

Returns the component name.

Returns:

  • (String)

    the Inertia component name



37
38
39
# File 'lib/inertia/rspec.rb', line 37

def component
  @data[:component]
end

#deferred_propsHash

Returns the deferred props configuration.

Returns:

  • (Hash)

    the deferred props, or an empty hash if none



44
45
46
# File 'lib/inertia/rspec.rb', line 44

def deferred_props
  @data[:deferredProps] || {}
end

#propsHash{Symbol => Object}

Note:

To comply with the Inertia protocol, props always include the errors object.

Returns the props with symbolized keys.

Returns:

  • (Hash{Symbol => Object})

    the props hash



30
31
32
# File 'lib/inertia/rspec.rb', line 30

def props
  sybmolize_keys(@data[:props])
end