Module: Compass::Rspec::Menu

Defined in:
lib/compass/rspec/menu.rb

Overview

Compass::Menu test helper for RSpec

Defined Under Namespace

Classes: HaveMenuItem

Instance Method Summary collapse

Instance Method Details

#have_menu_itemHaveMenuItem

Creates a matcher for menu items, allowing you to assert that a menu item with a given label exists.

I.e.:

menu = ExampleMenu.new

expect(menu).to have_menu_item("Dashboard")
expect(menu).to have_menu_item("Dashboard").with_url("/dashboard")
expect(menu).to have_menu_item("Dashboard").with_icon("fa fa-dashboard")
expect(menu).to have_menu_item("Dashboard").with_tags("tag1", "tag2")
expect(menu).to have_menu_item("Dashboard").with_badge(1)
expect(menu).to(
  have_menu_item("Dashboard")
    .with_badge(1)
    .with_icon("dashboard")
)

The matcher will test whether the given menu/item has a nested authorized item with the given attributes. To match unauthorized items, you can also pass ‘authorized: false` to `have_menu_item`.

I.e.:

menu = ExampleMenu.new
expect(menu).to have_menu_item("Unauthorized Item", authorized: false)

Parameters:

  • label (String)

    the label of the menu item

  • url (String)

    the URL of the menu item

  • badge (String)

    the badge of the menu item

  • icon (String)

    the icon of the menu item

  • tags (Array<String>)

    the tags of the menu item

  • authorized (Boolean)

    whether the menu item is authorized

Returns:



39
40
41
# File 'lib/compass/rspec/menu.rb', line 39

def have_menu_item(...) # rubocop:disable Naming/PredicateName
  HaveMenuItem.new(...)
end