rspactor 0.6.4 → 0.7.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,195 +1,55 @@
1
- require 'rspactor'
1
+ require 'growl'
2
2
 
3
3
  module RSpactor
4
4
  class Runner
5
- def self.start(options = {})
6
- run_in = options.delete(:run_in) || Dir.pwd
7
- new(run_in, options).start
8
- end
9
-
10
- attr_reader :dir, :options, :inspector, :interactor, :spork
11
-
12
- def initialize(dir, options = {})
13
- @dir = dir
14
- @options = options
15
- @spork = Spork.new(self) if options[:spork]
16
- read_git_head
17
- end
18
-
19
- def start
20
- load_dotfile
21
- puts "** RSpactor, now watching at '#{dir}'"
22
- spork.start if spork?
23
- start_interactor
24
- start_listener
25
- end
26
-
27
- def start_interactor
28
- @interactor = Interactor.new(self)
29
- message = "** Hit <enter> to skip initial spec #{"& cucumber " if cucumber?}run"
30
- aborted = options[:skip] || @interactor.wait_for_enter_key(message, 2, false)
31
- @interactor.start_termination_handler
32
- unless aborted
33
- run_all_specs
34
- run_cucumber_command('~@wip,~@pending', false)
35
- end
36
- end
37
-
38
- def start_listener
39
- @inspector = Inspector.new(self)
40
-
41
- Listener.new(Inspector::EXTENSIONS) do |files|
42
- changed_files(files) unless git_head_changed?
43
- end.run(dir)
44
- end
45
-
46
- def load_dotfile
47
- dotfile = File.join(ENV['HOME'], '.rspactor')
48
- if File.exists?(dotfile)
49
- begin
50
- Kernel.load dotfile
51
- rescue => e
52
- $stderr.puts "Error while loading #{dotfile}: #{e}"
53
- end
54
- end
55
- end
5
+ attr_reader :pipe
56
6
 
57
- def run_all_specs
58
- run_spec_command(File.join(dir, 'spec'))
59
- end
60
-
61
- def run_spec_command(paths)
62
- paths = Array(paths)
63
- if paths.empty?
64
- @last_run_failed = nil
7
+ def start(options = {})
8
+ if options[:all]
9
+ command = rspec_command(["spec"])
10
+ message = "Running all specs"
65
11
  else
66
- cmd = [ruby_opts, spec_runner, paths, spec_opts].flatten.join(' ')
67
- @last_run_failed = run_command(cmd)
12
+ command = rspec_command(Inspector.spec_paths)
13
+ message = "Running: #{Inspector.spec_paths.join(' ') }"
68
14
  end
15
+ run_rspec(command, message)
69
16
  end
70
17
 
71
- def run_cucumber_command(tags = '@wip:2', clear = @options[:clear])
72
- return unless cucumber?
73
-
74
- system("clear;") if clear
75
- puts "** Running all #{tags} tagged features..."
76
- cmd = [ruby_opts, cucumber_runner, cucumber_opts(tags)].flatten.join(' ')
77
- @last_run_failed = run_command(cmd)
78
- end
79
-
80
- def last_run_failed?
81
- @last_run_failed == false
82
- end
83
-
84
- def cucumber?
85
- @cucumber ||= File.exist?(File.join(dir, 'features'))
86
- end
87
-
88
- def spork?
89
- spork != nil
90
- end
91
-
92
- protected
93
-
94
- def run_command(cmd)
95
- system(cmd)
96
- $?.success?
18
+ def stop
19
+ Process.kill("ABRT", pipe.pid)
20
+ @pipe = nil
97
21
  end
98
22
 
