Class: Caffeinate::RSpec::Matchers::SubscribeToCaffeinateCampaign

Inherits:
Object
  • Object
show all
Defined in:
lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_campaign, subscriber, **args) ⇒ SubscribeToCaffeinateCampaign

Returns a new instance of SubscribeToCaffeinateCampaign.



17
18
19
20
21
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 17

def initialize(expected_campaign, subscriber, **args)
  @expected_campaign = expected_campaign
  @subscriber = subscriber
  @args = args
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 23

def description
  "subscribe #{who} to the \"Campaign##{@expected_campaign.slug}\" campaign"
end

#failure_messageObject



27
28
29
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 27

def failure_message
  "expected #{who} to subscribe to the \"Campaign##{@expected_campaign.slug}\" campaign but didn't"
end

#failure_message_when_negatedObject



41
42
43
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 41

def failure_message_when_negated
  "expected #{who} to not subscribe to the \"Campaign##{@expected_campaign.slug}\" campaign but did"
end

#matches?(block) ⇒ Boolean

Checks whether the block results in a subscription to the expected campaign.

Parameters:

  • block (Block)

    The block of code to execute.

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 34

def matches?(block)
  return false if @expected_campaign.caffeinate_campaign_subscriptions.active.exists?(subscriber: @subscriber, **@args)

  block.call
  @expected_campaign.caffeinate_campaign_subscriptions.active.exists?(subscriber: @subscriber, **@args)
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/caffeinate/rspec/matchers/subscribe_to_caffeinate_campaign.rb', line 45

def supports_block_expectations?
  true
end