Sha256: c5ba8c10acf2ac2c18193a8a5bd34e6e88f4df5b16d78f0b0e7222b3115f8e7b

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

require 'rspec/expectations'

module Arrthorizer
  module RSpec
    module Matchers
      module Roles
        class AppliesToUser
          def initialize(user)
            @user = user
          end

          def matches?(role)
            @role = role

            role.applies_to_user?(user, context)
          end

          def failure_message
            "Expected role #{@role.name} to apply in context #{context.inspect}\nfor user #{user.inspect}, but it does not apply!"
          end

          def negative_failure_message
            "Expected role #{@role.name} not to apply in context #{context.inspect}\nfor user #{user.inspect}, but it applies!"
          end

          def with_context(hash)
            @context = to_context(hash)

            self
          end

        protected
          attr_accessor :context, :user

          def to_context(context_hash)
            Arrthorizer::Context.new(context_hash)
          end
        end

        def apply_to_user(user, context = {})
          AppliesToUser.new(user).with_context(context)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
arrthorizer-0.4.1 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.3.2 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.3.1 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.3.0 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.2.1 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.2.0 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.1.3 lib/arrthorizer/rspec/matchers.rb
arrthorizer-0.1.2 lib/arrthorizer/rspec/matchers.rb