Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
spec/example_spec.rb | 88 | 81 | 75.00%
|
72.84%
|
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.expand_path('../spec_helper', __FILE__) |
2 |
3 $:.unshift File.expand_path('../../example', __FILE__) |
4 |
5 describe "ASIR Example" do |
6 attr_accessor :file, :expects |
7 |
8 before(:each) do |
9 @expects = [ ] |
10 end |
11 |
12 after(:each) do |
13 @file.should_not == nil |
14 File.open(@file) do | fh | |
15 until fh.eof? |
16 line = fh.readline |
17 line.chomp! |
18 case |
19 when line.sub!(/^\s*#\s*EXPECT\/:\s*/, '') |
20 expect Regexp.new(line) |
21 when line.sub!(/^\s*#\s*EXPECT!\/:\s*/, '') |
22 expect Regexp.new(line), :'!~' |
23 when line.sub!(/^\s*#\s*EXPECT:\s*/, '') |
24 expect Regexp.new(Regexp.escape(line)) |
25 when line.sub!(/^\s*#\s*EXPECT!:\s*/, '') |
26 expect Regexp.new(Regexp.escape(line)), :'!~' |
27 end |
28 end |
29 end |
30 @output, @exit_code = run_file!(@file) |
31 @exit_code.should == 0 |
32 @expects.empty?.should_not == true |
33 @expects.each do | rx, mode | |
34 $stderr.puts " Checking #{mode} #{rx.inspect}" if ENV['SPEC_VERBOSE'] |
35 case mode |
36 when :'=~' |
37 @output.should =~ rx |
38 when :'!~' |
39 @output.should_not =~ rx |
40 else |
41 raise ArgumentError |
42 end |
43 end |
44 end |
45 |
46 def run_file! file, output = StringIO.new('') |
47 progname_save, stdout_save, stderr_save = $0, $stdout, $stderr |
48 exc = system_exit = nil; exit_code = 0 |
49 begin |
50 if true |
51 cmd = "ASIR_EXAMPLE_SILENT=1 ruby -I example -I lib #{file}" |
52 $stderr.puts "\n Running #{cmd}:" if ENV['SPEC_VERBOSE'] |
53 output = `#{cmd} 2>&1 | tee #{file}.out` |
54 else |
55 $stderr.puts "\n Loading #{file}:" if ENV['SPEC_VERBOSE'] |
56 $stdout.puts "*** #{$$}: client process"; $stdout.flush |
57 $stdout = $stderr = output |
58 $0 = file |
59 Kernel.load(file, true) |
60 output = output.string if StringIO === output |
61 end |
62 rescue ::SystemExit => system_exit |
63 exit_code = 1 # ??? |
64 rescue ::Exception => exc |
65 exit_code = -1 |
66 end |
67 [ output, exit_code ] |
68 ensure |
69 $0, $stdout, $stderr = progname_save, stdout_save, stderr_save |
70 $stderr.write output if ENV['SPEC_VERBOSE'] |
71 if exc |
72 stderr_save.puts "ERROR: #{file}: #{exc.inspect}\n#{exc.backtrace * "\n"}" |
73 raise exc |
74 end |
75 end |
76 |
77 def expect rx, mode = :'=~' |
78 @expects << [ rx, mode ] |
79 end |
80 |
81 Dir['example/**/ex[0-9]*.rb'].sort.each do | file | |
82 title = File.open(file) { | fh | fh.read(4096) } |
83 title = title =~ /#\s+!SLIDE[^\n]*\n\s*#\s*([^\n]+)/ && $1 |
84 it "#{file} - #{title}" do |
85 @file = file |
86 end |
87 end |
88 end |
Generated on Fri Jan 27 17:37:46 -0600 2012 with rcov 0.9.8