Class: Spectre::Assertion::Evaluation
- Defined in:
- lib/spectre/assertion.rb
Constant Summary collapse
- @@location_cache =
{}
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#call_location ⇒ Object
readonly
Returns the value of attribute call_location.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#failure ⇒ Object
readonly
Returns the value of attribute failure.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#negate ⇒ Object
readonly
Returns the value of attribute negate.
Instance Method Summary collapse
-
#initialize(call_location, actual, expected, method, predicate, negate: false) ⇒ Evaluation
constructor
A new instance of Evaluation.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(call_location, actual, expected, method, predicate, negate: false) ⇒ Evaluation
Returns a new instance of Evaluation.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/spectre/assertion.rb', line 66 def initialize call_location, actual, expected, method, predicate, negate: false @call_location = call_location @actual = actual @expected = ValueWrapper.wrap(expected) @predicate = predicate @negate = negate @failure = nil # Maybe not the most elegant way, but it works for now # as long as the `.to` call is on the same line as the variable location = call_location .find { |x| x.label.include? 'Spectre::Engine#load_files' or x.base_label == '<top (required)>' } path = location.path if @@location_cache.key?(path) file_content = @@location_cache[path] else file_content = File.read(path) @@location_cache[path] = file_content end @var_name = file_content .lines[location.lineno - 1] .strip .match(/[\s(]([^\s]+|\[.*\]|{.*})\.(to|not_to)[\s(]/) .captures .first .strip @repr = @var_name @repr += ' not' if @negate @repr += " to #{method}" @repr += expected.nil? ? ' empty' : " #{@expected}" success = @expected.evaluate?(@predicate, @actual, @negate) return if success @failure = if @negate 'it does not' else "got #{@actual.inspect}" end end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def actual @actual end |
#call_location ⇒ Object (readonly)
Returns the value of attribute call_location.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def call_location @call_location end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def desc @desc end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def expected @expected end |
#failure ⇒ Object (readonly)
Returns the value of attribute failure.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def failure @failure end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def method @method end |
#negate ⇒ Object (readonly)
Returns the value of attribute negate.
64 65 66 |
# File 'lib/spectre/assertion.rb', line 64 def negate @negate end |