Class: Compass::Rspec::Menu::HaveMenuItem
- Inherits:
-
Object
- Object
- Compass::Rspec::Menu::HaveMenuItem
- Defined in:
- lib/compass/rspec/menu.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(label, url: nil, badge: nil, icon: nil, tags: nil, authorized: true) ⇒ HaveMenuItem
constructor
A new instance of HaveMenuItem.
- #matches?(menu_item) ⇒ Boolean
-
#with_badge(badge) ⇒ Object
Matches the item badge.
-
#with_icon(icon) ⇒ Object
Matches the item icon.
-
#with_tags(*tags) ⇒ Object
Matches the item tags.
-
#with_url(url) ⇒ Object
Matches the item URL.
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: , badge: badge, icon: icon, tags: } end |
Instance Method Details
#failure_message ⇒ Object
94 95 96 97 98 |
# File 'lib/compass/rspec/menu.rb', line 94 def return @matcher. if @matcher "expected #{@menu_item.label} to have nested item #{@label}" end |
#failure_message_when_negated ⇒ Object
101 102 103 104 105 |
# File 'lib/compass/rspec/menu.rb', line 101 def return @matcher. if @matcher "expected #{@menu_item.label} to not have nested item #{@label}" end |
#matches?(menu_item) ⇒ 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 = matching_label = .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 (*) @attributes[: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 |