<commit_before>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:
        attr_reader :failure_message_for_should, :failure_message_for_should_not

        def initialize(variable)
          @variable    = variable.to_s
          @options = {}
          @options[:check_value] = false
        end

        def with_kind_of(expected_class)
          @options[:expected_class] = expected_class
          self
        end

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

        def matches?(controller)
          @controller = controller
          normalize_expected_value!
          assigned_value? &&
            kind_of_expected_class? &&
            equal_to_expected_value?
        end

        def description
          description = "assign @#{@variable}"
          if @options.key?(:expected_class)
            description << " with a kind of #{@options[:expected_class]}"
          end
          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_for_should_not =
              "Didn't expect action to assign a value for @#{@variable}, " <<
              "but it was assigned to #{assigned_value.inspect}"
            true
          else
            @failure_message_for_should =
              "Expected action to assign a value for @#{@variable}"
            false
          end
        end

        def kind_of_expected_class?
          if @options.key?(:expected_class)
            if assigned_value.kind_of?(@options[:expected_class])
              @failure_message_for_should_not =
                "Didn't expect action to assign a kind of #{@options[:expected_class]} " <<
                "for #{@variable}, but got one anyway"
              true
            else
              @failure_message_for_should =
                "Expected action to assign a kind of #{@options[:expected_class]} " <<
                "for #{@variable}, but got #{assigned_value.inspect} " <<
                "(#{assigned_value.class.name})"
              false
            end
          else
            true
          end
        end

        def equal_to_expected_value?
          if @options[:check_value]
            if @options[:expected_value] == assigned_value
              @failure_message_for_should_not =
                "Didn't expect action to assign #{@options[:expected_value].inspect} " <<
                "for #{@variable}, but got it anyway"
              true
            else
              @failure_message_for_should =
                "Expected action to assign #{@options[:expected_value].inspect} " <<
                "for #{@variable}, but got #{assigned_value.inspect}"
              false
            end
          else
            true
          end
        end

        def normalize_expected_value!
          if @options[:expectation_block]
            @options[:expected_value] = @context.instance_eval(&@options[:expectation_block])
          end
        end

        def assigned_value
          @controller.instance_variable_get("@#{@variable}")
        end
      end
    end
  end
end<commit_msg>Update to RSpec 3 syntax.<commit_after>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:
        attr_reader :failure_message, :failure_message_when_negated

        def initialize(variable)
          @variable    = variable.to_s
          @options = {}
          @options[:check_value] = false
        end

        def with_kind_of(expected_class)
          @options[:expected_class] = expected_class
          self
        end

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

        def matches?(controller)
          @controller = controller
          normalize_expected_value!
          assigned_value? &&
            kind_of_expected_class? &&
            equal_to_expected_value?
        end

        def description
          description = "assign @#{@variable}"
          if @options.key?(:expected_class)
            description << " with a kind of #{@options[:expected_class]}"
          end
          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_when_negated =
              "Didn't expect action to assign a value for @#{@variable}, " <<
              "but it was assigned to #{assigned_value.inspect}"
            true
          else
            @failure_message =
              "Expected action to assign a value for @#{@variable}"
            false
          end
        end

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

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

        def normalize_expected_value!
          if @options[:expectation_block]
            @options[:expected_value] = @context.instance_eval(&@options[:expectation_block])
          end
        end

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

{'fraction_non_alphanumeric': 0.09138251704897705, 'fraction_numerical': 0.00012399256044637322, 'mean_word_length': 1.7370206990159485, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5215106', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2098, 'n_words': 505}