ciserver_formatter 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ciserver_formatter.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ciserver_formatter (0.0.1)
5
+ rspec (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.4)
11
+ rspec (2.13.0)
12
+ rspec-core (~> 2.13.0)
13
+ rspec-expectations (~> 2.13.0)
14
+ rspec-mocks (~> 2.13.0)
15
+ rspec-core (2.13.1)
16
+ rspec-expectations (2.13.0)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.13.1)
19
+
20
+ PLATFORMS
21
+ java
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ ciserver_formatter!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Diego Alonso
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # CiserverFormatter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ciserver_formatter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ciserver_formatter
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ciserver_formatter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ciserver_formatter"
8
+ gem.version = CiserverFormatter::VERSION
9
+ gem.authors = ["Diego Alonso"]
10
+ gem.email = ["diego.alonso@adaptfms.com"]
11
+ gem.description = %q{Formatter for AdaptFMS CI server}
12
+ gem.summary = %q{Formatter used when running rspec from the AdaptFMS CI server}
13
+ gem.homepage = "http://www.adaptfms.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('rspec', ["~> 2.0"])
21
+ end
@@ -0,0 +1,91 @@
1
+ require 'rspec/core/formatters/base_text_formatter'
2
+
3
+ module CiserverFormatter
4
+ class CiserverFormatter < RSpec::Core::Formatters::BaseTextFormatter
5
+ attr_accessor :status, :passed_count, :failed_count, :pending_count, :example_count
6
+
7
+ def initialize(output)
8
+ super
9
+ @status = :pass
10
+ @passed_count = 0
11
+ @failed_count = 0
12
+ @pending_count = 0
13
+ @group_level = 0
14
+ end
15
+
16
+ def start(example_count)
17
+ @example_count = example_count
18
+ StatusReporter.new(FileResolver.branch_status_file).start
19
+ StatusReporter.new(FileResolver.commit_status_file).start
20
+ end
21
+
22
+ def output
23
+ @ciserver_output ||= File.open(FileResolver.output_file, 'w')
24
+ end
25
+
26
+ def stop
27
+ StatusReporter.new(FileResolver.branch_status_file).finish(self)
28
+ StatusReporter.new(FileResolver.commit_status_file).finish(self)
29
+ end
30
+
31
+ def example_group_started(example_group)
32
+ super
33
+ output.puts "#{current_indentation}#{example_group.description}"
34
+ @group_level += 1
35
+ end
36
+
37
+ def example_group_finished(example_group)
38
+ super
39
+ @group_level -= 1
40
+ end
41
+
42
+ def example_started(example)
43
+ super
44
+ end
45
+
46
+ def example_pending(example)
47
+ super
48
+ output.puts "#{current_indentation}#{example.description}"
49
+ @status = :pending if @status == :pass
50
+ @pending_count += 1
51
+ update_progress
52
+ end
53
+
54
+ def example_failed(example)
55
+ super
56
+ output.puts "#{current_indentation}#{example.description}"
57
+ @status = :failed
58
+ @failed_count += 1
59
+ update_progress
60
+ end
61
+
62
+ def example_passed(example)
63
+ super
64
+ output.puts "#{current_indentation}#{example.description}"
65
+ @passed_count += 1
66
+ update_progress
67
+ end
68
+
69
+ def percentage
70
+ total_count * 100 / @example_count
71
+ end
72
+
73
+ def branch
74
+ FileResolver.branch
75
+ end
76
+
77
+ private
78
+ def current_indentation
79
+ ' ' * @group_level
80
+ end
81
+
82
+ def total_count
83
+ @failed_count + @passed_count + @pending_count
84
+ end
85
+
86
+ def update_progress
87
+ ProgressReporter.new(FileResolver.progress_output_file).report(self)
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,40 @@
1
+ module CiserverFormatter
2
+ class FileResolver
3
+ def self.branch
4
+ ENV['BRANCH']
5
+ end
6
+
7
+ def self.branch_path
8
+ File.join(build_path, branch)
9
+ end
10
+
11
+ def self.commit
12
+ ENV['COMMIT']
13
+ end
14
+
15
+ def self.commit_path
16
+ File.join(build_path, branch, commit)
17
+ end
18
+
19
+ def self.build_path
20
+ ENV['BUILD_PATH']
21
+ end
22
+
23
+ def self.progress_output_file
24
+ File.join(build_path, 'current_test_session.txt')
25
+ end
26
+
27
+ def self.commit_status_file
28
+ File.join(commit_path, 'status.txt')
29
+ end
30
+
31
+ def self.branch_status_file
32
+ File.join(branch_path, 'status.txt')
33
+ end
34
+
35
+ def self.output_file
36
+ File.join(commit_path, 'output.txt')
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ module CiserverFormatter
2
+ class ProgressReporter
3
+
4
+ def initialize(output_file)
5
+ @output_file = output_file
6
+ end
7
+
8
+ def report(formatter)
9
+ File.open(@output_file, 'w') { |f| f.write(output_for_formatter(formatter)) }
10
+ end
11
+
12
+ private
13
+ def output_for_formatter(formatter)
14
+ """branch:#{formatter.branch}
15
+ test_session_status:#{formatter.status.capitalize}
16
+ percentage_run:#{formatter.percentage}
17
+ failed_count:#{formatter.failed_count}
18
+ pending_count:#{formatter.pending_count}
19
+ passed_count:#{formatter.passed_count}
20
+ example_count:#{formatter.example_count}
21
+ """
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module CiserverFormatter
2
+ class StatusReporter
3
+ def initialize(file)
4
+ @file = file
5
+ end
6
+
7
+ def start
8
+ File.open(@file, 'w') { |f| f.write("Testing") }
9
+ end
10
+
11
+ def finish(formatter)
12
+ File.open(@file, 'w') { |f| f.write(formatter.status.capitalize) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module CiserverFormatter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "ciserver_formatter/version"
2
+ require "ciserver_formatter/ciserver_formatter"
3
+ require "ciserver_formatter/status_reporter"
4
+ require "ciserver_formatter/file_resolver"
5
+ require "ciserver_formatter/progress_reporter"
6
+
7
+ module CiserverFormatter
8
+ end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ module CiserverFormatter
4
+ describe CiserverFormatter do
5
+ let(:output) { double(:string_io).as_null_object }
6
+ let(:formatter) { CiserverFormatter.new(output) }
7
+ let(:example) { double(:example) }
8
+ let(:example_group) { double(:example_group) }
9
+
10
+ before(:each) do
11
+ # Ignore progress report
12
+ FileResolver.stub(progress_output_file: nil)
13
+ ProgressReporter.stub(:new).with(nil).and_return(double(:reporter).as_null_object)
14
+ end
15
+
16
+ describe "initialize" do
17
+ it "should start as passed" do
18
+ formatter.status.should be :pass
19
+ end
20
+
21
+ it "should start with no examples passed" do
22
+ formatter.passed_count.should be 0
23
+ end
24
+
25
+ it "should start with no examples failed" do
26
+ formatter.failed_count.should be 0
27
+ end
28
+
29
+ it "should start with no examples pending" do
30
+ formatter.pending_count.should be 0
31
+ end
32
+ end
33
+
34
+ describe "example group started" do
35
+ it "should output the description" do
36
+ example_group.stub(description: "The example group description")
37
+ output.should_receive(:puts).with("The example group description")
38
+ formatter.example_group_started(example_group)
39
+ end
40
+
41
+ it "should increase indentation" do
42
+ example_group.stub(description: "")
43
+ formatter.example_group_started(example_group)
44
+
45
+ example.stub(description: "The example description")
46
+ output.should_receive(:puts).with(" The example description")
47
+ formatter.example_group_started(example)
48
+ end
49
+ end
50
+
51
+ describe "example group finished" do
52
+ it "should decrease indentation" do
53
+ example_group.stub(description: "")
54
+ formatter.example_group_started(example_group)
55
+ formatter.example_group_finished(example_group)
56
+
57
+ example.stub(description: "The example description")
58
+ output.should_receive(:puts).with("The example description")
59
+ formatter.example_group_started(example)
60
+ end
61
+ end
62
+
63
+ describe "example passed" do
64
+ it "should increase the number of passed tests" do
65
+ example.stub(description: "The example description")
66
+ formatter.example_passed(example)
67
+ formatter.passed_count.should be 1
68
+ end
69
+
70
+ it "should output the passed example description" do
71
+ example.stub(description: "The example description")
72
+ output.should_receive(:puts).with("The example description")
73
+ formatter.example_passed(example)
74
+ end
75
+ end
76
+
77
+ describe "example failed" do
78
+ it "should increase the number of failed tests" do
79
+ example.stub(description: "The example description")
80
+ formatter.example_failed(example)
81
+ formatter.failed_count.should be 1
82
+ end
83
+
84
+ it "should output the failed example description" do
85
+ example.stub(description: "The example description")
86
+ output.should_receive(:puts).with("The example description")
87
+ formatter.example_failed(example)
88
+ end
89
+
90
+ it "should change status to failed" do
91
+ example.stub(description: "The example description")
92
+ formatter.example_failed(example)
93
+ formatter.status.should be :failed
94
+ end
95
+ end
96
+
97
+ describe "example pending" do
98
+ it "should increase the number of pending tests" do
99
+ example.stub(description: "The example description")
100
+ formatter.example_pending(example)
101
+ formatter.pending_count.should be 1
102
+ end
103
+
104
+ it "should output the pending example description" do
105
+ example.stub(description: "The example description")
106
+ output.should_receive(:puts).with("The example description")
107
+ formatter.example_pending(example)
108
+ end
109
+
110
+ describe "status change" do
111
+ it "changes to pending if previous status was pass" do
112
+ example.stub(description: "The example description")
113
+ formatter.example_pending(example)
114
+ formatter.status.should be :pending
115
+ end
116
+ it "stays in failed if previous state was failed" do
117
+ example.stub(description: "The example description")
118
+ formatter.example_failed(example)
119
+ formatter.example_pending(example)
120
+ formatter.status.should be :failed
121
+ end
122
+ end
123
+ end
124
+
125
+ describe "percentage" do
126
+ before (:each) do
127
+ FileResolver.stub(branch_status_file: "")
128
+ FileResolver.stub(commit_status_file: "")
129
+ StatusReporter.stub_chain(:new, :start)
130
+ formatter.start(5)
131
+ end
132
+
133
+ it "percentage is 0 is no tests run" do
134
+ formatter.percentage.should be 0
135
+ end
136
+
137
+ it "calculates the right percentage" do
138
+ example.stub(description: "The example description")
139
+ formatter.example_failed(example)
140
+ formatter.percentage.should be 20
141
+ end
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module CiserverFormatter
4
+ describe ProgressReporter do
5
+ let(:output_file) { double(:file) }
6
+ let(:progress_reporter) { ProgressReporter.new(output_file) }
7
+
8
+ it "Reports the status of the formatter" do
9
+ expected_output = """branch:branch_name
10
+ test_session_status:Pass
11
+ percentage_run:35
12
+ failed_count:0
13
+ pending_count:0
14
+ passed_count:35
15
+ example_count:100
16
+ """
17
+
18
+ formatter = double(:formatter)
19
+ formatter.stub(status: :pass, percentage: 35, failed_count: 0,
20
+ pending_count: 0, passed_count: 35, example_count: 100,
21
+ branch: "branch_name")
22
+
23
+ opened_file = double(:opened_file)
24
+ File.should_receive(:open).with(output_file, 'w').and_yield(opened_file)
25
+ opened_file.should_receive(:write).with(expected_output)
26
+ progress_reporter.report(formatter)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe CiserverFormatter::StatusReporter do
4
+ let(:formatter) { CiserverFormatter::CiserverFormatter.new(double(:string_io)) }
5
+ let(:output_file) { double(:file) }
6
+ let(:status_reporter) { CiserverFormatter::StatusReporter.new(output_file) }
7
+
8
+ describe "report_start" do
9
+ it "sets the status to testing" do
10
+ opened_file = double(:opened_file)
11
+ opened_file.should_receive(:write).with("Testing")
12
+ File.should_receive(:open).with(output_file, 'w').and_yield(opened_file)
13
+ status_reporter.start
14
+ end
15
+ end
16
+
17
+ describe "report finish" do
18
+ it "sets the status to the formatter status" do
19
+ formatter.should_receive(:status).and_return(:pass)
20
+ opened_file = double(:opened_file)
21
+ opened_file.should_receive(:write).with(:Pass)
22
+ File.should_receive(:open).with(output_file, 'w').and_yield(opened_file)
23
+ status_reporter.finish(formatter)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ require 'ciserver_formatter'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ciserver_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Diego Alonso
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ description: Formatter for AdaptFMS CI server
31
+ email:
32
+ - diego.alonso@adaptfms.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - ciserver_formatter.gemspec
44
+ - lib/ciserver_formatter.rb
45
+ - lib/ciserver_formatter/ciserver_formatter.rb
46
+ - lib/ciserver_formatter/file_resolver.rb
47
+ - lib/ciserver_formatter/progress_reporter.rb
48
+ - lib/ciserver_formatter/status_reporter.rb
49
+ - lib/ciserver_formatter/version.rb
50
+ - spec/ciserver_formatter/ciserver_formatter_spec.rb
51
+ - spec/ciserver_formatter/progress_reporter_spec.rb
52
+ - spec/ciserver_formatter/status_reporter_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: http://www.adaptfms.com
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.24
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Formatter used when running rspec from the AdaptFMS CI server
78
+ test_files:
79
+ - spec/ciserver_formatter/ciserver_formatter_spec.rb
80
+ - spec/ciserver_formatter/progress_reporter_spec.rb
81
+ - spec/ciserver_formatter/status_reporter_spec.rb
82
+ - spec/spec_helper.rb