Parent

Class Index [+]

Quicksearch

RSpec::Matchers::BuiltIn::YieldProbe

Attributes

num_yields[RW]
yielded_args[RW]

Public Class Methods

assert_valid_expect_block!(block) click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 60
60:         def self.assert_valid_expect_block!(block)
61:           return if block.arity == 1
62:           raise "Your expect block must accept an argument to be used with this " +
63:                 "matcher. Pass the argument as a block on to the method you are testing."
64:         end
new() click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 15
15:         def initialize
16:           @used = false
17:           self.num_yields, self.yielded_args = 0, []
18:         end
probe(block) click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 5
 5:         def self.probe(block)
 6:           probe = new
 7:           assert_valid_expect_block!(block)
 8:           block.call(probe)
 9:           probe.assert_used!
10:           probe
11:         end

Public Instance Methods

assert_used!() click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 51
51:         def assert_used!
52:           return if @used
53:           raise "You must pass the argument yielded to your expect block on " +
54:                 "to the method-under-test as a block. It acts as a probe that " +
55:                 "allows the matcher to detect whether or not the method-under-test " +
56:                 "yields, and, if so, how many times, and what the yielded arguments " +
57:                 "are."
58:         end
single_yield_args() click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 30
30:         def single_yield_args
31:           yielded_args.first
32:         end
successive_yield_args() click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 45
45:         def successive_yield_args
46:           yielded_args.map do |arg_array|
47:             arg_array.size == 1 ? arg_array.first : arg_array
48:           end
49:         end
to_proc() click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 20
20:         def to_proc
21:           @used = true
22: 
23:           probe = self
24:           Proc.new do |*args|
25:             probe.num_yields += 1
26:             probe.yielded_args << args
27:           end
28:         end
yielded_once?(matcher_name) click to toggle source
    # File lib/rspec/matchers/built_in/yield.rb, line 34
34:         def yielded_once?(matcher_name)
35:           case num_yields
36:           when 1 then true
37:           when 0 then false
38:           else
39:             raise "The #{matcher_name} matcher is not designed to be used with a " +
40:                   "method that yields multiple times. Use the yield_successive_args " +
41:                   "matcher for that case."
42:           end
43:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.