Class: Compass::Rspec::Menu::HaveMenuItem

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

Instance Method Summary collapse

Constructor Details

#initialize(label, url: nil, badge: nil, icon: nil, tags: nil, authorized: true) ⇒ HaveMenuItem

Returns a new instance of HaveMenuItem.



44
45
46
47
48
49
50
51
52
53
# File 'lib/compass/rspec/menu.rb', line 44

def initialize(label, url: nil, badge: nil, icon: nil, tags: nil, authorized: true)
  @label = label
  @attributes = {
    url: url,
    authorized: authorized,
    badge: badge,
    icon: icon,
    tags: tags
  }
end

Instance Method Details

#failure_messageObject



94
95
96
97
98
# File 'lib/compass/rspec/menu.rb', line 94

def failure_message
  return @matcher.failure_message if @matcher

  "expected #{@menu_item.label} to have nested item #{@label}"
end

#failure_message_when_negatedObject



101
102
103
104
105
# File 'lib/compass/rspec/menu.rb', line 101

def failure_message_when_negated
  return @matcher.failure_message_when_negated if @matcher

  "expected #{@menu_item.label} to not have nested item #{@label}"
end

#matches?(menu_item) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/compass/rspec/menu.rb', line 55

def matches?(menu_item)
  @menu_item = menu_item
  matching_label = menu_item.items.find do |item|
    item.label == @label
  end
  if matching_label
    @matcher = RSpec::Matchers::BuiltIn::HaveAttributes.new(@attributes.compact)
    def @matcher.actual_formatted = @actual.label.inspect
    @matcher.matches?(matching_label)
  else
    false
  end
end

#with_badge(badge) ⇒ Object

Matches the item badge



88
89
90
91
# File 'lib/compass/rspec/menu.rb', line 88

def with_badge(badge)
  @attributes[:badge] = badge
  self
end

#with_icon(icon) ⇒ Object

Matches the item icon



76
77
78
79
# File 'lib/compass/rspec/menu.rb', line 76

def with_icon(icon)
  @attributes[:icon] = icon
  self
end

#with_tags(*tags) ⇒ Object

Matches the item tags



82
83
84
85
# File 'lib/compass/rspec/menu.rb', line 82

def with_tags(*tags)
  @attributes[:tags] = tags.flatten
  self
end

#with_url(url) ⇒ Object

Matches the item URL



70
71
72
73
# File 'lib/compass/rspec/menu.rb', line 70

def with_url(url)
  @attributes[:url] = url
  self
end