coveralls 0.6.0 → 0.6.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.
@@ -0,0 +1 @@
1
+ 1.9.3-p194
@@ -1,10 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - rbx-18mode
4
3
  - rbx-19mode
5
- - jruby-18mode
6
4
  - jruby-19mode
7
- - 1.8.7
8
5
  - 1.9.2
9
6
  - 1.9.3
7
+ - 2.0.0
10
8
  - ruby-head
@@ -24,9 +24,13 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency 'simplecov', ">= 0.7"
25
25
  end
26
26
 
27
+ unless ENV["CI"]
28
+ gem.add_development_dependency 'debugger'
29
+ end
30
+
27
31
  gem.add_runtime_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'
28
32
 
29
33
  gem.add_development_dependency 'rspec'
30
34
  gem.add_development_dependency 'rake'
31
-
35
+ gem.add_development_dependency 'webmock'
32
36
  end
@@ -6,14 +6,16 @@ require "coveralls/api"
6
6
  require "coveralls/simplecov"
7
7
 
8
8
  module Coveralls
9
+ extend self
9
10
 
10
- def self.wear!(*args)
11
+ attr_accessor :testing, :noisy, :adapter, :run_locally
12
+
13
+ def wear!(simplecov_setting=nil, &block)
11
14
  setup!
12
- start!(*args)
15
+ start! simplecov_setting, &block
13
16
  end
14
17
 
15
- def self.setup!
16
-
18
+ def setup!
17
19
  # Try to load up SimpleCov.
18
20
  @@adapter = nil
19
21
  if defined?(::SimpleCov)
@@ -36,11 +38,17 @@ module Coveralls
36
38
 
37
39
  end
38
40
 
39
- def self.start!(simplecov_setting = 'test_frameworks')
41
+ def start!(simplecov_setting = 'test_frameworks', &block)
40
42
  if @@adapter == :simplecov
41
43
  if simplecov_setting
42
44
  puts "[Coveralls] Using SimpleCov's '#{simplecov_setting}' settings.".green
43
- ::SimpleCov.start(simplecov_setting)
45
+ if block
46
+ else
47
+ ::SimpleCov.start(simplecov_setting)
48
+ end
49
+ elsif block
50
+ puts "[Coveralls] Using SimpleCov settings defined in block.".green
51
+ ::SimpleCov.start { instance_eval &block }
44
52
  else
45
53
  puts "[Coveralls] Using SimpleCov's default settings.".green
46
54
  ::SimpleCov.start
@@ -48,19 +56,22 @@ module Coveralls
48
56
  end
49
57
  end
50
58
 
51
- def self.should_run?
59
+ def should_run?
52
60
 
53
61
  # Fail early if we're not on Travis
54
- unless ENV["TRAVIS"] || ENV["COVERALLS_RUN_LOCALLY"]
62
+ unless ENV["CI"] || ENV["COVERALLS_RUN_LOCALLY"] || @testing
55
63
  puts "[Coveralls] Outside the Travis environment, not sending data.".yellow
56
64
  return false
57
65
  end
58
66
 
59
- if ENV["COVERALLS_RUN_LOCALLY"]
67
+ if ENV["COVERALLS_RUN_LOCALLY"] || @run_locally
60
68
  puts "[Coveralls] Creating a new job on Coveralls from local coverage results.".cyan
61
69
  end
62
70
 
63
71
  true
64
72
  end
65
73
 
74
+ def noisy?
75
+ ENV["COVERALLS_NOISY"] || @noisy
76
+ end
66
77
  end
@@ -30,7 +30,7 @@ module Coveralls
30
30
  private
31
31
 
32
32
  def self.disable_net_blockers!
33
- if defined?(WebMock)
33
+ if defined?(WebMock) &&
34
34
  allow = WebMock::Config.instance.allow || []
35
35
  WebMock::Config.instance.allow = [*allow].push API_HOST
36
36
  end
@@ -59,7 +59,7 @@ module Coveralls
59
59
 
60
60
  def self.apified_hash hash