99
- def changed_files(files)
100
- files = files.inject([]) do |all, file|
101
- all.concat inspector.determine_files(file)
102
- end
103
- unless files.empty?
104
-
105
- # cucumber features
106
- if files.delete('cucumber')
107
- run_cucumber_command
108
- end
109
-
110
- # specs files
111
- unless files.empty?
112
- system("clear;") if @options[:clear]
113
- files.uniq!
114
- puts files.map { |f| f.to_s.gsub(/#{dir}/, '') }.join("\n")
115
-
116
- previous_run_failed = last_run_failed?
117
- run_spec_command(files)
118
-
119
- if options[:retry_failed] and previous_run_failed and not last_run_failed?
120
- run_all_specs
121
- end
122
- end
123
- end
23
+ def run?
24
+ pipe && pipe.pid != nil
124
25
  end
125
26
 
126
27
  private
127
28
 
128
- def spec_opts
129
- if File.exist?('spec/spec.opts')
130
- opts = File.read('spec/spec.opts').gsub("\n", ' ')
131
- else
132
- opts = "--color"
133
- end
134
- opts << " --drb" if spork
135
- opts << spec_formatter_opts
136
- # only add the "progress" formatter unless no other (besides growl) is specified
137
- opts << ' -f progress' unless opts.scan(/\s(?:-f|--format)\b/).length > 1
138
- opts
139
- end
140
-
141
- def cucumber_opts(tags)
142
- opts = "--profile rspactor"
143
- opts << " --drb" if spork
144
- opts << " --tags #{tags}"
145
- opts << cucumber_formatter_opts
146
- opts << " --require features" # because using require option overwrite default require
147
- opts << " features"
148
- opts
149
- end
150
-
151
- def spec_formatter_opts
152
- " --require #{File.dirname(__FILE__)}/../rspec_growler.rb --format RSpecGrowler:STDOUT"
153
- end
154
-
155
- def cucumber_formatter_opts
156
- " --require #{File.dirname(__FILE__)}/../cucumber_growler.rb"
157
- end
158
-
159
- def spec_runner
160
- if File.exist?("script/spec")
161
- "script/spec"
162
- else
163
- "spec"
164
- end
165
- end
166
-
167
- def cucumber_runner
168
- if File.exist?("script/cucumber")
169
- "script/cucumber"
170
- else
171
- "cucumber"
29
+ def run_rspec(command, message)
30
+ @pipe = IO.popen(command)
31
+ UI.info message, :reset => true, :clear => RSpactor.options[:clear]
32
+ while pipe && !pipe.eof?
33
+ if pipe && char = pipe.read(8)
34
+ print char
35
+ $stdout.flush if pipe
36
+ end
172
37
  end
38
+ @pipe = nil
173
39
  end
174
40
 
175
- def ruby_opts
176
- other = ENV['RUBYOPT'] ? " #{ENV['RUBYOPT']}" : ''
177
- other << ' -rcoral' if options[:coral]
178
- %(RUBYOPT='-Ilib:spec#{other}')
41
+ def rspec_command(paths)
42
+ cmd_parts = [paths.join(' ')]
43
+ cmd_parts.unshift "--require #{File.dirname(__FILE__)}/../growl/growl_formatter.rb --format GrowlFormatter" if Growl.installed?
44
+ cmd_parts.unshift "--color"
45
+ cmd_parts.unshift "rspec"
46
+ cmd_parts.unshift "bundle exec" if bundler?
47
+ cmd_parts.join(" ")
179
48
  end
180
49
 
181
- def git_head_changed?
182
- old_git_head = @git_head
183
- read_git_head
184
- @git_head and old_git_head and @git_head != old_git_head
50
+ def bundler?
51
+ File.exist?("./Gemfile")
185
52
  end
186
53
 
187
- def read_git_head
188
- git_head_file = File.join(dir, '.git', 'HEAD')
189
- @git_head = File.exists?(git_head_file) && File.read(git_head_file)
190
- end
191
54
  end
192
- end
193
-
194
- # backward compatibility
195
- Runner = RSpactor::Runner
55
+ end
@@ -0,0 +1,37 @@
1
+ module RSpactor
2
+ module UI
3
+ class << self
4
+
5
+ def info(message, options = {})
6
+ unless test?
7
+ reset_line if options[:reset]
8
+ clear if options[:clear]
9
+ puts reset_color(message)
10
+ end
11
+ end
12
+
13
+ def reset_line
14
+ print "\r\e "
15
+ end
16
+
17
+ private
18
+
19
+ def clear
20
+ system("clear;")
21
+ end
22
+
23
+ def test?
24
+ ENV["RSPACTOR_ENV"] == "test"
25
+ end
26
+
27
+ def reset_color(text)
28
+ color(text, "\e[0m")
29
+ end
30
+
31
+ def color(text, color_code)
32
+ "#{color_code}#{text}\e[0m"
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module RSpactor
2
+ VERSION = "0.7.0.beta.1"
3
+ end
data/lib/rspactor.rb CHANGED
@@ -1,8 +1,27 @@
1
1
  module RSpactor
2
- autoload :Interactor, 'rspactor/interactor'
3
- autoload :Listener, 'rspactor/listener'
4
- autoload :Inspector, 'rspactor/inspector'
5
- autoload :Runner, 'rspactor/runner'
6
- autoload :Growl, 'rspactor/growl'
7
- autoload :Spork, 'rspactor/spork'
8
- end
2
+
3
+ autoload :UI, 'rspactor/ui'
4
+ autoload :Interactor, 'rspactor/interactor'
5
+ autoload :Listener, 'rspactor/listener'
6
+ autoload :Inspector, 'rspactor/inspector'
7
+ autoload :Runner, 'rspactor/runner'
8
+
9
+ class << self
10
+ attr_reader :options, :listener, :runner
11
+
12
+ def start(options = {})
13
+ @options = options
14
+ @listener = Listener.new
15
+ @runner = Runner.new
16
+ Interactor.init_signal_traps
17
+ listener.watch do |files|
18
+ Inspector.determine_spec_paths(files)
19
+ runner.start if Inspector.spec_paths?
20
+ end
21
+ UI.info "RSpactor is now watching at '#{Dir.pwd}'"
22
+ listener.start
23
+ end
24
+
25
+ end
26
+
27
+ end
metadata CHANGED
@@ -1,103 +1,136 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspactor
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 62196433
5
+ prerelease: true
5
6
  segments:
6
7
  - 0
7
- - 6
8
- - 4
9
- version: 0.6.4
8
+ - 7
9
+ - 0
10
+ - beta
11
+ - 1
12
+ version: 0.7.0.beta.1
10
13
  platform: ruby
11
14
  authors:
12
- - "Mislav Marohni\xC4\x87"
13
- - Andreas Wolff
14
- - Pelle Braendgaard
15
15
  - Thibaud Guillaume-Gentil
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-04 00:00:00 +02:00
21
- default_executable: rspactor
20
+ date: 2010-06-30 00:00:00 +02:00
21
+ default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 83
30
+ segments:
31
+ - 1
32
+ - 16
33
+ - 2
34
+ version: 1.16.2
35
+ name: trollop
36
+ prerelease: false
37
+ requirement: *id001
38
+ type: :runtime
39
+ - !ruby/object:Gem::Dependency
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 62196479
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ - beta
51
+ - 14
52
+ version: 2.0.0.beta.14
24
53
  name: rspec
25
54
  prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
55
+ requirement: *id002
56
+ type: :runtime
57
+ - !ruby/object:Gem::Dependency
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
59
+ none: false
27
60
  requirements:
28
61
  - - ">="
29
62
  - !ruby/object:Gem::Version
63
+ hash: 17
30
64
  segments:
31
65
  - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
35
- type: :development
36
- version_requirements: *id001
37
- description: RSpactor is a command line tool to automatically run your changed specs & cucumber features (much like autotest).
38
- email: thibaud@thibaud.me
66
+ - 0
67
+ - 3
68
+ version: 1.0.3
69
+ name: growl
70
+ prerelease: false
71
+ requirement: *id003
72
+ type: :runtime
73
+ description: RSpactor is a command line tool to automatically run your changed specs (much like autotest)
74
+ email:
75
+ - thibaud@thibaud.me
39
76
  executables:
40
77
  - rspactor
41
- extensions: []
78
+ extensions:
79
+ - ext/fsevent/extconf.rb
80
+ extra_rdoc_files: []
42
81
 
43
- extra_rdoc_files:
44
- - LICENSE
45
- - README.rdoc
46
82
  files:
47
- - .gitignore
48
- - .rspactor
49
- - LICENSE
50
- - README.rdoc
51
- - Rakefile
52
- - VERSION
53
83
  - bin/rspactor
54
84
  - images/failed.png
55
85
  - images/pending.png
56
86
  - images/success.png
57
- - lib/cucumber_growler.rb
58
- - lib/rspactor.rb
59
- - lib/rspactor/growl.rb
87
+ - lib/growl/growl_formatter.rb
60
88
  - lib/rspactor/inspector.rb
61
89
  - lib/rspactor/interactor.rb
62
90
  - lib/rspactor/listener.rb
63
91
  - lib/rspactor/runner.rb
64
- - lib/rspactor/spork.rb
65
- - lib/rspec_growler.rb
66
- - rspactor.gemspec
67
- - spec/inspector_spec.rb
68
- - spec/listener_spec.rb
69
- - spec/runner_spec.rb
92
+ - lib/rspactor/ui.rb
93
+ - lib/rspactor/version.rb
94
+ - lib/rspactor.rb
95
+ - ext/fsevent/extconf.rb
96
+ - ext/fsevent/fsevent_watch.c
97
+ - LICENSE
98
+ - README.rdoc
70
99
  has_rdoc: true
71
100
  homepage: http://github.com/thibaudgg/rspactor
72
101
  licenses: []
73
102
 
74
103
  post_install_message:
75
- rdoc_options:
76
- - --charset=UTF-8
104
+ rdoc_options: []
105
+
77
106
  require_paths:
78
107
  - lib
79
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
80
110
  requirements:
81
111
  - - ">="
82
112
  - !ruby/object:Gem::Version
113
+ hash: 3
83
114
  segments:
84
115
  - 0
85
116
  version: "0"
86
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
87
119
  requirements:
88
120
  - - ">="
89
121
  - !ruby/object:Gem::Version
122
+ hash: 21
90
123
  segments:
91
- - 0
92
- version: "0"
124
+ - 1
125
+ - 3
126
+ - 7
127
+ version: 1.3.7
93
128
  requirements: []
94
129
 
95
130
  rubyforge_project:
96
- rubygems_version: 1.3.6
131
+ rubygems_version: 1.3.7
97
132
  signing_key:
98
133
  specification_version: 3
99
- summary: RSpactor is a command line tool to automatically run your changed specs & cucumber features.
100
- test_files:
101
- - spec/inspector_spec.rb
102
- - spec/listener_spec.rb
103
- - spec/runner_spec.rb
134
+ summary: Simpler Autotest
135
+ test_files: []
136
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/.rspactor DELETED
File without changes
data/Rakefile DELETED
@@ -1,50 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rspactor"
8
- gem.summary = "RSpactor is a command line tool to automatically run your changed specs & cucumber features."
9
- gem.description = "RSpactor is a command line tool to automatically run your changed specs & cucumber features (much like autotest)."
10
- gem.email = "thibaud@thibaud.me"
11
- gem.homepage = "http://github.com/thibaudgg/rspactor"
12
- gem.authors = ["Mislav Marohnić", "Andreas Wolff", "Pelle Braendgaard", "Thibaud Guillaume-Gentil"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
32
-
33
- desc "starts RSpactor"
34
- task :rspactor do
35
- system "ruby -Ilib bin/rspactor"
36
- end
37
-
38
- task :spec => :check_dependencies
39
-
40
- task :default => :rspactor
41
-
42
- require 'rake/rdoctask'
43
- Rake::RDocTask.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
-
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "rspactor #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
50
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.4
@@ -1,61 +0,0 @@
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, profiles = [])
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, profiles = [])
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
@@ -1,14 +0,0 @@
1
- module RSpactor
2
- module Growl
3
- extend self
4
-
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
- end
8
-
9
- # failed | pending | success
10
- def image_path(icon)
11
- File.expand_path File.dirname(__FILE__) + "/../../images/#{icon}.png"
12
- end
13
- end
14
- end