C0 code coverage information
Generated on Sun Oct 26 11:18:12 -0500 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 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'aquarium/extras/design_by_contract'
3
4 describe Aquarium::Extras::DesignByContract, "precondition" do
5 class PreCond
6 include Aquarium::Extras::DesignByContract
7 def action *args
8 end
9
10 precondition :method => :action, :message => "Must pass more than one argument." do |jp, obj, *args|
11 args.size > 0
12 end
13 end
14
15 it "should add advice that raises if the precondition is not satisfied" do
16 lambda {PreCond.new.action}.should raise_error(Aquarium::Extras::DesignByContract::ContractError)
17 end
18
19 it "should add advice that does not raise if the precondition is satisfied" do
20 PreCond.new.action(:a1)
21 end
22 end
23
24 describe Aquarium::Extras::DesignByContract, "postcondition" do
25 class PostCond
26 include Aquarium::Extras::DesignByContract
27 def action *args
28 end
29
30 postcondition :method => :action, :message => "Must pass more than one argument and first argument must be non-empty." do |jp, obj, *args|
31 args.size > 0 && ! args[0].empty?
32 end
33 end
34
35 it "should add advice that raises if the postcondition is not satisfied" do
36 lambda {PostCond.new.action}.should raise_error(Aquarium::Extras::DesignByContract::ContractError)
37 lambda {PostCond.new.action("")}.should raise_error(Aquarium::Extras::DesignByContract::ContractError)
38 end
39
40 it "should add advice that does not raise if the postcondition is satisfied" do
41 PostCond.new.action(:a1)
42 end
43 end
44
45
46 describe Aquarium::Extras::DesignByContract, "invariant" do
47 class InvarCond
48 include Aquarium::Extras::DesignByContract
49 def initialize
50 @invar = 0
51 end
52 attr_reader :invar
53 def good_action
54 "good"
55 end
56 def bad_action
57 @invar = 1
58 "bad"
59 end
60
61 invariant :methods => /action$/, :message => "Must not change the @invar value." do |jp, obj, *args|
62 obj.invar == 0
63 end
64 end
65
66 it "should add advice that raises if the invariant is not satisfied" do
67 lambda {InvarCond.new.bad_action}.should raise_error(Aquarium::Extras::DesignByContract::ContractError)
68 end
69
70 it "should add advice that does not raise if the invariant is satisfied" do
71 InvarCond.new.good_action
72 end
73
74 it "should return the value returned by the checked method when the invariant is satisfied" do
75 InvarCond.new.good_action.should == "good"
76 end
77 end
78
79 describe Aquarium::Extras::DesignByContract, "global enable/disable option" do
80 class ContractEnablement
81 include Aquarium::Extras::DesignByContract
82 def action *args
83 end
84
85 precondition :method => :action, :message => "Must pass more than one argument." do |jp, obj, *args|
86 args.size > 0
87 end
88 end
89
90 it "should disable creation of the contract aspects when the contracts are disabled" do
91 begin
92 Aquarium::Extras::DesignByContract.disable_all
93 lambda { ContractEnablement.new.action }.should_not raise_error(Aquarium::Extras::DesignByContract::ContractError)
94 ensure
95 Aquarium::Extras::DesignByContract.enable_all
96 end
97 end
98
99 it "should enable creation of the contract aspects when the contracts are enabled" do
100 Aquarium::Extras::DesignByContract.enable_all
101 lambda { ContractEnablement.new.action }.should raise_error(Aquarium::Extras::DesignByContract::ContractError)
102 end
103 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.