Class: Wrong::FailureMessage
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- @@formatters =
[]
Instance Attribute Summary collapse
-
#chunk ⇒ Object
Returns the value of attribute chunk.
-
#explanation ⇒ Object
Returns the value of attribute explanation.
-
#valence ⇒ Object
Returns the value of attribute valence.
Class Method Summary collapse
Instance Method Summary collapse
- #basic ⇒ Object
- #full ⇒ Object
-
#initialize(chunk, valence, explanation) ⇒ FailureMessage
constructor
A new instance of FailureMessage.
Constructor Details
#initialize(chunk, valence, explanation) ⇒ FailureMessage
Returns a new instance of FailureMessage.
46 47 48 |
# File 'lib/wrong/failure_message.rb', line 46 def initialize(chunk, valence, explanation) @chunk, @valence, @explanation = chunk, valence, explanation end |
Instance Attribute Details
#chunk ⇒ Object
Returns the value of attribute chunk.
44 45 46 |
# File 'lib/wrong/failure_message.rb', line 44 def chunk @chunk end |
#explanation ⇒ Object
Returns the value of attribute explanation.
44 45 46 |
# File 'lib/wrong/failure_message.rb', line 44 def explanation @explanation end |
#valence ⇒ Object
Returns the value of attribute valence.
44 45 46 |
# File 'lib/wrong/failure_message.rb', line 44 def valence @valence end |
Class Method Details
.formatter_for(predicate) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/wrong/failure_message.rb', line 13 def self.formatter_for(predicate) @@formatters.each do |formatter_class| formatter = formatter_class.new(predicate) if formatter.match? return formatter end end nil end |
.formatters ⇒ Object
9 10 11 |
# File 'lib/wrong/failure_message.rb', line 9 def self.formatters @@formatters end |
.register_formatter(formatter) ⇒ Object
5 6 7 |
# File 'lib/wrong/failure_message.rb', line 5 def self.register_formatter(formatter) @@formatters << formatter end |
Instance Method Details
#basic ⇒ Object
50 51 52 |
# File 'lib/wrong/failure_message.rb', line 50 def basic "#{valence == :deny ? "Didn't expect" : "Expected"} #{colored(:blue, chunk.code)}" end |
#full ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wrong/failure_message.rb', line 54 def full = "" << "#{explanation}: " if explanation << basic = if predicate && !(predicate.is_a? Predicated::Conjunction) if formatter = FailureMessage.formatter_for(predicate) colored(:bold, formatter.describe) end end unless chunk.details.empty? and .nil? << ", but" end << if << chunk.details unless chunk.details.empty? end |