Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
rcov/ruby/1.8/gems/rspec-core-2.5.1/lib/rspec/core/let.rb | 101 | 26 | 89.11%
|
57.69%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module RSpec |
2 module Core |
3 module Let |
4 |
5 module ClassMethods |
6 # Generates a method whose return value is memoized |
7 # after the first call. |
8 # |
9 # == Examples |
10 # |
11 # describe Thing do |
12 # let(:thing) { Thing.new } |
13 # |
14 # it "does something" do |
15 # # first invocation, executes block, memoizes and returns result |
16 # thing.do_something |
17 # |
18 # # second invocation, returns the memoized value |
19 # thing.should be_something |
20 # end |
21 # end |
22 def let(name, &block) |
23 define_method(name) do |
24 __memoized[name] ||= instance_eval(&block) |
25 end |
26 end |
27 |
28 # Just like <tt>let()</tt>, except the block is invoked |
29 # by an implicit <tt>before</tt> hook. This serves a dual |
30 # purpose of setting up state and providing a memoized |
31 # reference to that state. |
32 # |
33 # == Examples |
34 # |
35 # class Thing |
36 # def self.count |
37 # @count ||= 0 |
38 # end |
39 # |
40 # def self.count=(val) |
41 # @count += val |
42 # end |
43 # |
44 # def self.reset_count |
45 # @count = 0 |
46 # end |
47 # |
48 # def initialize |
49 # self.class.count += 1 |
50 # end |
51 # end |
52 # |
53 # describe Thing do |
54 # after(:each) { Thing.reset_count } |
55 # |
56 # context "using let" do |
57 # let(:thing) { Thing.new } |
58 # |
59 # it "is not invoked implicitly" do |
60 # Thing.count.should == 0 |
61 # end |
62 # |
63 # it "can be invoked explicitly" do |
64 # thing |
65 # Thing.count.should == 1 |
66 # end |
67 # end |
68 # |
69 # context "using let!" do |
70 # let!(:thing) { Thing.new } |
71 # |
72 # it "is invoked implicitly" do |
73 # Thing.count.should == 1 |
74 # end |
75 # |
76 # it "returns memoized version on first invocation" do |
77 # thing |
78 # Thing.count.should == 1 |
79 # end |
80 # end |
81 # end |
82 def let!(name, &block) |
83 let(name, &block) |
84 before { __send__(name) } |
85 end |
86 end |
87 |
88 module InstanceMethods |
89 def __memoized # :nodoc: |
90 @__memoized ||= {} |
91 end |
92 end |
93 |
94 def self.included(mod) # :nodoc: |
95 mod.extend ClassMethods |
96 mod.__send__ :include, InstanceMethods |
97 end |
98 |
99 end |
100 end |
101 end |
Generated on Fri Apr 22 17:22:42 -0700 2011 with rcov 0.9.8