This file is indexed.

/usr/lib/ruby/vendor_ruby/shoulda/matchers/action_controller/assign_to_matcher.rb is in ruby-shoulda-matchers 1.0.0~beta2-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module Shoulda # :nodoc:
  module Matchers
    module ActionController # :nodoc:

      # Ensures that the controller assigned to the named instance variable.
      #
      # Options:
      # * <tt>with_kind_of</tt> - The expected class of the instance variable
      #   being checked.
      # * <tt>with</tt> - The value that should be assigned.
      #
      # Example:
      #
      #   it { should assign_to(:user) }
      #   it { should_not assign_to(:user) }
      #   it { should assign_to(:user).with_kind_of(User) }
      #   it { should assign_to(:user).with(@user) }
      def assign_to(variable)
        AssignToMatcher.new(variable)
      end

      class AssignToMatcher # :nodoc:

        def initialize(variable)
          @variable    = variable.to_s
          @check_value = false
        end

        def with_kind_of(expected_class)
          @expected_class = expected_class
          self
        end

        def with(expected_value = nil, &block)
          @check_value       = true
          @expected_value    = expected_value
          @expectation_block = block
          self
        end

        def matches?(controller)
          @controller = controller
          @expected_value = @context.instance_eval(&@expectation_block) if @expectation_block
          assigned_value? && kind_of_expected_class? && equal_to_expected_value?
        end

        attr_reader :failure_message, :negative_failure_message

        def description
          description = "assign @#{@variable}"
          description << " with a kind of #{@expected_class}" if @expected_class
          description
        end

        def in_context(context)
          @context = context
          self
        end

        private

        def assigned_value?
          if !@controller.instance_variables.map(&:to_s).include?("@#{@variable}")
            @failure_message =
              "Expected action to assign a value for @#{@variable}"
            false
          else
            @negative_failure_message =
              "Didn't expect action to assign a value for @#{@variable}, " <<
              "but it was assigned to #{assigned_value.inspect}"
            true
          end
        end

        def kind_of_expected_class?
          return true unless @expected_class
          if assigned_value.kind_of?(@expected_class)
            @negative_failure_message =
              "Didn't expect action to assign a kind of #{@expected_class} " <<
              "for #{@variable}, but got one anyway"
            true
          else
            @failure_message =
              "Expected action to assign a kind of #{@expected_class} " <<
              "for #{@variable}, but got #{@variable.inspect} " <<
              "(#{@variable.class.name})"
            false
          end
        end

        def equal_to_expected_value?
          return true unless @check_value
          if @expected_value == assigned_value
            @negative_failure_message =
              "Didn't expect action to assign #{@expected_value.inspect} " <<
              "for #{@variable}, but got it anyway"
            true
          else
            @failure_message =
              "Expected action to assign #{@expected_value.inspect} " <<
              "for #{@variable}, but got #{assigned_value.inspect}"
            false
          end
        end

        def assigned_value
          @controller.instance_variable_get("@#{@variable}")
        end

      end

    end
  end
end