r19cov 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module R19Cov
4
+ class ReportFactory
5
+ def self.create(options)
6
+ if options.report == :html
7
+ Report::HTML.new(options)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module R19Cov
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
4
+
5
+ describe R19Cov::Analyzer do
6
+ before(:all) do
7
+ @output_dir = File.join(File.dirname(__FILE__), '..', '..', 'coverage')
8
+ end
9
+
10
+ describe '#targets' do
11
+ it 'should return script files to analyze coverage' do
12
+ options = %w(foo.rb bar.rb baz.rb)
13
+ files = options.dup
14
+ analyzer = R19Cov::Analyzer.new(options)
15
+ analyzer.targets.should == options
16
+
17
+ options = %w(./lib/foo.rb ./lib/bar.rb ./lib/baz.rb)
18
+ files = options.dup
19
+ analyzer = R19Cov::Analyzer.new(options)
20
+ analyzer.targets.should == files
21
+ end
22
+ end
23
+
24
+ describe '#output_dir' do
25
+ it 'should return output dir' do
26
+ options = [__FILE__]
27
+ analyzer = R19Cov::Analyzer.new(options)
28
+ analyzer.output_dir.should == File.expand_path(@output_dir)
29
+ end
30
+ end
31
+
32
+ describe '#analyze' do
33
+ it 'should analyze coverage' do
34
+ options = [__FILE__]
35
+ analyzer = R19Cov::Analyzer.new(options)
36
+ analyzer.analyze
37
+ analyzer.should have_at_least(1).coverages
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,78 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
4
+
5
+ describe R19Cov::OptionParser do
6
+ before(:each) do
7
+ @out = StringIO.new
8
+ @err = StringIO.new
9
+ @parser = R19Cov::OptionParser.new(@out, @err)
10
+ @help_pattern = /Usage: r19cov \[options\] \(FILE\\|DIRECTORY\)\+ \[-- --extra-options\]/m
11
+ end
12
+
13
+ def parse(args)
14
+ @parser.parse(args)
15
+ @parser.options
16
+ end
17
+
18
+ it 'should accept files to exclude' do
19
+ options = parse(['--exclude', 'foo'])
20
+ options.exclude.should == ['foo']
21
+ end
22
+
23
+ it 'should accept -x form of files to exclude option' do
24
+ options = parse(['-x', 'bar'])
25
+ options.exclude.should == ['bar']
26
+ end
27
+
28
+ it 'should accept coverage report directory' do
29
+ options = parse(['--output', 'foo'])
30
+ options.output_dir.should == 'foo'
31
+ end
32
+
33
+ it 'should accept -o form of coverage report directory' do
34
+ options = parse(['-o', 'bar'])
35
+ options.output_dir.should == 'bar'
36
+ end
37
+
38
+ it 'should print help to stdout if no args' do
39
+ options = parse([])
40
+ @out.rewind
41
+ @out.read.should match(@help_pattern)
42
+ end
43
+
44
+ it 'should print help to stdout' do
45
+ options = parse(['--help'])
46
+ @out.rewind
47
+ @out.read.should match(@help_pattern)
48
+ end
49
+
50
+ it 'should acceopt -h form of help' do
51
+ options = parse(['-h'])
52
+ @out.rewind
53
+ @out.read.should match(@help_pattern)
54
+ end
55
+
56
+ it 'should print version to stdout' do
57
+ options = parse(['--version'])
58
+ @out.rewind
59
+ @out.read.should match(/r19cov \d+\.\d+\.\d+/n)
60
+ end
61
+
62
+ it 'should accept -v form of print version to stdout' do
63
+ options = parse(['-v'])
64
+ @out.rewind
65
+ @out.read.should match(/r19cov \d+\.\d+\.\d+/n)
66
+ end
67
+
68
+ it 'should raise if passed invalid option' do
69
+ lambda {
70
+ parse(['-a'])
71
+ }.should raise_error ::OptionParser::InvalidOption
72
+ end
73
+
74
+ it 'should recognize extra options' do
75
+ parse(['--', 'foo', 'bar'])
76
+ ARGV.should == ['foo', 'bar']
77
+ end
78
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
4
+
5
+ class Foo
6
+ include R19Cov::Report::HTML::Page
7
+ end
8
+
9
+ describe R19Cov::Report::HTML::Page do
10
+ before(:all) do
11
+ @foo = Foo.new
12
+ end
13
+
14
+ describe '#filename_format' do
15
+ it 'should round filename if length of filename is over MAX_FILENAME_SIZE' do
16
+ filename = '/foo/bar/baz/hoge'
17
+ @foo.filename_format(filename).should == filename
18
+
19
+ filename = ('0123456789' * 7) + '.html'
20
+ @foo.filename_format(filename).should == '...56789' + ('0123456789' * 6) + '.html'
21
+ end
22
+
23
+ it 'should round filename if file is under current directory' do
24
+ filename = File.join(Dir.pwd, 'foo', 'bar')
25
+ @foo.filename_format(filename).should == './foo/bar'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
4
+
5
+ describe R19Cov::ReportFactory do
6
+ describe '#create' do
7
+ it 'should create spedified Report object' do
8
+ mock_options = mock('options')
9
+ mock_options.should_receive(:report).and_return(:html)
10
+ R19Cov::ReportFactory.create(mock_options).should be_an_instance_of(R19Cov::Report::HTML)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
4
+
5
+ describe R19Cov::VERSION do
6
+ it 'should return R19Cov version' do
7
+ R19Cov::VERSION.should =~ /^[\d]{1,2}\.[\d]{1,2}\.[\d]{1,2}$/
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), 'spec_helper')
4
+ require 'fileutils'
5
+
6
+ describe 'bin/r19cov' do
7
+
8
+ before(:all) do
9
+ @coverage_dir = File.join(File.dirname(__FILE__), 'tmp')
10
+ end
11
+
12
+ after(:all) do
13
+ FileUtils.rm_r(@coverage_dir) if File.exist?(@coverage_dir)
14
+ end
15
+
16
+ it 'should create `coverage` dir and report html files' do
17
+ script = File.join(File.dirname(__FILE__), 'sample', 'sample_script.rb')
18
+ sh [r19cov_bin, "-o #{@coverage_dir}", script].join(' ')
19
+
20
+ File.exist?(@coverage_dir).should be_true
21
+
22
+ report_files = Dir["#{@coverage_dir}/**/*"]
23
+
24
+ report_files.any?{ |f| f =~ /foo_rb.html/ }.should be_true
25
+ report_files.any?{ |f| f =~ /bar_rb.html/ }.should be_true
26
+ report_files.any?{ |f| f =~ /baz_rb.html/ }.should be_true
27
+ end
28
+
29
+ it 'should not exit if exit in a library' do
30
+ script = File.join(File.dirname(__FILE__), 'sample', 'exit_script.rb')
31
+ sh [r19cov_bin, "-o #{@coverage_dir}", script].join(' ')
32
+
33
+ report_files = Dir["#{@coverage_dir}/**/*"]
34
+ report_files.any?{ |f| f =~ /exit_script_rb.html/ }.should be_true
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ class Bar
2
+ def str
3
+ self.class.to_s
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Baz
2
+ def str
3
+ self.class.to_s
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ foo = 1
5
+ bar = foo + 1
6
+ baz = bar + 1
7
+
8
+ exit(0)
@@ -0,0 +1,5 @@
1
+ class Foo
2
+ def str
3
+ self.class.to_s
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ dir = File.dirname(__FILE__)
5
+
6
+ $:.unshift << dir unless $:.include?(dir)
7
+
8
+ require 'foo'
9
+ require 'bar'
10
+ require 'baz'
11
+
12
+ foo = Foo.new
13
+ foo.str
14
+
15
+ baz = Baz.new
16
+ baz.str
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec'
4
+ require 'r19cov'
5
+
6
+ def coverage_dir
7
+ File.join(File.dirname(__FILE__), '..', 'coverage')
8
+ end
9
+
10
+ def sh(*args)
11
+ `#{args.join(' ')}`
12
+ end
13
+
14
+ def r19cov_bin
15
+ File.join(File.dirname(__FILE__), '..', 'bin', 'r19cov')
16
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r19cov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - orepuri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-20 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ description: Coverage Tool for Ruby 1.9
26
+ email: orepuri@gmail.com
27
+ executables:
28
+ - r19cov
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - COPYING
35
+ - ChangeLog
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/r19cov/analyzer.rb
39
+ - lib/r19cov/cli.rb
40
+ - lib/r19cov/coverage/summary.rb
41
+ - lib/r19cov/coverage.rb
42
+ - lib/r19cov/option_parser.rb
43
+ - lib/r19cov/options.rb
44
+ - lib/r19cov/rake/spec_task.rb
45
+ - lib/r19cov/report/html/detail_page.rb
46
+ - lib/r19cov/report/html/index_page.rb
47
+ - lib/r19cov/report/html/page.rb
48
+ - lib/r19cov/report/html/templates/detail.html.erb
49
+ - lib/r19cov/report/html/templates/index.html.erb
50
+ - lib/r19cov/report/html/templates/r19cov.css
51
+ - lib/r19cov/report/html.rb
52
+ - lib/r19cov/report_factory.rb
53
+ - lib/r19cov/version.rb
54
+ - lib/r19cov.rb
55
+ - bin/r19cov
56
+ - spec/r19cov/analyzer_spec.rb
57
+ - spec/r19cov/option_parser_spec.rb
58
+ - spec/r19cov/report/html/page_spec.rb
59
+ - spec/r19cov/report_factory_spec.rb
60
+ - spec/r19cov/version_spec.rb
61
+ - spec/r19cov_spec.rb
62
+ - spec/sample/bar.rb
63
+ - spec/sample/baz.rb
64
+ - spec/sample/exit_script.rb
65
+ - spec/sample/foo.rb
66
+ - spec/sample/sample_script.rb
67
+ - spec/spec.opts
68
+ - spec/spec_helper.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/orepuri
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "1.9"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project: r19cov
93
+ rubygems_version: 1.3.5
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: R19Cov is a Coverage Tool for Ruby 1.9. It uses `coverage` library embeded in Ruby 1.9. R19Cov analyzes source code coverage and report in HTML format.
97
+ test_files: []
98
+