Class: ActionPolicy::RSpec::BeAnAliasOf

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/action_policy/rspec/be_an_alias_of.rb

Overview

Policy rule alias matcher ‘be_an_alias_of`.

Verifies that for given policy a policy rule has an alias.

Example:

# in policy specs
subject(:policy) { described_class.new(record, user: user) }

let(:user) { build_stubbed(:user) }
let(:record) { build_stubbed(:post) }

describe "#show?" do
  it "is an alias of :index? policy rule" do
    expect(:show?).to be_an_alias_of(policy, :index?)
  end
end

# negated version
describe "#show?" do
  it "is not an alias of :index? policy rule" do
    expect(:show?).to_not be_an_alias_of(policy, :index?)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policy, rule) ⇒ BeAnAliasOf

Returns a new instance of BeAnAliasOf.



35
36
37
38
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 35

def initialize(policy, rule)
  @policy = policy
  @rule = rule
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



33
34
35
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 33

def actual
  @actual
end

#policyObject (readonly)

Returns the value of attribute policy.



33
34
35
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 33

def policy
  @policy
end

#ruleObject (readonly)

Returns the value of attribute rule.



33
34
35
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 33

def rule
  @rule
end

Instance Method Details

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 44

def does_not_match?(actual)
  @actual = actual
  policy.resolve_rule(actual) != rule
end

#failure_messageObject



51
52
53
54
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 51

def failure_message
  "expected #{policy}##{actual} " \
  "to be an alias of #{policy}##{rule}"
end

#failure_message_when_negatedObject



56
57
58
59
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 56

def failure_message_when_negated
  "expected #{policy}##{actual} " \
  "to not be an alias of #{policy}##{rule}"
end

#match(_expected, actual) ⇒ Object



40
41
42
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 40

def match(_expected, actual)
  policy.resolve_rule(actual) == rule
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


49
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 49

def supports_block_expectations?() = false