Class: Steep::Expectations::TestResult

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/expectations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, expectation:, actual:) ⇒ TestResult

Returns a new instance of TestResult.



139
140
141
142
143
# File 'lib/steep/expectations.rb', line 139

def initialize(path:, expectation:, actual:)
  @path = path
  @expectation = expectation
  @actual = actual
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



137
138
139
# File 'lib/steep/expectations.rb', line 137

def actual
  @actual
end

#expectationObject (readonly)

Returns the value of attribute expectation.



136
137
138
# File 'lib/steep/expectations.rb', line 136

def expectation
  @expectation
end

#pathObject (readonly)

Returns the value of attribute path.



135
136
137
# File 'lib/steep/expectations.rb', line 135

def path
  @path
end

Instance Method Details

#each_diagnosticsObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/steep/expectations.rb', line 153

def each_diagnostics
  if block_given?
    expected_set = Set.new(expectation) #: Set[Diagnostic]
    actual_set = Set.new(actual) #: Set[Diagnostic]

    (expected_set + actual_set).sort_by(&:sort_key).each do |diagnostic|
      case
      when expected_set.include?(diagnostic) && actual_set.include?(diagnostic)
        yield [:expected, diagnostic]
      when expected_set.include?(diagnostic)
        yield [:missing, diagnostic]
      when actual_set.include?(diagnostic)
        yield [:unexpected, diagnostic]
      end
    end
  else
    enum_for :each_diagnostics
  end
end

#empty?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/steep/expectations.rb', line 145

def empty?
  actual.empty?
end

#expected_diagnosticsObject



173
174
175
# File 'lib/steep/expectations.rb', line 173

def expected_diagnostics
  each_diagnostics.select {|type, _| type == :expected }.map {|_, diag| diag }
end

#missing_diagnosticsObject



181
182
183
# File 'lib/steep/expectations.rb', line 181

def missing_diagnostics
  each_diagnostics.select {|type, _| type == :missing }.map {|_, diag| diag }
end

#satisfied?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/steep/expectations.rb', line 149

def satisfied?
  unexpected_diagnostics.empty? && missing_diagnostics.empty?
end

#unexpected_diagnosticsObject



177
178
179
# File 'lib/steep/expectations.rb', line 177

def unexpected_diagnostics
  each_diagnostics.select {|type, _| type == :unexpected }.map {|_, diag| diag }
end