starting_blocks 0.0.8 → 0.0.9
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/lib/starting_blocks/displayable.rb +18 -0
- data/lib/starting_blocks/publisher.rb +30 -0
- data/lib/starting_blocks/result_parser.rb +20 -0
- data/lib/starting_blocks/runner.rb +9 -4
- data/lib/starting_blocks/version.rb +1 -1
- data/lib/starting_blocks/watcher.rb +22 -21
- data/lib/starting_blocks.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/starting_blocks/publisher_spec.rb +114 -0
- data/spec/starting_blocks/result_parser_spec.rb +86 -0
- data/starting_blocks.gemspec +3 -0
- metadata +62 -5
@@ -0,0 +1,18 @@
|
|
1
|
+
module StartingBlocks
|
2
|
+
|
3
|
+
module Displayable
|
4
|
+
module ClassMethods
|
5
|
+
def display message
|
6
|
+
puts message if @verbose
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(receiver)
|
14
|
+
receiver.extend ClassMethods
|
15
|
+
receiver.send :include, InstanceMethods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module StartingBlocks
|
2
|
+
module Publisher
|
3
|
+
class << self
|
4
|
+
attr_accessor :subscribers, :result_parser
|
5
|
+
|
6
|
+
def publish_results results
|
7
|
+
return unless @subscribers
|
8
|
+
@subscribers.each do |s|
|
9
|
+
parsed_results = StartingBlocks::Publisher.result_parser.parse(results)
|
10
|
+
begin
|
11
|
+
s.receive_results parsed_results
|
12
|
+
rescue
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def publish_specs_to_run specs
|
18
|
+
return unless @subscribers
|
19
|
+
@subscribers.each do |s|
|
20
|
+
begin
|
21
|
+
s.receive_specs_to_run specs
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
StartingBlocks::Publisher.subscribers = []
|
30
|
+
StartingBlocks::Publisher.result_parser = StartingBlocks::ResultParser.new
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module StartingBlocks
|
2
|
+
class ResultParser
|
3
|
+
def parse(text)
|
4
|
+
{
|
5
|
+
tests: get_count_of('tests', text),
|
6
|
+
assertions: get_count_of('assertions', text),
|
7
|
+
failures: get_count_of('failures', text),
|
8
|
+
errors: get_count_of('errors', text),
|
9
|
+
skips: get_count_of('skips', text)
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_count_of name, text
|
14
|
+
text.scan(/(\d+ #{name})/)[-1][0].split(' ')[0].to_i
|
15
|
+
rescue
|
16
|
+
0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -1,19 +1,24 @@
|
|
1
1
|
module StartingBlocks
|
2
2
|
class Runner
|
3
|
+
|
4
|
+
include Displayable
|
5
|
+
|
3
6
|
def initialize options
|
4
7
|
@verbose = options[:verbose]
|
5
8
|
end
|
6
9
|
|
7
10
|
def run_files specs
|
8
|
-
requires = specs.map { |x| "require '#{x}'" }.join("\n")
|
9
11
|
display "Specs to run: #{specs.inspect}"
|
10
|
-
|
12
|
+
results = execute_these_specs specs
|
13
|
+
StartingBlocks::Publisher.publish_results results
|
14
|
+
puts results
|
11
15
|
end
|
12
16
|
|
13
17
|
private
|
14
18
|
|
15
|
-
def
|
16
|
-
|
19
|
+
def execute_these_specs specs
|
20
|
+
requires = specs.map { |x| "require '#{x}'" }.join("\n")
|
21
|
+
`ruby -e "#{requires}"`
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -2,44 +2,45 @@ require 'fssm'
|
|
2
2
|
|
3
3
|
module StartingBlocks
|
4
4
|
module Watcher
|
5
|
+
|
6
|
+
include Displayable
|
7
|
+
|
5
8
|
class << self
|
6
9
|
def start_watching(dir, options)
|
7
10
|
location = dir.getwd
|
8
|
-
|
11
|
+
all_files = Dir['**/*']
|
9
12
|
FSSM.monitor(location, '**/*') do
|
10
|
-
update {|base,
|
11
|
-
delete {|base,
|
12
|
-
create {|base,
|
13
|
+
update {|base, file_that_changed| StartingBlocks::Watcher.run_it file_that_changed, all_files, options }
|
14
|
+
delete {|base, file_that_changed| StartingBlocks::Watcher.delete_it file_that_changed, all_files, options }
|
15
|
+
create {|base, file_that_changed| StartingBlocks::Watcher.add_it file_that_changed, all_files, options }
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
def add_it(
|
17
|
-
return if
|
18
|
-
display "Adding: #{
|
19
|
-
|
19
|
+
def add_it(file_that_changed, all_files, options)
|
20
|
+
return if file_that_changed.index('.git') == 0
|
21
|
+
display "Adding: #{file_that_changed}"
|
22
|
+
all_files << file_that_changed
|
20
23
|
end
|
21
24
|
|
22
|
-
def run_it(
|
23
|
-
|
24
|
-
display "File to run is: #{file}"
|
25
|
-
display "Filename: #{filename}"
|
26
|
-
matches = files.select { |x| x.gsub('_spec.rb', '.rb').include?(filename) && x != file }
|
27
|
-
matches << file
|
28
|
-
specs = matches.select { |x| x.include?('_spec') && File.file?(x) }.map { |x| File.expand_path x }
|
25
|
+
def run_it(file_that_changed, all_files, options)
|
26
|
+
specs = get_the_specs_to_run file_that_changed, all_files
|
29
27
|
display "Matches: #{specs.inspect}"
|
30
28
|
StartingBlocks::Runner.new(options).run_files specs
|
31
29
|
end
|
32
30
|
|
33
|
-
def delete_it(
|
34
|
-
return if
|
35
|
-
display "Deleting: #{
|
36
|
-
|
31
|
+
def delete_it(file_that_changed, all_files, options)
|
32
|
+
return if file_that_changed.index('.git') == 0
|
33
|
+
display "Deleting: #{file_that_changed}"
|
34
|
+
all_files.delete(file_that_changed)
|
37
35
|
end
|
38
36
|
|
39
37
|
private
|
40
38
|
|
41
|
-
def
|
42
|
-
|
39
|
+
def get_the_specs_to_run(file_that_changed, all_files)
|
40
|
+
filename = file_that_changed.downcase.split('/')[-1].gsub('_spec', '')
|
41
|
+
matches = all_files.select { |x| x.gsub('_spec.rb', '.rb').include?(filename) && x != file_that_changed }
|
42
|
+
matches << file_that_changed
|
43
|
+
specs = matches.select { |x| x.include?('_spec') && File.file?(x) }.map { |x| File.expand_path x }
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
data/lib/starting_blocks.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "starting_blocks/version"
|
2
|
+
require_relative 'starting_blocks/displayable'
|
2
3
|
require_relative 'starting_blocks/runner'
|
3
4
|
require_relative 'starting_blocks/watcher'
|
5
|
+
require_relative 'starting_blocks/result_parser'
|
6
|
+
require_relative 'starting_blocks/publisher'
|
4
7
|
|
5
8
|
module StartingBlocks
|
6
9
|
# Your code goes here...
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe StartingBlocks::Publisher do
|
4
|
+
|
5
|
+
let(:results) { Object.new }
|
6
|
+
let(:parsed_results) { Object.new }
|
7
|
+
let(:result_parser) { mock() }
|
8
|
+
let(:specs) { Object.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
result_parser.stubs(:parse).with(results).returns parsed_results
|
12
|
+
StartingBlocks::Publisher.result_parser = result_parser
|
13
|
+
end
|
14
|
+
|
15
|
+
it "subscribers should be empty" do
|
16
|
+
StartingBlocks::Publisher.subscribers.count.must_equal 0
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#publish_results" do
|
20
|
+
describe "one subscriber" do
|
21
|
+
it "should pass the results to the subscriber" do
|
22
|
+
subscriber = mock()
|
23
|
+
subscriber.expects(:receive_results).with(parsed_results)
|
24
|
+
StartingBlocks::Publisher.subscribers = [subscriber]
|
25
|
+
StartingBlocks::Publisher.publish_results results
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "two subscribers" do
|
30
|
+
it "should pass the results to the subscriber" do
|
31
|
+
first_subscriber = mock()
|
32
|
+
first_subscriber.expects(:receive_results).with(parsed_results)
|
33
|
+
second_subscriber = mock()
|
34
|
+
second_subscriber.expects(:receive_results).with(parsed_results)
|
35
|
+
StartingBlocks::Publisher.subscribers = [first_subscriber, second_subscriber]
|
36
|
+
StartingBlocks::Publisher.publish_results results
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "nil subscribers" do
|
41
|
+
it "should not error" do
|
42
|
+
StartingBlocks::Publisher.subscribers = nil
|
43
|
+
StartingBlocks::Publisher.publish_results results
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "no subscribers" do
|
48
|
+
it "should not error" do
|
49
|
+
StartingBlocks::Publisher.subscribers = []
|
50
|
+
StartingBlocks::Publisher.publish_results results
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "subscriber with no method to receive" do
|
55
|
+
it "should pass the results to the subscriber" do
|
56
|
+
first_subscriber = mock()
|
57
|
+
first_subscriber.expects(:receive_results).with(parsed_results)
|
58
|
+
second_subscriber = Object.new
|
59
|
+
third_subscriber = mock()
|
60
|
+
third_subscriber.expects(:receive_results).with(parsed_results)
|
61
|
+
StartingBlocks::Publisher.subscribers = [first_subscriber, second_subscriber, third_subscriber]
|
62
|
+
StartingBlocks::Publisher.publish_results results
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#publish_specs_to_run" do
|
68
|
+
describe "one subscriber" do
|
69
|
+
it "should pass the specs to the subscriber" do
|
70
|
+
subscriber = mock()
|
71
|
+
subscriber.expects(:receive_specs_to_run).with(specs)
|
72
|
+
StartingBlocks::Publisher.subscribers = [subscriber]
|
73
|
+
StartingBlocks::Publisher.publish_specs_to_run specs
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "two subscribers" do
|
78
|
+
it "should pass the specs to the subscriber" do
|
79
|
+
first_subscriber = mock()
|
80
|
+
first_subscriber.expects(:receive_specs_to_run).with(specs)
|
81
|
+
second_subscriber = mock()
|
82
|
+
second_subscriber.expects(:receive_specs_to_run).with(specs)
|
83
|
+
StartingBlocks::Publisher.subscribers = [first_subscriber, second_subscriber]
|
84
|
+
StartingBlocks::Publisher.publish_specs_to_run specs
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "nil subscribers" do
|
89
|
+
it "should not error" do
|
90
|
+
StartingBlocks::Publisher.subscribers = nil
|
91
|
+
StartingBlocks::Publisher.publish_specs_to_run specs
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "no subscribers" do
|
96
|
+
it "should not error" do
|
97
|
+
StartingBlocks::Publisher.subscribers = []
|
98
|
+
StartingBlocks::Publisher.publish_specs_to_run specs
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "subscriber with no method to receive" do
|
103
|
+
it "should not error" do
|
104
|
+
first_subscriber = mock()
|
105
|
+
first_subscriber.expects(:receive_specs_to_run).with(specs)
|
106
|
+
second_subscriber = Object.new
|
107
|
+
third_subscriber = mock()
|
108
|
+
third_subscriber.expects(:receive_specs_to_run).with(specs)
|
109
|
+
StartingBlocks::Publisher.subscribers = [first_subscriber, second_subscriber, third_subscriber]
|
110
|
+
StartingBlocks::Publisher.publish_specs_to_run specs
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe StartingBlocks::ResultParser do
|
4
|
+
describe "simple case" do
|
5
|
+
let(:text) do <<EOF
|
6
|
+
Fabulous tests in 0.000372s, 2688.1720 tests/s, 2688.1720 assertions/s.
|
7
|
+
|
8
|
+
2 tests, 3 assertions, 4 failures, 5 errors, 6 skips
|
9
|
+
|
10
|
+
asldkjflaskjflsakj
|
11
|
+
EOF
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:expected_results) do
|
15
|
+
{
|
16
|
+
tests: 2,
|
17
|
+
assertions: 3,
|
18
|
+
failures: 4,
|
19
|
+
errors: 5,
|
20
|
+
skips: 6
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def subject
|
25
|
+
StartingBlocks::ResultParser.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the counts" do
|
29
|
+
subject.parse(text).contrast_with! expected_results
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "another case" do
|
34
|
+
let(:text) do <<EOF
|
35
|
+
aaaaa
|
36
|
+
801 tests, 30014 assertions, 432 failures, 234 errors, 2141 skips
|
37
|
+
bbbbbb
|
38
|
+
EOF
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:expected_results) do
|
42
|
+
{
|
43
|
+
tests: 801,
|
44
|
+
assertions: 30014,
|
45
|
+
failures: 432,
|
46
|
+
errors: 234,
|
47
|
+
skips: 2141
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def subject
|
52
|
+
StartingBlocks::ResultParser.new
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return the counts" do
|
56
|
+
subject.parse(text).contrast_with! expected_results
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "unparsable text" do
|
61
|
+
let(:text) do <<EOF
|
62
|
+
aaaaa
|
63
|
+
lkjsdlfkjslkjslkjalskjfsalkjfd
|
64
|
+
bbbbbb
|
65
|
+
EOF
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:expected_results) do
|
69
|
+
{
|
70
|
+
tests: 0,
|
71
|
+
assertions: 0,
|
72
|
+
failures: 0,
|
73
|
+
errors: 0,
|
74
|
+
skips: 0
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def subject
|
79
|
+
StartingBlocks::ResultParser.new
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return the counts" do
|
83
|
+
subject.parse(text).contrast_with! expected_results
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/starting_blocks.gemspec
CHANGED
@@ -20,5 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "contrast"
|
24
|
+
spec.add_development_dependency "subtle"
|
25
|
+
spec.add_development_dependency "mocha"
|
23
26
|
spec.add_runtime_dependency 'fssm'
|
24
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starting_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,54 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: contrast
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: subtle
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mocha
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
46
94
|
- !ruby/object:Gem::Dependency
|
47
95
|
name: fssm
|
48
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,9 +122,15 @@ files:
|
|
74
122
|
- Rakefile
|
75
123
|
- bin/sb
|
76
124
|
- lib/starting_blocks.rb
|
125
|
+
- lib/starting_blocks/displayable.rb
|
126
|
+
- lib/starting_blocks/publisher.rb
|
127
|
+
- lib/starting_blocks/result_parser.rb
|
77
128
|
- lib/starting_blocks/runner.rb
|
78
129
|
- lib/starting_blocks/version.rb
|
79
130
|
- lib/starting_blocks/watcher.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- spec/starting_blocks/publisher_spec.rb
|
133
|
+
- spec/starting_blocks/result_parser_spec.rb
|
80
134
|
- starting_blocks.gemspec
|
81
135
|
homepage: ''
|
82
136
|
licenses:
|
@@ -93,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
147
|
version: '0'
|
94
148
|
segments:
|
95
149
|
- 0
|
96
|
-
hash:
|
150
|
+
hash: 2423351663168125208
|
97
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
152
|
none: false
|
99
153
|
requirements:
|
@@ -102,11 +156,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
156
|
version: '0'
|
103
157
|
segments:
|
104
158
|
- 0
|
105
|
-
hash:
|
159
|
+
hash: 2423351663168125208
|
106
160
|
requirements: []
|
107
161
|
rubyforge_project:
|
108
162
|
rubygems_version: 1.8.25
|
109
163
|
signing_key:
|
110
164
|
specification_version: 3
|
111
165
|
summary: One command to run all tests, test watcher, etc.
|
112
|
-
test_files:
|
166
|
+
test_files:
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/starting_blocks/publisher_spec.rb
|
169
|
+
- spec/starting_blocks/result_parser_spec.rb
|