zaphod 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.org +1 -1
- data/lib/simplecov/formatter/zaphod_formatter.rb +12 -4
- data/lib/zaphod/change_set.rb +12 -2
- data/lib/zaphod/code_change.rb +4 -2
- data/lib/zaphod/git.rb +1 -1
- data/lib/zaphod/version.rb +1 -1
- data/lib/zaphod.rb +0 -1
- data/spec/simplecov/formatter/zaphod_formatter_spec.rb +5 -6
- data/spec/zaphod/change_set_spec.rb +30 -1
- data/spec/zaphod/code_change_spec.rb +26 -0
- metadata +2 -4
- data/.bundle/config +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9716d2d2bc5d2523195132e42ef2cfe697956449
|
4
|
+
data.tar.gz: 02e7e816192a3437b1a2c6b946ed6a97780bf018
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c96b73e834d184a91993a6f95f7a74bb101d7bc2763f1f4a99bcbbf1bf670fbcc8f34172b6fc06ff31365f2223fc6f3f62b750778ee7b91650921d7da95cb15d
|
7
|
+
data.tar.gz: 7a4d12e3294f2e00b87ab66545f7e6ca9ffbd6ff2d29c10099c2bb5d460f27e28f2a71b2e973f8dd40ad4bafb281f09dd03ee34949705dd92d5fb844e4b07032
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.org
CHANGED
@@ -36,7 +36,7 @@ Catch, and publicly embarrass, untested commits into git.
|
|
36
36
|
Zaphod.setup do |configuration|
|
37
37
|
configuration.on_failure do
|
38
38
|
Pony.mail(
|
39
|
-
to: '
|
39
|
+
to: 'your-team@example.com',
|
40
40
|
subject: "Someone is trying to commit untested code!"
|
41
41
|
)
|
42
42
|
raise SystemExit.new( -1 )
|
@@ -3,9 +3,9 @@ require "zaphod/change_set"
|
|
3
3
|
module SimpleCov
|
4
4
|
module Formatter
|
5
5
|
# Send a set of File:Line tuples to a Zaphod class that intersects
|
6
|
-
# it with a set from the last git commit.
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# it with a set from the last git commit. Call the failure hook if
|
7
|
+
# the intersection reveals lines in the current changeset that are
|
8
|
+
# uncovered.
|
9
9
|
#
|
10
10
|
# Aborting with a non-zero exit code should propagate properly
|
11
11
|
# through SimpleCov.
|
@@ -21,7 +21,15 @@ module SimpleCov
|
|
21
21
|
uncovered_codeset = uncovered result
|
22
22
|
changed_codeset = source_control.changes
|
23
23
|
|
24
|
-
diff =
|
24
|
+
diff = changed_codeset.intersection( uncovered_codeset )
|
25
|
+
if $DEBUG || ENV["DEBUG"]
|
26
|
+
require "pp"
|
27
|
+
pp(
|
28
|
+
"--- UNCOVERED ---", uncovered_codeset,
|
29
|
+
"--- CHANGED ---", changed_codeset,
|
30
|
+
"--- DIFF ---", diff
|
31
|
+
)
|
32
|
+
end
|
25
33
|
unless diff.empty?
|
26
34
|
Zaphod.configuration.on_failure.call diff
|
27
35
|
end
|
data/lib/zaphod/change_set.rb
CHANGED
@@ -5,10 +5,20 @@ module Zaphod
|
|
5
5
|
class ChangeSet
|
6
6
|
extend Forwardable
|
7
7
|
attr_reader :changes
|
8
|
-
def_delegators :@changes, :empty?, :each, :map, :first, :length, :
|
8
|
+
def_delegators :@changes, :empty?, :each, :map, :first, :length, :include?, :add, :any?
|
9
9
|
|
10
|
-
def initialize( changes )
|
10
|
+
def initialize( changes=[] )
|
11
11
|
@changes = Set.new changes
|
12
12
|
end
|
13
|
+
|
14
|
+
def intersection( other )
|
15
|
+
changes.each_with_object( self.class.new ) do |change, set|
|
16
|
+
set.add( change ) if other.any? { |c| c.eql? change }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==( other )
|
21
|
+
changes == other.changes
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
data/lib/zaphod/code_change.rb
CHANGED
@@ -13,11 +13,13 @@ module Zaphod
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def hash()
|
16
|
-
[path
|
16
|
+
[path].hash
|
17
17
|
end
|
18
18
|
|
19
19
|
def inspect()
|
20
|
-
"
|
20
|
+
"#{self.class.name}.new(\"#{path}\", [\n" +
|
21
|
+
source.map( &:inspect ).join( ",\n" ) +
|
22
|
+
"])"
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/zaphod/git.rb
CHANGED
data/lib/zaphod/version.rb
CHANGED
data/lib/zaphod.rb
CHANGED
@@ -25,7 +25,10 @@ describe SimpleCov::Formatter::ZaphodFormatter do
|
|
25
25
|
context "when the uncovered lines include the current changes" do
|
26
26
|
let( :source_changes ) do
|
27
27
|
Zaphod::ChangeSet.new([
|
28
|
-
Zaphod::CodeChange.new(
|
28
|
+
Zaphod::CodeChange.new(
|
29
|
+
"./lib/zaphod/spike.rb",
|
30
|
+
[" @var = \"foo\"\n"]
|
31
|
+
)
|
29
32
|
])
|
30
33
|
end
|
31
34
|
|
@@ -41,15 +44,11 @@ describe SimpleCov::Formatter::ZaphodFormatter do
|
|
41
44
|
|
42
45
|
subject.format result
|
43
46
|
|
44
|
-
expect( failed ).to eq( source_changes
|
47
|
+
expect( failed ).to eq( source_changes )
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
51
|
context "when the uncovered lines do not include the current changes" do
|
49
|
-
before :each do
|
50
|
-
stub( source_control ).changes { Hash.new }
|
51
|
-
end
|
52
|
-
|
53
52
|
it "proceeds normally" do
|
54
53
|
subject.format result
|
55
54
|
end
|
@@ -52,7 +52,36 @@ module Zaphod
|
|
52
52
|
|
53
53
|
it do
|
54
54
|
expect( set1.intersection( set2 ) ).
|
55
|
-
to eq(
|
55
|
+
to eq( ChangeSet.new([ CodeChange.new( "/dev/null", ["baz"] ) ]) )
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the changes are 'eql' but not identical" do
|
59
|
+
let( :coverage_change ) do
|
60
|
+
CodeChange.new(
|
61
|
+
"/app/controllers/tags_controller.rb", [
|
62
|
+
" ) unless Tag.find_by_name(params[:tag_name])\n",
|
63
|
+
" respond_to do |format|\n",
|
64
|
+
" if tag.valid?\n",
|
65
|
+
" format.js {render :json => {:success => true, :message => \"Tag Creation Successful!\"}}\n",
|
66
|
+
" format.js {render :json => {:success => false, :message => tag.errors.inspect}}\n",
|
67
|
+
" puts \"ha HA! I'm a cheater!\"\n"])
|
68
|
+
end
|
69
|
+
|
70
|
+
let( :git_change ) do
|
71
|
+
CodeChange.new(
|
72
|
+
"/app/controllers/tags_controller.rb", [
|
73
|
+
"\n",
|
74
|
+
" def uncovered_method\n",
|
75
|
+
" puts \"ha HA! I'm a cheater!\"\n",
|
76
|
+
" end\n"])
|
77
|
+
end
|
78
|
+
|
79
|
+
let( :set1 ) { described_class.new([ coverage_change ]) }
|
80
|
+
let( :set2 ) { described_class.new([ git_change ]) }
|
81
|
+
|
82
|
+
it "does content based intersection" do
|
83
|
+
expect( set1.intersection( set2 ) ).to_not be_empty
|
84
|
+
end
|
56
85
|
end
|
57
86
|
end
|
58
87
|
end
|
@@ -56,6 +56,31 @@ module Zaphod
|
|
56
56
|
|
57
57
|
it( "is true" ) { expect( change1 ).to eql( change2 ) }
|
58
58
|
end
|
59
|
+
|
60
|
+
context "when weird things happen" do
|
61
|
+
let( :coverage_change ) do
|
62
|
+
CodeChange.new(
|
63
|
+
"/app/controllers/tags_controller.rb", [
|
64
|
+
" ) unless Tag.find_by_name(params[:tag_name])\n",
|
65
|
+
" respond_to do |format|\n",
|
66
|
+
" if tag.valid?\n",
|
67
|
+
" format.js {render :json => {:success => true, :message => \"Tag Creation Successful!\"}}\n",
|
68
|
+
" format.js {render :json => {:success => false, :message => tag.errors.inspect}}\n",
|
69
|
+
" puts \"ha HA! I'm a cheater!\"\n"])
|
70
|
+
end
|
71
|
+
|
72
|
+
let( :git_change ) do
|
73
|
+
CodeChange.new(
|
74
|
+
"/app/controllers/tags_controller.rb", [
|
75
|
+
"\n",
|
76
|
+
" def uncovered_method\n",
|
77
|
+
" puts \"ha HA! I'm a cheater!\"\n",
|
78
|
+
" end\n"])
|
79
|
+
end
|
80
|
+
|
81
|
+
it { expect( coverage_change ).to eql( git_change ) }
|
82
|
+
it { expect( coverage_change.hash ).to eql( git_change.hash ) }
|
83
|
+
end
|
59
84
|
end
|
60
85
|
|
61
86
|
describe "#hash" do
|
@@ -68,6 +93,7 @@ module Zaphod
|
|
68
93
|
end
|
69
94
|
|
70
95
|
it "differs for two changes that have inequal sources" do
|
96
|
+
pending "breaks Set intersection... think harder on this"
|
71
97
|
expect( change2.hash ).to_not eq( change3.hash )
|
72
98
|
end
|
73
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaphod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Tripp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grit
|
@@ -185,10 +185,8 @@ extensions: []
|
|
185
185
|
extra_rdoc_files:
|
186
186
|
- README.org
|
187
187
|
files:
|
188
|
-
- ".bundle/config"
|
189
188
|
- ".gitignore"
|
190
189
|
- ".rspec"
|
191
|
-
- ".ruby-version"
|
192
190
|
- Gemfile
|
193
191
|
- Gemfile.lock
|
194
192
|
- Guardfile
|
data/.bundle/config
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--- {}
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.0
|