Class: RSpec::Undefined::Matchers::BeUndefined

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/undefined/matchers.rb

Constant Summary collapse

LOCATION_SEARCH_DEPTH =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inner: nil, expected_value: nil, expected_provided: false, category: nil) ⇒ BeUndefined

kwarg: :expected_provided で「キーワードが明示された」を示す(nil 期待値との区別)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/undefined/matchers.rb', line 15

def initialize(inner: nil, expected_value: nil, expected_provided: false, category: nil)
  @matcher_name = "be_undefined"
  @inner = inner
  @expected_value = expected_value
  @expected_provided = expected_provided
  @category = category
  @expected_recorded =
    if @inner
      describe_inner(@inner)
    elsif @expected_provided
      @expected_value.respond_to?(:description) ? @expected_value.description : @expected_value
    else
      :__any__
    end
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



12
13
14
# File 'lib/rspec/undefined/matchers.rb', line 12

def actual
  @actual
end

#categoryObject (readonly)

Returns the value of attribute category.



12
13
14
# File 'lib/rspec/undefined/matchers.rb', line 12

def category
  @category
end

#expected_recordedObject (readonly)

Returns the value of attribute expected_recorded.



12
13
14
# File 'lib/rspec/undefined/matchers.rb', line 12

def expected_recorded
  @expected_recorded
end

#matcher_nameObject (readonly)

Returns the value of attribute matcher_name.



12
13
14
# File 'lib/rspec/undefined/matchers.rb', line 12

def matcher_name
  @matcher_name
end

Instance Method Details

#descriptionObject



52
53
54
55
# File 'lib/rspec/undefined/matchers.rb', line 52

def description
  suffix = category ? " [#{category}]" : ""
  "は未確定仕様#{suffix}である"
end

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/rspec/undefined/matchers.rb', line 38

def does_not_match?(actual)
  @actual = actual
  false
end

#failure_messageObject



43
44
45
46
# File 'lib/rspec/undefined/matchers.rb', line 43

def failure_message
  "undefined[#{matcher_name}] at #{location_summary}: " \
    "category=#{category.inspect} expected=#{@expected_recorded.inspect} actual=#{@actual.inspect}"
end

#failure_message_when_negatedObject



48
49
50
# File 'lib/rspec/undefined/matchers.rb', line 48

def failure_message_when_negated
  "undefined matcher は否定形では使えません"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/rspec/undefined/matchers.rb', line 31

def matches?(actual)
  @actual = actual
  matched = evaluate(actual)
  record(matched)
  !RSpec::Undefined.configuration.strict?
end