C0 code coverage information
Generated on Wed Dec 24 11:03:27 -0600 2008 with rcov 0.8.1.2
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 Context
2 class SharedBehavior < Module
3 def self.create_from_behavior(beh) # :nodoc:
4 mod = self.new
5 mod._behavior = beh
6
7 mod
8 end
9
10 def _behavior=(beh) # :nodoc:
11 @_behavior = beh
12 end
13
14 def included(arg) # :nodoc:
15 @_behavior.call
16 end
17 end
18 end
19
20 class Test::Unit::TestCase
21 class << self
22 # Share behavior among different contexts. This creates a module (actually, a Module subclass)
23 # that is included using the +use+ method (or one of its aliases) provided by context or +include+
24 # if you know the module's constant name.
25 #
26 # ==== Examples
27 #
28 # shared "other things" do
29 # it "should do things but not some things" do
30 # # behavior is fun
31 # end
32 # end
33 #
34 # use "other things"
35 # # or...
36 # it_should_behave_like "other things"
37 #
38 # shared :client do
39 # it "should be a client to our server" do
40 # # TODO: client behavior here
41 # end
42 # end
43 #
44 # use :client
45 # # or...
46 # uses "client"
47 # behaves_like "client"
48 #
49 def shared(name, &block)
50 case name.class.name
51 when "String"
52 name = name.to_module_name
53 when "Symbol"
54 name = name.to_s.to_module_name
55 else
56 raise ArgumentError, "Provide a String or Symbol as the name of the shared behavior group"
57 end
58
59 Object.const_set(name, Context::SharedBehavior.create_from_behavior(block))
60 end
61
62 %w(shared_behavior share_as share_behavior_as shared_examples_for).each {|m| alias_method m, :shared}
63
64 # Pull in behavior shared by +shared+ or a module.
65 #
66 # ==== Examples
67 #
68 # shared "other things" do
69 # it "should do things but not some things" do
70 # # behavior is fun
71 # end
72 # end
73 #
74 # use "other things"
75 # # or...
76 # it_should_behave_like "other things"
77 #
78 # module Things
79 # end
80 #
81 # uses Things
82 #
83 def use(shared_name)
84 case shared_name.class.name
85 when "Context::SharedBehavior", "Module"
86 include shared_name
87 when "String"
88 include Object.const_get(shared_name.to_module_name)
89 when "Symbol"
90 include Object.const_get(shared_name.to_s.to_module_name)
91 else
92 raise ArgumentError, "Provide a String or Symbol as the name of the shared behavior group or the module name"
93 end
94 end
95
96 %w(uses it_should_behave_like behaves_like uses_examples_from).each {|m| alias_method m, :use}
97 end
98 end
Generated using the rcov code coverage analysis tool for Ruby
version 0.8.1.2.