Class: Synthesis::ExpectationRecord
- Extended by:
- Logging
- Defined in:
- lib/synthesis/expectation_record.rb
Class Method Summary collapse
- .[](matcher) ⇒ Object
- .add_expectation(receiver, method, track, args = []) ⇒ Object
- .expectations ⇒ Object
- .has_untested_expectations? ⇒ Boolean
- .ignore(*args) ⇒ Object
- .ignored ⇒ Object
- .record_invocations ⇒ Object
- .remove(expectation) ⇒ Object
- .tested_expectations ⇒ Object
- .untested_expectations ⇒ Object
Methods included from Logging
Class Method Details
.[](matcher) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/synthesis/expectation_record.rb', line 35 def [](matcher) # Using a hash for faster look up of expectations # when recording invocations expectations_with_return_values[matcher] || expectations_without_return_values[matcher] || Expectation::NilExpectation.new end |
.add_expectation(receiver, method, track, args = []) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/synthesis/expectation_record.rb', line 6 def add_expectation(receiver, method, track, args = []) unless ignore?(receiver) expectation = Expectation.new(receiver, method, track, args) expectations << expectation expectation end end |
.expectations ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/synthesis/expectation_record.rb', line 22 def expectations # Using an Array instead of a Set because the +Expectation+ instance # is not complete when first added. A Set would result to possible duplicates. # obj.expects(:method).with(:args) # the +Expectation+ will be added when obj.expects(:method) is called # the +Expectation+ arguments will be added when .with(:args) is called @expectations ||= [] end |
.has_untested_expectations? ⇒ Boolean
65 66 67 |
# File 'lib/synthesis/expectation_record.rb', line 65 def has_untested_expectations? untested_expectations.any? end |
.ignore(*args) ⇒ Object
18 19 20 |
# File 'lib/synthesis/expectation_record.rb', line 18 def ignore(*args) ignored.merge(args) end |
.ignored ⇒ Object
31 32 33 |
# File 'lib/synthesis/expectation_record.rb', line 31 def ignored @ignored ||= Set.new end |
.record_invocations ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/synthesis/expectation_record.rb', line 43 def record_invocations expectations.map! { |e| e.explode } expectations.flatten! expectations.uniq! expectations.each do |e| e.record_invocations if e.return_values_defined? expectations_with_return_values[e] = e else expectations_without_return_values[e] = e end end end |
.remove(expectation) ⇒ Object
14 15 16 |
# File 'lib/synthesis/expectation_record.rb', line 14 def remove(expectation) expectations.delete(expectation) end |
.tested_expectations ⇒ Object
57 58 59 |
# File 'lib/synthesis/expectation_record.rb', line 57 def tested_expectations expectations.select { |e| e.invoked? } end |
.untested_expectations ⇒ Object
61 62 63 |
# File 'lib/synthesis/expectation_record.rb', line 61 def untested_expectations expectations.select { |e| !e.invoked? } end |