Class: RSpec::Matchers::BuiltIn::AbleToMatcher

Inherits:
Be
  • Object
show all
Defined in:
lib/bali/rspec/able_to_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation, class_or_record = nil) ⇒ AbleToMatcher

Returns a new instance of AbleToMatcher.



5
6
7
8
# File 'lib/bali/rspec/able_to_matcher.rb', line 5

def initialize(operation, class_or_record = nil)
  @operation = operation
  @class_or_record = class_or_record
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/bali/rspec/able_to_matcher.rb', line 29

def description
  "be able to #{@operation}"
end

#failure_messageObject



21
22
23
# File 'lib/bali/rspec/able_to_matcher.rb', line 21

def failure_message
  "expected to be able to #{@operation}, but actually cannot"
end

#failure_message_when_negatedObject



25
26
27
# File 'lib/bali/rspec/able_to_matcher.rb', line 25

def failure_message_when_negated
  "expected not to be able to #{@operation}, but actually can"
end

#matches?(actor) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
# File 'lib/bali/rspec/able_to_matcher.rb', line 10

def matches?(actor)
  if @class_or_record
    rule_class = "#{@class_or_record.class.name}#{Bali.config.suffix}".constantize
    rule_class.can?(actor, @operation, @class_or_record)
  else
    @class_or_record = actor
    rule_class = "#{@class_or_record.name}#{Bali.config.suffix}".constantize
    rule_class.can?(nil, @operation, @class_or_record)
  end
end