61
61
  config = Coveralls::Configuration.configuration
62
- if ENV['TRAVIS'] || ENV['COVERALLS_DEBUG']
62
+ if ENV['CI'] || ENV['COVERALLS_DEBUG'] || Coveralls.testing
63
63
  puts "[Coveralls] Submiting with config:".yellow
64
64
  puts MultiJson.dump(config, :pretty => true).
65
65
  gsub(/"repo_token": "(.*?)"/,'"repo_token": "[secure]"').yellow
@@ -5,7 +5,7 @@ module Coveralls
5
5
 
6
6
  def self.configuration
7
7
  config = {
8
- :environment => self.relevant_env,
8
+ :environment => self.relevant_env,
9
9
  :git => git
10
10
  }
11
11
  yml = self.yaml_config
@@ -19,8 +19,10 @@ module Coveralls
19
19
  if ENV['TRAVIS']
20
20
  config[:service_job_id] = ENV['TRAVIS_JOB_ID']
21
21
  config[:service_name] = (yml ? yml['service_name'] : nil) || 'travis-ci'
22
- end
23
- if ENV["COVERALLS_RUN_LOCALLY"]
22
+ elsif ENV['CIRCLECI']
23
+ config[:service_job_id] = ENV['CIRCLE_BUILD_NUM']
24
+ config[:service_name] = 'circleci'
25
+ elsif ENV["COVERALLS_RUN_LOCALLY"] || Coveralls.testing
24
26
  config[:service_job_id] = nil
25
27
  config[:service_name] = 'coveralls-ruby'
26
28
  config[:service_event_type] = 'manual'
@@ -60,11 +62,11 @@ module Coveralls
60
62
 
61
63
  def self.git
62
64
  hash = {}
63
-
65
+
64
66
  Dir.chdir(root) do
65
67
 
