Class: RSpec::Matchers::BuiltIn::ThrowSymbol Private

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation for ‘throw_symbol`. Not intended to be instantiated directly.

Instance Method Summary collapse

Methods included from Composable

#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?

Constructor Details

#initialize(expected_symbol = nil, expected_arg = nil) ⇒ ThrowSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ThrowSymbol.



10
11
12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 10

def initialize(expected_symbol=nil, expected_arg=nil)
  @expected_symbol = expected_symbol
  @expected_arg = expected_arg
  @caught_symbol = @caught_arg = nil
end

Instance Method Details

#descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



86
87
88
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 86

def description
  "throw #{expected}"
end

#does_not_match?(given_proc) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/MethodLength

Returns:

  • (Boolean)


68
69
70
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 68

def does_not_match?(given_proc)
  !matches?(given_proc) && Proc === given_proc
end

#expects_call_stack_jump?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


103
104
105
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 103

def expects_call_stack_jump?
  true
end

#failure_messageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



74
75
76
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 74

def failure_message
  "expected #{expected} to be thrown, #{actual_result}"
end

#failure_message_when_negatedString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



80
81
82
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 80

def failure_message_when_negated
  "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, #{actual_result}"
end

#matches?(given_proc) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength

Returns:

  • (Boolean)


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
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 18

def matches?(given_proc)
  @block = given_proc
  return false unless Proc === given_proc

  begin
    if @expected_symbol.nil?
      given_proc.call
    else
      @caught_arg = catch :proc_did_not_throw_anything do
        catch @expected_symbol do
          given_proc.call
          throw :proc_did_not_throw_anything, :nothing_thrown
        end
      end

      if @caught_arg == :nothing_thrown
        @caught_arg = nil
      else
        @caught_symbol = @expected_symbol
      end
    end

    # Ruby 1.8 uses NameError with `symbol'
    # Ruby 1.9 uses ArgumentError with :symbol
  rescue NameError, ArgumentError => e
    unless (match_data = e.message.match(/uncaught throw (`|\:)([a-zA-Z0-9_]*)(')?/))
      other_exception = e
      raise
    end
    @caught_symbol = match_data.captures[1].to_sym
  rescue => other_exception
    raise
  ensure
    # rubocop:disable Lint/EnsureReturn
    unless other_exception
      if @expected_symbol.nil?
        return !!@caught_symbol
      else
        if @expected_arg.nil?
          return @caught_symbol == @expected_symbol
        else
          return (@caught_symbol == @expected_symbol) && values_match?(@expected_arg, @caught_arg)
        end
      end
    end
    # rubocop:enable Lint/EnsureReturn
  end
end

#supports_block_expectations?True

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Indicates this matcher matches against a block.

Returns:

  • (True)


93
94
95
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 93

def supports_block_expectations?
  true
end

#supports_value_expectations?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


98
99
100
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/throw_symbol.rb', line 98

def supports_value_expectations?
  false
end