Class: ActionPolicy::RSpec::BeAnAliasOf
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- ActionPolicy::RSpec::BeAnAliasOf
- 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
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #does_not_match?(actual) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(policy, rule) ⇒ BeAnAliasOf
constructor
A new instance of BeAnAliasOf.
- #match(_expected, actual) ⇒ Object
- #supports_block_expectations? ⇒ Boolean
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
#actual ⇒ Object (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 |
#policy ⇒ Object (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 |
#rule ⇒ Object (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
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_message ⇒ Object
51 52 53 54 |
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 51 def "expected #{policy}##{actual} " \ "to be an alias of #{policy}##{rule}" end |
#failure_message_when_negated ⇒ Object
56 57 58 59 |
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 56 def "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
49 |
# File 'lib/action_policy/rspec/be_an_alias_of.rb', line 49 def supports_block_expectations?() = false |