66
68
  hash[:head] = {
67
- :id => `git log -1 --pretty=format:'%H'`,
69
+ :id => `git log -1 --pretty=format:'%H'`,
68
70
  :author_name => `git log -1 --pretty=format:'%aN'`,
69
71
  :author_email => `git log -1 --pretty=format:'%ae'`,
70
72
  :committer_name => `git log -1 --pretty=format:'%cN'`,
@@ -98,14 +100,31 @@ module Coveralls
98
100
  end
99
101
 
100
102
  def self.relevant_env
101
- {
102
- :travis_job_id => ENV['TRAVIS_JOB_ID'],
103
- :travis_pull_request => ENV['TRAVIS_PULL_REQUEST'],
104
- :pwd => self.pwd,
105
- :rails_root => self.rails_root,
103
+ hash = {
104
+ :pwd => self.pwd,
105
+ :rails_root => self.rails_root,
106
106
  :simplecov_root => simplecov_root,
107
107
  :gem_version => VERSION
108
108
  }
109
+
110
+ hash.merge! begin
111
+ if ENV['TRAVIS']
112
+ {
113
+ :travis_job_id => ENV['TRAVIS_JOB_ID'],
114
+ :travis_pull_request => ENV['TRAVIS_PULL_REQUEST']
115
+ }
116
+ elsif ENV['CIRCLECI']
117
+ {
118
+ :circleci_build_num => ENV['CIRCLE_BUILD_NUM'],
119
+ :branch => ENV['CIRCLE_BRANCH'],
120
+ :commit_sha => ENV['CIRCLE_SHA1']
121
+ }
122
+ else
123
+ {}
124
+ end
125
+ end
126
+
127
+ hash
109
128
  end
110
129
 
111
130
  end
@@ -2,30 +2,35 @@ module Coveralls
2
2
  module SimpleCov
3
3
  class Formatter
4
4
 
5
+ def display_result(result)
6
+ # Log which files would be submitted.
7
+ if result.files.length > 0
8
+ puts "[Coveralls] Some handy coverage stats:"
9
+ else
10
+ puts "[Coveralls] There are no covered files.".yellow
11
+ end
12
+ result.files.each do |f|
13
+ print " * "
14
+ print "#{short_filename(f.filename)}".cyan
15
+ print " => ".white
16
+ cov = "#{f.covered_percent.round}%"
17
+ if f.covered_percent > 90
18
+ print cov.green
19
+ elsif f.covered_percent > 80
20
+ print cov.yellow
21
+ else
22
+ print cov.red
23
+ end
24
+ puts ""
25
+ end
26
+ true
27
+ end
28
+
5
29
  def format(result)
6
30
 
7
31
  unless Coveralls.should_run?
8
- if ENV["COVERALLS_NOISY"]
9
- # Log which files would be submitted.
10
- if result.files.length > 0
11
- puts "[Coveralls] Some handy coverage stats:"
12
- else
13
- puts "[Coveralls] There are no covered files.".yellow
14
- end
15
- result.files.each do |f|
16
- print " * "
17
- print "#{short_filename(f.filename)}".cyan
18
- print " => ".white
19
- cov = "#{f.covered_percent.round}%"
20
- if f.covered_percent > 90
21
- print cov.green
22
- elsif f.covered_percent > 80
23
- print cov.yellow
24
- else
25
- print cov.red
26
- end
27
- puts ""
28
- end
32
+ if Coveralls.noisy?
33
+ display_result result
29
34
  end
30
35
  return
31
36
  end
@@ -65,19 +70,25 @@ module Coveralls
65
70
 
66
71
  # Post to Coveralls.
67
72
  API.post_json "jobs", {:source_files => source_files, :test_framework => result.command_name.downcase, :run_at => result.created_at}
73
+ puts output_message result
68
74
 
69
75
  true
70
76
 
71
77
  rescue Exception => e
78
+ display_error e
79
+ end
80
+
81
+ def display_error(e)
72
82
  puts "Coveralls encountered an exception:".red
73
83
  puts e.class.to_s.red
74
84
  puts e.message.red
75
85
  e.backtrace.each do |line|
76
86
  puts line.red
77
- end
87
+ end if e.backtrace
78
88
  if e.respond_to?(:response) && e.response
79
89
  puts e.response.to_s.red
80
90
  end
91
+ false
81
92
  end
82
93
 
83
94
  def output_message(result)
@@ -1,3 +1,3 @@
1
1
  module Coveralls
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coveralls do
4
+ before do
5
+ SimpleCov.stub(:start)
6
+ stub_api_post
7
+ Coveralls.testing = true
8
+ end
9
+
10
+ describe "#should_run?" do
11
+ it "outputs to stdout when running locally" do
12
+ Coveralls.testing = false
13
+ Coveralls.run_locally = true
14
+ silence do
15
+ Coveralls.should_run?
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#wear!" do
21
+ it "receives block" do
22
+ ::SimpleCov.should_receive(:start)
23
+ silence do
24
+ subject.wear! do
25
+ add_filter 's'
26
+ end
27
+ end
28
+ end
29
+
30
+ it "uses string" do
31
+ ::SimpleCov.should_receive(:start).with 'test_frameworks'
32
+ silence do
33
+ subject.wear! 'test_frameworks'
34
+ end
35
+ end
36
+
37
+ it "uses default" do
38
+ ::SimpleCov.should_receive(:start).with
39
+ silence do
40
+ subject.wear!
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#setup!" do
46
+ it "sets SimpleCov adapter" do
47
+ SimpleCovTmp = SimpleCov
48
+ Object.send :remove_const, :SimpleCov
49
+ silence { subject.setup! }
50
+ SimpleCov = SimpleCovTmp
51
+ end
52
+ end
53
+
54
+ after(:all) do
55
+ setup_formatter
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ def bar
8
+ @foo
9
+ end
10
+ end
@@ -2,12 +2,71 @@ require 'spec_helper'
2
2
 
3
3
  describe Coveralls::SimpleCov::Formatter do
4
4
 
5
- # it "fails unless we are on travis" do
6
- # Coveralls::SimpleCov::Formatter.new.format(nil).should be_false
7
- # end
5
+ before do
6
+ stub_api_post
7
+ end
8
8
 
9
- it "asserts true" do
10
- true.should be_true
11
- end
9
+ let(:result) {
10
+ def source_fixture(filename)
11
+ File.expand_path( File.join( File.dirname( __FILE__ ), 'fixtures', filename ) )
12
+ end
12
13
 
14
+ SimpleCov::Result.new({
15
+ source_fixture( 'sample.rb' ) => [nil, 1, 1, 1, nil, 0, 1, 1, nil, nil],
16
+ source_fixture( 'app/models/user.rb' ) => [nil, 1, 1, 1, 1, 0, 1, 0, nil, nil],
17
+ source_fixture( 'app/models/robot.rb' ) => [1, 1, 1, 1, nil, nil, 1, 0, nil, nil],
18
+ source_fixture( 'app/models/house.rb' ) => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
19
+ source_fixture( 'app/models/airplane.rb' ) => [0, 0, 0, 0, 0],
20
+ source_fixture( 'app/models/dog.rb' ) => [1, 1, 1, 1, 1],
21
+ source_fixture( 'app/controllers/sample.rb' ) => [nil, 1, 1, 1, nil, nil, 0, 0, nil, nil]
22
+ })
23
+ }
24
+
25
+ describe "#format" do
26
+ context "should run" do
27
+ before do
28
+ Coveralls.testing = true
29
+ Coveralls.noisy = false
30
+ end
31
+
32
+ it "posts json" do
33
+ result.files.should_not be_empty
34
+ silence do
35
+ Coveralls::SimpleCov::Formatter.new.format(result).should be_true
36
+ end
37
+ end
38
+ end
39
+
40
+ context "should not run, noisy" do
41
+ it "only displays result" do
42
+ silence do
43
+ Coveralls::SimpleCov::Formatter.new.display_result(result).should be_true
44
+ end
45
+ end
46
+ end
47
+
48
+ context "no files" do
49
+ let(:result) { SimpleCov::Result.new({}) }
50
+ it "shows note that no files have been covered" do
51
+ Coveralls.noisy = true
52
+ Coveralls.testing = false
53
+
54
+ silence do
55
+ expect do
56
+ Coveralls::SimpleCov::Formatter.new.format(result)
57
+ end.not_to raise_error
58
+ end
59
+ end
60
+ end
61
+
62
+ context "with api error" do
63
+ it "rescues" do
64
+ e = RestClient::ResourceNotFound.new mock('HTTP Response', :code => '502')
65
+ silence do
66
+ Coveralls::SimpleCov::Formatter.new.display_error(e).should be_false
67
+ end
68
+ end
69
+ end
70
+
71
+ end
13
72
  end
@@ -1,4 +1,5 @@
1
1
  require 'simplecov'
2
+ require 'webmock'
2
3
 
3
4
  class InceptionFormatter
4
5
  def format(result)
@@ -6,8 +7,22 @@ class InceptionFormatter
6
7
  end
7
8
  end
8
9
 
9
- SimpleCov.formatter = InceptionFormatter
10
- SimpleCov.start 'test_frameworks'
10
+ def setup_formatter
11
+ SimpleCov.formatter = if ENV['TRAVIS'] || ENV['COVERALLS_REPO_TOKEN']
12
+ InceptionFormatter
13
+ else
14
+ SimpleCov::Formatter::HTMLFormatter
15
+ end
16
+
17
+ # SimpleCov.start 'test_frameworks'
18
+ SimpleCov.start do
19
+ add_filter do |source_file|
20
+ source_file.filename =~ /spec/ && !(source_file.filename =~ /fixture/)
21
+ end
22
+ end
23
+ end
24
+
25
+ setup_formatter
11
26
 
12
27
  require 'coveralls'
13
28
 
@@ -15,4 +30,41 @@ RSpec.configure do |config|
15
30
  config.treat_symbols_as_metadata_keys_with_true_values = true
16
31
  config.run_all_when_everything_filtered = true
17
32
  config.filter_run :focus
33
+ config.include WebMock::API
34
+ config.after(:suite) do
35
+ WebMock.disable!
36
+ end
37
+ end
38
+
39
+ def stub_api_post
40
+ body = "{\"message\":\"\",\"url\":\"\"}"
41
+ stub_request(:post, Coveralls::API::API_BASE+"/jobs").with(
42
+ :body => /.+/,
43
+ :headers => {
44
+ 'Accept'=>'*/*; q=0.5, application/xml',
45
+ 'Accept-Encoding'=>'gzip, deflate',
46
+ 'Content-Length'=>/.+/,
47
+ 'Content-Type'=>/.+/,
48
+ 'User-Agent'=>'Ruby'
49
+ }
50
+ ).to_return(:status => 200, :body => body, :headers => {})
18
51
  end
52
+
53
+ def silence
54
+ return yield if ENV['silence'] == 'false'
55
+
56
+ silence_stream(STDOUT) do
57
+ yield
58
+ end
59
+ end
60
+
61
+ module Kernel
62
+ def silence_stream(stream)
63
+ old_stream = stream.dup
64
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
65
+ stream.sync = true
66
+ yield
67
+ ensure
68
+ stream.reopen(old_stream)
69
+ end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coveralls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-01 00:00:00.000000000 Z
13
+ date: 2013-03-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -92,6 +92,22 @@ dependencies:
92
92
  - - ! '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0.7'
95
+ - !ruby/object:Gem::Dependency
96
+ name: debugger
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
95
111
  - !ruby/object:Gem::Dependency
96
112
  name: rspec
97
113
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +140,22 @@ dependencies:
124
140
  - - ! '>='
125
141
  - !ruby/object:Gem::Version
126
142
  version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: webmock
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
127
159
  description: A Ruby implementation of the Coveralls API.
128
160
  email:
129
161
  - nick@lemurheavy.com
@@ -133,8 +165,8 @@ executables:
133
165
  extensions: []
134
166
  extra_rdoc_files: []
135
167
  files:
136
- - .coveralls.yml
137
168
  - .gitignore
169
+ - .rbenv-version
138
170
  - .rspec
139
171
  - .travis.yml
140
172
  - Gemfile
@@ -150,6 +182,14 @@ files:
150
182
  - lib/coveralls/simplecov.rb
151
183
  - lib/coveralls/version.rb
152
184
  - spec/coveralls/configuration_spec.rb
185
+ - spec/coveralls/coveralls_spec.rb
186
+ - spec/coveralls/fixtures/app/controllers/sample.rb
187
+ - spec/coveralls/fixtures/app/models/airplane.rb
188
+ - spec/coveralls/fixtures/app/models/dog.rb
189
+ - spec/coveralls/fixtures/app/models/house.rb
190
+ - spec/coveralls/fixtures/app/models/robot.rb
191
+ - spec/coveralls/fixtures/app/models/user.rb
192
+ - spec/coveralls/fixtures/sample.rb
153
193
  - spec/coveralls/simplecov_spec.rb
154
194
  - spec/spec_helper.rb
155
195
  homepage: http://coveralls.io
@@ -178,5 +218,13 @@ specification_version: 3
178
218
  summary: A Ruby implementation of the Coveralls API.
179
219
  test_files:
180
220
  - spec/coveralls/configuration_spec.rb
221
+ - spec/coveralls/coveralls_spec.rb
222
+ - spec/coveralls/fixtures/app/controllers/sample.rb
223
+ - spec/coveralls/fixtures/app/models/airplane.rb
224
+ - spec/coveralls/fixtures/app/models/dog.rb
225
+ - spec/coveralls/fixtures/app/models/house.rb
226
+ - spec/coveralls/fixtures/app/models/robot.rb
227
+ - spec/coveralls/fixtures/app/models/user.rb
228
+ - spec/coveralls/fixtures/sample.rb
181
229
  - spec/coveralls/simplecov_spec.rb
182
230
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- repo_secret_token: 1NlQMLuOhf9NAFElxHAxVKxIWzv3oAYW5