guillaumegentil-rspactor 0.3.4 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/rspactor +2 -0
- data/bin/rspactor-system +3 -3
- data/lib/cucumber_growler.rb +61 -0
- data/lib/rspactor/growl.rb +2 -2
- data/lib/rspactor/inspector.rb +17 -7
- data/lib/rspactor/interactor.rb +5 -3
- data/lib/rspactor/runner.rb +51 -12
- data/lib/rspec_growler.rb +3 -5
- data/spec/inspector_spec.rb +14 -3
- data/spec/runner_spec.rb +9 -8
- metadata +3 -2
data/Rakefile
CHANGED
data/bin/rspactor
CHANGED
data/bin/rspactor-system
CHANGED
@@ -53,11 +53,11 @@ listener = RSpactor::Listener.new do |changed_files|
|
|
53
53
|
existing_targets = targets.select { |file| File.exist?(File.join(dir, file)) }
|
54
54
|
else
|
55
55
|
inspector = RSpactor::Inspector.new(dir)
|
56
|
-
existing_targets = inspector.
|
56
|
+
existing_targets = inspector.determine_files(changed_file).map do |file|
|
57
57
|
file.sub(dir + '/', '')
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
if not existing_targets.empty?
|
62
62
|
case existing_targets.first
|
63
63
|
when %r{^test/}
|
@@ -77,7 +77,7 @@ listener = RSpactor::Listener.new do |changed_files|
|
|
77
77
|
puts changed_file
|
78
78
|
system command
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
if $?.success?
|
82
82
|
Growl::notify $title, "You rock!", Growl::image_path('success')
|
83
83
|
else
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'cucumber'
|
2
|
+
require 'cucumber/formatter/console'
|
3
|
+
require File.dirname(__FILE__) + '/rspactor/growl'
|
4
|
+
|
5
|
+
module CucumberGrowler
|
6
|
+
include RSpactor::Growl
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
alias original_print_stats print_stats
|
11
|
+
include InstanceMethods
|
12
|
+
|
13
|
+
def print_stats(features)
|
14
|
+
title, icon, messages = '', '', []
|
15
|
+
[:failed, :skipped, :undefined, :pending, :passed].reverse.each do |status|
|
16
|
+
if step_mother.steps(status).any?
|
17
|
+
icon = icon_for(status)
|
18
|
+
title = title_for(status)
|
19
|
+
messages << dump_count(step_mother.steps(status).length, "step", status.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
notify "Cucumber Results", messages.reverse.join(' - '), icon
|
24
|
+
original_print_stats(features)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
def icon_for(status)
|
31
|
+
case status
|
32
|
+
when :passed
|
33
|
+
'success'
|
34
|
+
when :pending, :undefined, :skipped
|
35
|
+
'pending'
|
36
|
+
when :failed
|
37
|
+
'failed'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def title_for(status)
|
42
|
+
case status
|
43
|
+
when :passed
|
44
|
+
'Features passed!'
|
45
|
+
when :pending
|
46
|
+
'Some steps are pending...'
|
47
|
+
when :undefined
|
48
|
+
'Some undefined steps...'
|
49
|
+
when :skipped
|
50
|
+
'Some steps skipped...'
|
51
|
+
when :failed
|
52
|
+
'Failures occurred!'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
module Cucumber::Formatter::Console
|
60
|
+
include CucumberGrowler
|
61
|
+
end
|
data/lib/rspactor/growl.rb
CHANGED
@@ -2,8 +2,8 @@ module RSpactor
|
|
2
2
|
module Growl
|
3
3
|
extend self
|
4
4
|
|
5
|
-
def notify(title, msg,
|
6
|
-
system("growlnotify -w -n rspactor --image #{
|
5
|
+
def notify(title, msg, icon, pri = 0)
|
6
|
+
system("growlnotify -w -n rspactor --image #{image_path(icon)} -p #{pri} -m #{msg.inspect} #{title} &")
|
7
7
|
end
|
8
8
|
|
9
9
|
# failed | pending | success
|
data/lib/rspactor/inspector.rb
CHANGED
@@ -8,17 +8,20 @@ module RSpactor
|
|
8
8
|
@root = dir
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def determine_files(file)
|
12
12
|
candidates = translate(file)
|
13
|
+
cucumberable = candidates.delete('cucumber')
|
13
14
|
candidates.reject { |candidate| candidate.index('.') }.each do |dir|
|
14
15
|
candidates.reject! { |candidate| candidate.index("#{dir}/") == 0 }
|
15
16
|
end
|
16
|
-
|
17
|
+
files = candidates.select { |candidate| File.exists? candidate }
|
17
18
|
|
18
|
-
if
|
19
|
+
if files.empty? && !cucumberable
|
19
20
|
$stderr.puts "doesn't exist: #{candidates.inspect}"
|
20
21
|
end
|
21
|
-
|
22
|
+
|
23
|
+
files << 'cucumber' if cucumberable
|
24
|
+
files.uniq
|
22
25
|
end
|
23
26
|
|
24
27
|
# mappings for Rails are inspired by autotest mappings in rspec-rails
|
@@ -28,6 +31,8 @@ module RSpactor
|
|
28
31
|
|
29
32
|
if spec_file?(file)
|
30
33
|
candidates << file
|
34
|
+
elsif cucumber_file?(file)
|
35
|
+
candidates << 'cucumber'
|
31
36
|
else
|
32
37
|
spec_file = append_spec_file_extension(file)
|
33
38
|
|
@@ -55,8 +60,8 @@ module RSpactor
|
|
55
60
|
# lib/bar_spec.rb -> bar_spec.rb
|
56
61
|
candidates << candidates.last.sub(%r:\w+/:, '') if candidates.last.index('/')
|
57
62
|
when 'config/routes.rb'
|
58
|
-
candidates << 'controllers' << 'helpers' << 'views'
|
59
|
-
when 'config/database.yml', 'db/schema.rb'
|
63
|
+
candidates << 'controllers' << 'helpers' << 'views' << 'routing'
|
64
|
+
when 'config/database.yml', 'db/schema.rb', 'spec/factories.rb'
|
60
65
|
candidates << 'models'
|
61
66
|
when %r:^(spec/(spec_helper|shared/.*)|config/(boot|environment(s/test)?))\.rb$:, 'spec/spec.opts'
|
62
67
|
candidates << 'spec'
|
@@ -66,7 +71,9 @@ module RSpactor
|
|
66
71
|
end
|
67
72
|
|
68
73
|
candidates.map do |candidate|
|
69
|
-
if candidate
|
74
|
+
if candidate == 'cucumber'
|
75
|
+
candidate
|
76
|
+
elsif candidate.index('spec') == 0
|
70
77
|
File.join(@root, candidate)
|
71
78
|
else
|
72
79
|
File.join(@root, 'spec', candidate)
|
@@ -85,5 +92,8 @@ module RSpactor
|
|
85
92
|
def spec_file?(file)
|
86
93
|
file =~ /^spec\/.+_spec.rb$/
|
87
94
|
end
|
95
|
+
def cucumber_file?(file)
|
96
|
+
file =~ /^features\/.+$/
|
97
|
+
end
|
88
98
|
end
|
89
99
|
end
|
data/lib/rspactor/interactor.rb
CHANGED
@@ -2,14 +2,16 @@ require 'timeout'
|
|
2
2
|
|
3
3
|
module RSpactor
|
4
4
|
class Interactor
|
5
|
-
def initialize(dir)
|
5
|
+
def initialize(dir, options = {})
|
6
6
|
@root = dir
|
7
|
+
@options = options
|
7
8
|
ticker
|
8
9
|
end
|
9
10
|
|
10
|
-
def wait_for_enter_key(msg, seconds_to_wait)
|
11
|
+
def wait_for_enter_key(msg, seconds_to_wait, clear = false)
|
11
12
|
begin
|
12
13
|
Timeout::timeout(seconds_to_wait) do
|
14
|
+
system("clear;") if clear
|
13
15
|
ticker(:start => true, :msg => msg)
|
14
16
|
$stdin.gets
|
15
17
|
return true
|
@@ -27,7 +29,7 @@ module RSpactor
|
|
27
29
|
loop do
|
28
30
|
sleep 0.5
|
29
31
|
if $stdin.gets
|
30
|
-
if wait_for_enter_key("** Running all specs.. Hit <enter> again to exit RSpactor", 3)
|
32
|
+
if wait_for_enter_key("** Running all specs.. Hit <enter> again to exit RSpactor", 3, @options[:clear])
|
31
33
|
@main_thread.exit
|
32
34
|
exit
|
33
35
|
end
|
data/lib/rspactor/runner.rb
CHANGED
@@ -23,7 +23,7 @@ module RSpactor
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def start_interactor
|
26
|
-
@interactor = Interactor.new(dir)
|
26
|
+
@interactor = Interactor.new(dir, options)
|
27
27
|
aborted = @interactor.wait_for_enter_key("** Hit <enter> to skip initial spec run", 3)
|
28
28
|
@interactor.start_termination_handler
|
29
29
|
run_all_specs unless aborted
|
@@ -33,7 +33,7 @@ module RSpactor
|
|
33
33
|
@inspector = Inspector.new(dir)
|
34
34
|
|
35
35
|
Listener.new(Inspector::EXTENSIONS) do |files|
|
36
|
-
|
36
|
+
changed_files(files) unless git_head_changed?
|
37
37
|
end.run(dir)
|
38
38
|
end
|
39
39
|
|
@@ -62,6 +62,12 @@ module RSpactor
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def run_cucumber_command
|
66
|
+
cmd = [ruby_opts, cucumber_runner, cucumber_opts].flatten.join(' ')
|
67
|
+
@last_run_failed = run_command(cmd)
|
68
|
+
system('killall java') if options[:kill]
|
69
|
+
end
|
70
|
+
|
65
71
|
def last_run_failed?
|
66
72
|
@last_run_failed == false
|
67
73
|
end
|
@@ -69,20 +75,27 @@ module RSpactor
|
|
69
75
|
protected
|
70
76
|
|
71
77
|
def run_command(cmd)
|
72
|
-
$stderr.puts "#{cmd}"
|
73
78
|
system(cmd)
|
74
79
|
$?.success?
|
75
80
|
end
|
76
81
|
|
77
|
-
def
|
78
|
-
|
79
|
-
all.concat inspector.
|
82
|
+
def changed_files(files)
|
83
|
+
files = files.inject([]) do |all, file|
|
84
|
+
all.concat inspector.determine_files(file)
|
80
85
|
end
|
81
|
-
unless
|
82
|
-
|
86
|
+
unless files.empty?
|
87
|
+
system("clear;") if @options[:clear]
|
88
|
+
|
89
|
+
if files.delete('cucumber')
|
90
|
+
puts '--- cucumber current tagged features ---'
|
91
|
+
run_cucumber_command
|
92
|
+
end
|
93
|
+
|
94
|
+
# specs files
|
95
|
+
puts files.map { |f| f.to_s.gsub(/#{dir}/, '') }.join("\n")
|
83
96
|
|
84
97
|
previous_run_failed = last_run_failed?
|
85
|
-
run_spec_command(
|
98
|
+
run_spec_command(files)
|
86
99
|
|
87
100
|
if options[:retry_failed] and previous_run_failed and not last_run_failed?
|
88
101
|
run_all_specs
|
@@ -99,15 +112,33 @@ module RSpactor
|
|
99
112
|
opts = "--color"
|
100
113
|
end
|
101
114
|
|
102
|
-
opts <<
|
115
|
+
opts << spec_formatter_opts
|
103
116
|
# only add the "progress" formatter unless no other (besides growl) is specified
|
104
117
|
opts << ' -f progress' unless opts.scan(/\s(?:-f|--format)\b/).length > 1
|
105
118
|
|
106
119
|
opts
|
107
120
|
end
|
108
121
|
|
109
|
-
def
|
110
|
-
|
122
|
+
def cucumber_opts
|
123
|
+
if File.exist?('features/support/cucumber.opts')
|
124
|
+
opts = File.read('features/support/cucumber.opts').gsub("\n", ' ')
|
125
|
+
else
|
126
|
+
opts = "--format progress --drb "
|
127
|
+
end
|
128
|
+
|
129
|
+
opts << " --tags current"
|
130
|
+
opts << cucumber_formatter_opts
|
131
|
+
opts << " --require features" # because cucumber_formatter_opts overwrite default features require
|
132
|
+
opts << " features"
|
133
|
+
opts
|
134
|
+
end
|
135
|
+
|
136
|
+
def spec_formatter_opts
|
137
|
+
" --require #{File.dirname(__FILE__)}/../rspec_growler.rb --format RSpecGrowler:STDOUT"
|
138
|
+
end
|
139
|
+
|
140
|
+
def cucumber_formatter_opts
|
141
|
+
" --require #{File.dirname(__FILE__)}/../cucumber_growler.rb"
|
111
142
|
end
|
112
143
|
|
113
144
|
def spec_runner
|
@@ -118,6 +149,14 @@ module RSpactor
|
|
118
149
|
end
|
119
150
|
end
|
120
151
|
|
152
|
+
def cucumber_runner
|
153
|
+
if File.exist?("script/cucumber")
|
154
|
+
"script/cucumber"
|
155
|
+
else
|
156
|
+
"cucumber"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
121
160
|
def ruby_opts
|
122
161
|
other = ENV['RUBYOPT'] ? " #{ENV['RUBYOPT']}" : ''
|
123
162
|
other << ' -rcoral' if options[:coral]
|
data/lib/rspec_growler.rb
CHANGED
@@ -13,14 +13,12 @@ class RSpecGrowler < Spec::Runner::Formatter::BaseFormatter
|
|
13
13
|
'success'
|
14
14
|
end
|
15
15
|
|
16
|
-
image_path = File.dirname(__FILE__) + "/../images/#{icon}.png"
|
16
|
+
# image_path = File.dirname(__FILE__) + "/../images/#{icon}.png"
|
17
17
|
message = "#{total} examples, #{failures} failures"
|
18
|
-
|
19
18
|
if pending > 0
|
20
19
|
message << " (#{pending} pending)"
|
21
20
|
end
|
22
21
|
|
23
|
-
notify "
|
22
|
+
notify "Spec Results", message, icon
|
24
23
|
end
|
25
|
-
end
|
26
|
-
|
24
|
+
end
|
data/spec/inspector_spec.rb
CHANGED
@@ -53,7 +53,7 @@ describe RSpactor::Inspector do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should consider all controllers, helpers and views when routes.rb changes" do
|
56
|
-
translate('config/routes.rb').should == ['/project/spec/controllers', '/project/spec/helpers', '/project/spec/views']
|
56
|
+
translate('config/routes.rb').should == ['/project/spec/controllers', '/project/spec/helpers', '/project/spec/views', '/project/spec/routing']
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should consider all models when config/database.yml changes" do
|
@@ -64,6 +64,10 @@ describe RSpactor::Inspector do
|
|
64
64
|
translate('db/schema.rb').should == ['/project/spec/models']
|
65
65
|
end
|
66
66
|
|
67
|
+
it "should consider all models when spec/factories.rb changes" do
|
68
|
+
translate('spec/factories.rb').should == ['/project/spec/models']
|
69
|
+
end
|
70
|
+
|
67
71
|
it "should consider related model when its observer changes" do
|
68
72
|
translate('app/models/user_observer.rb').should == ['/project/spec/models/user_observer_spec.rb', '/project/spec/models/user_spec.rb']
|
69
73
|
end
|
@@ -81,11 +85,18 @@ describe RSpactor::Inspector do
|
|
81
85
|
translate('config/environments/test.rb').should == ['/project/spec']
|
82
86
|
translate('config/boot.rb').should == ['/project/spec']
|
83
87
|
end
|
88
|
+
|
89
|
+
it "should consider cucumber when a features file change" do
|
90
|
+
translate('features/login.feature').should == ['cucumber']
|
91
|
+
translate('features/steps/webrat_steps.rb').should == ['cucumber']
|
92
|
+
translate('features/support/env.rb').should == ['cucumber']
|
93
|
+
end
|
94
|
+
|
84
95
|
end
|
85
96
|
|
86
|
-
describe "#
|
97
|
+
describe "#determine_files" do
|
87
98
|
def determine(file)
|
88
|
-
@inspector.
|
99
|
+
@inspector.determine_files(file)
|
89
100
|
end
|
90
101
|
|
91
102
|
it "should filter out files that don't exist on the filesystem" do
|
data/spec/runner_spec.rb
CHANGED
@@ -190,7 +190,7 @@ describe RSpactor::Runner do
|
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should include growl formatter" do
|
193
|
-
run('foo').should include('
|
193
|
+
run('foo').should include(' --format RSpecGrowler:STDOUT')
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should include 'progress' formatter" do
|
@@ -198,8 +198,8 @@ describe RSpactor::Runner do
|
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should not include 'progress' formatter if there already are 2 or more formatters" do
|
201
|
-
@runner.should_receive(:
|
202
|
-
run('foo').should_not include('
|
201
|
+
@runner.should_receive(:spec_formatter_opts).and_return('-f foo --format bar')
|
202
|
+
run('foo').should_not include('--format progress')
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should save status of last run" do
|
@@ -213,14 +213,14 @@ describe RSpactor::Runner do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
describe "#
|
216
|
+
describe "#changed_files" do
|
217
217
|
before(:each) do
|
218
218
|
@runner = described_class.new('.')
|
219
219
|
@runner.stub!(:inspector).and_return(mock("Inspector"))
|
220
220
|
end
|
221
221
|
|
222
222
|
def set_inspector_expectation(file, ret)
|
223
|
-
@runner.inspector.should_receive(:
|
223
|
+
@runner.inspector.should_receive(:determine_files).with(file).and_return(ret)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should find and run spec files" do
|
@@ -232,20 +232,21 @@ describe RSpactor::Runner do
|
|
232
232
|
@runner.should_receive(:run_spec_command).with(expected)
|
233
233
|
|
234
234
|
capture_stdout do
|
235
|
-
@runner.
|
235
|
+
@runner.stub!(:dir)
|
236
|
+
@runner.send(:changed_files, %w(moo.rb views/baz.haml config/bar.yml))
|
236
237
|
$stdout.string.split("\n").should == expected
|
237
238
|
end
|
238
239
|
end
|
239
240
|
|
240
241
|
it "should run the full suite after a run succeded when the previous one failed" do
|
241
|
-
@runner.inspector.stub!(:
|
242
|
+
@runner.inspector.stub!(:determine_files).and_return(['spec/foo_spec.rb'], ['spec/bar_spec.rb'])
|
242
243
|
@runner.stub!(:options).and_return({ :retry_failed => true })
|
243
244
|
|
244
245
|
capture_stdout do
|
245
246
|
@runner.stub!(:run_spec_command)
|
246
247
|
@runner.should_receive(:last_run_failed?).and_return(true, false)
|
247
248
|
@runner.should_receive(:run_all_specs)
|
248
|
-
@runner.send(:
|
249
|
+
@runner.send(:changed_files, %w(moo.rb))
|
249
250
|
end
|
250
251
|
end
|
251
252
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guillaumegentil-rspactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Mislav Marohni\xC4\x87"
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-07-
|
15
|
+
date: 2009-07-21 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies: []
|
18
18
|
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- Rakefile
|
30
30
|
- bin/rspactor
|
31
31
|
- bin/rspactor-system
|
32
|
+
- lib/cucumber_growler.rb
|
32
33
|
- lib/rspactor
|
33
34
|
- lib/rspactor/growl.rb
|
34
35
|
- lib/rspactor/inspector.rb
|