coveralls_reborn 0.8.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
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 "#will_run?" do
11
+ it "checks CI environemnt variables" do
12
+ Coveralls.will_run?.should be_truthy
13
+ end
14
+
15
+ context "with CI disabled" do
16
+ before do
17
+ @ci = ENV['CI']
18
+ ENV['CI'] = nil
19
+ @coveralls_run_locally = ENV['COVERALLS_RUN_LOCALLY']
20
+ ENV['COVERALLS_RUN_LOCALLY'] = nil
21
+
22
+ Coveralls.testing = false
23
+ end
24
+
25
+ after do
26
+ ENV['CI'] = @ci
27
+ ENV['COVERALLS_RUN_LOCALLY'] = @coveralls_run_locally
28
+ end
29
+
30
+ it "indicates no run" do
31
+ Coveralls.will_run?.should be_falsy
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#should_run?" do
37
+ it "outputs to stdout when running locally" do
38
+ Coveralls.testing = false
39
+ Coveralls.run_locally = true
40
+ silence do
41
+ Coveralls.should_run?
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#wear!" do
47
+ it "receives block" do
48
+ ::SimpleCov.should_receive(:start)
49
+ silence do
50
+ subject.wear! do
51
+ add_filter 's'
52
+ end
53
+ end
54
+ end
55
+
56
+ it "uses string" do
57
+ ::SimpleCov.should_receive(:start).with 'test_frameworks'
58
+ silence do
59
+ subject.wear! 'test_frameworks'
60
+ end
61
+ end
62
+
63
+ it "uses default" do
64
+ ::SimpleCov.should_receive(:start).with no_args
65
+ silence do
66
+ subject.wear!
67
+ end
68
+ ::SimpleCov.filters.map(&:filter_argument).should include 'vendor'
69
+ end
70
+ end
71
+
72
+ describe "#wear_merged!" do
73
+ it "sets formatter to NilFormatter" do
74
+ ::SimpleCov.should_receive(:start).with 'rails'
75
+ silence do
76
+ subject.wear_merged! 'rails' do
77
+ add_filter "/spec/"
78
+ end
79
+ end
80
+ ::SimpleCov.formatter.should be Coveralls::NilFormatter
81
+ end
82
+ end
83
+
84
+ describe "#push!" do
85
+ it "sends existing test results" do
86
+ result = false
87
+ silence do
88
+ result = subject.push!
89
+ end
90
+ result.should be_truthy
91
+ end
92
+ end
93
+
94
+ describe "#setup!" do
95
+ it "sets SimpleCov adapter" do
96
+ SimpleCovTmp = SimpleCov
97
+ Object.send :remove_const, :SimpleCov
98
+ silence { subject.setup! }
99
+ SimpleCov = SimpleCovTmp
100
+ end
101
+ end
102
+
103
+ after(:all) do
104
+ setup_formatter
105
+ end
106
+ end
@@ -0,0 +1,12 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ # :nocov:
8
+ def bar
9
+ @foo
10
+ end
11
+ # :nocov:
12
+ 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 @@
1
+ # this file should not be covered
@@ -0,0 +1,12 @@
1
+ # Foo class
2
+ class Foo
3
+ def initialize
4
+ @foo = 'baz'
5
+ end
6
+
7
+ # :nocov:
8
+ def bar
9
+ @foo
10
+ end
11
+ # :nocov:
12
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coveralls::Output do
4
+ it "defaults the IO to $stdout" do
5
+ old_stdout = $stdout
6
+ out = StringIO.new
7
+ $stdout = out
8
+ Coveralls::Output.puts "this is a test"
9
+ expect(out.string).to eq "this is a test\n"
10
+ $stdout = old_stdout
11
+ end
12
+
13
+ it "accepts an IO injection" do
14
+ out = StringIO.new
15
+ Coveralls::Output.output = out
16
+ Coveralls::Output.puts "this is a test"
17
+ expect(out.string).to eq "this is a test\n"
18
+ end
19
+
20
+ describe ".puts" do
21
+ it "accepts an IO injection" do
22
+ out = StringIO.new
23
+ Coveralls::Output.puts "this is a test", output: out
24
+ expect(out.string).to eq "this is a test\n"
25
+ end
26
+ end
27
+
28
+ describe ".print" do
29
+ it "accepts an IO injection" do
30
+ out = StringIO.new
31
+ Coveralls::Output.print "this is a test", output: out
32
+ expect(out.string).to eq "this is a test"
33
+ end
34
+ end
35
+
36
+ describe 'when silenced' do
37
+ before do
38
+ @original_stdout = $stdout
39
+ @output = StringIO.new
40
+ Coveralls::Output.silent = true
41
+ $stdout = @output
42
+ end
43
+ it "should not puts" do
44
+ Coveralls::Output.puts "foo"
45
+ @output.rewind
46
+ @output.read.should == ""
47
+ end
48
+ it "should not print" do
49
+ Coveralls::Output.print "foo"
50
+ @output.rewind
51
+ @output.read.should == ""
52
+ end
53
+ after do
54
+ $stdout = @original_stdout
55
+ end
56
+ end
57
+
58
+ describe '.format' do
59
+ it "accepts a color argument" do
60
+ require 'term/ansicolor'
61
+ string = 'Hello'
62
+ ansi_color_string = Term::ANSIColor.red(string)
63
+ Coveralls::Output.format(string, color: 'red').should eq(ansi_color_string)
64
+ end
65
+
66
+ it "also accepts no color arguments" do
67
+ unformatted_string = "Hi Doggie!"
68
+ Coveralls::Output.format(unformatted_string).should eq(unformatted_string)
69
+ end
70
+
71
+ it "rejects formats unrecognized by Term::ANSIColor" do
72
+ string = 'Hi dog!'
73
+ Coveralls::Output.format(string, color: "not_a_real_color").should eq(string)
74
+ end
75
+
76
+ it "accepts more than 1 color argument" do
77
+ string = 'Hi dog!'
78
+ multi_formatted_string = Term::ANSIColor.red{ Term::ANSIColor.underline(string) }
79
+ Coveralls::Output.format(string, color: 'red underline').should eq(multi_formatted_string)
80
+ end
81
+
82
+ context "no color" do
83
+ before { Coveralls::Output.no_color = true }
84
+
85
+ it "does not add color to string" do
86
+ unformatted_string = "Hi Doggie!"
87
+ Coveralls::Output.format(unformatted_string, color: 'red').
88
+ should eq(unformatted_string)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coveralls::SimpleCov::Formatter do
4
+
5
+ before do
6
+ stub_api_post
7
+ end
8
+
9
+ def source_fixture(filename)
10
+ File.expand_path( File.join( File.dirname( __FILE__ ), 'fixtures', filename ) )
11
+ end
12
+
13
+ let(:result) {
14
+
15
+ SimpleCov::Result.new({
16
+ source_fixture( 'sample.rb' ) => [nil, 1, 1, 1, nil, 0, 1, 1, nil, nil],
17
+ source_fixture( 'app/models/user.rb' ) => [nil, 1, 1, 1, 1, 0, 1, 0, nil, nil],
18
+ source_fixture( 'app/models/robot.rb' ) => [1, 1, 1, 1, nil, nil, 1, 0, nil, nil],
19
+ source_fixture( 'app/models/house.rb' ) => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
20
+ source_fixture( 'app/models/airplane.rb' ) => [0, 0, 0, 0, 0],
21
+ source_fixture( 'app/models/dog.rb' ) => [1, 1, 1, 1, 1],
22
+ source_fixture( 'app/controllers/sample.rb' ) => [nil, 1, 1, 1, nil, 0, 1, 1, nil, nil]
23
+ })
24
+ }
25
+
26
+ describe "#format" do
27
+ context "should run" do
28
+ before do
29
+ Coveralls.testing = true
30
+ Coveralls.noisy = false
31
+ end
32
+
33
+ it "posts json" do
34
+ result.files.should_not be_empty
35
+ silence do
36
+ Coveralls::SimpleCov::Formatter.new.format(result).should be_truthy
37
+ end
38
+ end
39
+ end
40
+
41
+ context "should not run, noisy" do
42
+ it "only displays result" do
43
+ silence do
44
+ Coveralls::SimpleCov::Formatter.new.display_result(result).should be_truthy
45
+ end
46
+ end
47
+ end
48
+
49
+ context "no files" do
50
+ let(:result) { SimpleCov::Result.new({}) }
51
+ it "shows note that no files have been covered" do
52
+ Coveralls.noisy = true
53
+ Coveralls.testing = false
54
+
55
+ silence do
56
+ expect do
57
+ Coveralls::SimpleCov::Formatter.new.format(result)
58
+ end.not_to raise_error
59
+ end
60
+ end
61
+ end
62
+
63
+ context "with api error" do
64
+ it "rescues" do
65
+ e = SocketError.new
66
+
67
+ silence do
68
+ Coveralls::SimpleCov::Formatter.new.display_error(e).should be_falsy
69
+ end
70
+ end
71
+ end
72
+
73
+ context "#get_source_files" do
74
+ let(:source_files) { Coveralls::SimpleCov::Formatter.new.get_source_files(result) }
75
+ it "nils the skipped lines" do
76
+ source_file = source_files.first
77
+ source_file[:coverage].should_not eq result.files.first.coverage
78
+ source_file[:coverage].should eq [nil, 1, 1, 1, nil, 0, nil, nil, nil, nil, nil]
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,82 @@
1
+ require 'simplecov'
2
+ require 'webmock'
3
+ require 'vcr'
4
+
5
+ require 'pry'
6
+
7
+ class InceptionFormatter
8
+ def format(result)
9
+ Coveralls::SimpleCov::Formatter.new.format(result)
10
+ end
11
+ end
12
+
13
+ def setup_formatter
14
+ SimpleCov.formatter = if ENV['TRAVIS'] || ENV['COVERALLS_REPO_TOKEN']
15
+ InceptionFormatter
16
+ else
17
+ SimpleCov::Formatter::HTMLFormatter
18
+ end
19
+
20
+ # SimpleCov.start 'test_frameworks'
21
+ SimpleCov.start do
22
+ add_filter do |source_file|
23
+ source_file.filename =~ /spec/ && !(source_file.filename =~ /fixture/)
24
+ end
25
+ end
26
+ end
27
+
28
+ setup_formatter
29
+
30
+ require 'coveralls'
31
+
32
+ VCR.configure do |c|
33
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
34
+ c.hook_into :webmock
35
+ end
36
+
37
+ RSpec.configure do |config|
38
+ config.run_all_when_everything_filtered = true
39
+ config.filter_run :focus
40
+ config.include WebMock::API
41
+ config.expect_with :rspec do |c|
42
+ c.syntax = [:should, :expect]
43
+ end
44
+ config.mock_with :rspec do |c|
45
+ c.syntax = [:should, :expect]
46
+ end
47
+ config.after(:suite) do
48
+ WebMock.disable!
49
+ end
50
+ end
51
+
52
+ def stub_api_post
53
+ body = "{\"message\":\"\",\"url\":\"\"}"
54
+ stub_request(:post, Coveralls::API::API_BASE+"/jobs").with(
55
+ headers: {
56
+ 'Accept'=>'*/*; q=0.5, application/xml',
57
+ 'Accept-Encoding'=>'gzip, deflate',
58
+ 'Content-Length'=>/.+/,
59
+ 'Content-Type'=>/.+/,
60
+ 'User-Agent'=>'Ruby'
61
+ }
62
+ ).to_return(status: 200, body: body, headers: {})
63
+ end
64
+
65
+ def silence
66
+ return yield if ENV['silence'] == 'false'
67
+
68
+ silence_stream(STDOUT) do
69
+ yield
70
+ end
71
+ end
72
+
73
+ module Kernel
74
+ def silence_stream(stream)
75
+ old_stream = stream.dup
76
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
77
+ stream.sync = true
78
+ yield
79
+ ensure
80
+ stream.reopen(old_stream)
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coveralls_reborn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.21
5
+ platform: ruby
6
+ authors:
7
+ - Geremia Taglialatela
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: tins
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: term-ansicolor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.20.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.20.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ description: A Ruby implementation of the Coveralls API.
98
+ email:
99
+ - tagliala.dev@gmail.com
100
+ executables:
101
+ - coveralls
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - CHANGELOG.md
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - bin/coveralls
115
+ - coveralls-ruby.gemspec
116
+ - lib/coveralls.rb
117
+ - lib/coveralls/api.rb
118
+ - lib/coveralls/command.rb
119
+ - lib/coveralls/configuration.rb
120
+ - lib/coveralls/output.rb
121
+ - lib/coveralls/rake/task.rb
122
+ - lib/coveralls/simplecov.rb
123
+ - lib/coveralls/version.rb
124
+ - spec/coveralls/configuration_spec.rb
125
+ - spec/coveralls/coveralls_spec.rb
126
+ - spec/coveralls/fixtures/app/controllers/sample.rb
127
+ - spec/coveralls/fixtures/app/models/airplane.rb
128
+ - spec/coveralls/fixtures/app/models/dog.rb
129
+ - spec/coveralls/fixtures/app/models/house.rb
130
+ - spec/coveralls/fixtures/app/models/robot.rb
131
+ - spec/coveralls/fixtures/app/models/user.rb
132
+ - spec/coveralls/fixtures/app/vendor/vendored_gem.rb
133
+ - spec/coveralls/fixtures/sample.rb
134
+ - spec/coveralls/output_spec.rb
135
+ - spec/coveralls/simplecov_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: https://coveralls.io
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 1.9.3
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.6.13
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: A Ruby implementation of the Coveralls API.
161
+ test_files:
162
+ - spec/coveralls/configuration_spec.rb
163
+ - spec/coveralls/coveralls_spec.rb
164
+ - spec/coveralls/fixtures/app/controllers/sample.rb
165
+ - spec/coveralls/fixtures/app/models/airplane.rb
166
+ - spec/coveralls/fixtures/app/models/dog.rb
167
+ - spec/coveralls/fixtures/app/models/house.rb
168
+ - spec/coveralls/fixtures/app/models/robot.rb
169
+ - spec/coveralls/fixtures/app/models/user.rb
170
+ - spec/coveralls/fixtures/app/vendor/vendored_gem.rb
171
+ - spec/coveralls/fixtures/sample.rb
172
+ - spec/coveralls/output_spec.rb
173
+ - spec/coveralls/simplecov_spec.rb
174
+ - spec/spec_helper.rb