prefetch-rspec 0.1.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.0.0"
10
+ gem "yard", "~> 0.6.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.1"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.0.1)
13
+ rspec-core (~> 2.0.1)
14
+ rspec-expectations (~> 2.0.1)
15
+ rspec-mocks (~> 2.0.1)
16
+ rspec-core (2.0.1)
17
+ rspec-expectations (2.0.1)
18
+ diff-lcs (>= 1.1.2)
19
+ rspec-mocks (2.0.1)
20
+ rspec-core (~> 2.0.1)
21
+ rspec-expectations (~> 2.0.1)
22
+ yard (0.6.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ jeweler (~> 1.5.1)
30
+ rcov
31
+ rspec (~> 2.0.0)
32
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Yuichi Tateno
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = prefetch-rspec
2
+
3
+ Prefetch RSpec is prefetch initialize phase before run rspec.
4
+
5
+ = Install
6
+
7
+ $ gem install prefetch-rspec
8
+
9
+ = Using with Rails3
10
+
11
+ Change config/environments/tests.rb cache_classess line.
12
+
13
+ config.cache_classes = ENV.has_key?('PRSPEC') ? false : true
14
+
15
+ Execute command Rails.root
16
+
17
+ $ prspecd --rails
18
+
19
+ or copy examples/rails.prspecd to Rails.root/.rspecd
20
+
21
+ $ prspecd
22
+
23
+ run prspec
24
+
25
+ $ prspec [rspec arguments]
26
+ example..
27
+ $ prspec spec/models/example.rb -l 5
28
+
29
+ = License
30
+
31
+ MIT License
32
+
33
+ Copyright (c) 2010 Yuichi Tateno.
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ "Software"), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
50
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
51
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
52
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53
+
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "prefetch-rspec"
16
+ gem.homepage = "http://github.com/hotchpotch/prefetch-rspec"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Prefetch initialize phase before run rspec}
19
+ gem.description = %Q{ }
20
+ gem.email = "hotchpotch@gmail.com"
21
+ gem.authors = ["Yuichi Tateno"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/prspec ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'prefetch_rspec'
4
+ PrefetchRspec::Runner.run(ARGV)
5
+
data/bin/prspecd ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'prefetch_rspec'
4
+ PrefetchRspec::Server.listen(ARGV, File.expand_path($0))
@@ -0,0 +1,31 @@
1
+
2
+ prefetch {
3
+ require 'pathname'
4
+ ENV["PRSPEC"] = 'true'
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+ envfile = Pathname.new(File.expand_path(Dir.pwd + "/config/environments/#{ENV["RAILS_ENV"]}.rb"))
7
+ unless envfile.read.match(/ENV.+PRSPEC/)
8
+ color("!!! set cache_classes (for reload classes) !!!", 31)
9
+ warn "Please replace #{envfile} settings."
10
+ mes = " config.cache_classes = ENV.has_key?('PRSPEC') ? false : true "
11
+ warn '-' * mes.length
12
+ warn mes
13
+ warn '-' * mes.length
14
+ end
15
+ require File.expand_path(Dir.pwd + "/config/environment")
16
+ Rails.application.config.cache_classes = false
17
+ require 'rspec/rails'
18
+ }
19
+
20
+ before_run {
21
+ ActionDispatch::Callbacks.new(Proc.new {}, false).call({})
22
+ ActiveSupport::DescendantsTracker.clear
23
+ ActiveSupport::Dependencies.clear
24
+ Rails.application.config.cache_classes = true
25
+ ActiveSupport::Dependencies.mechanism = :require
26
+ require 'spec/spec_helper'
27
+ }
28
+
29
+ # after_run {
30
+ # }
31
+
@@ -0,0 +1,287 @@
1
+
2
+ require 'drb/drb'
3
+
4
+ module PrefetchRspec
5
+ DEFAULT_PORT = 8989
6
+ class Base
7
+ attr_reader :options
8
+
9
+ def initialize(args)
10
+ optparse(args.to_a)
11
+ end
12
+
13
+ def cwarn(str, col = 37)
14
+ warn color(str, col)
15
+ end
16
+
17
+ def color(str, col = 37)
18
+ if STDOUT.tty?
19
+ "\033[1;#{col}m%s\033[0m" % str
20
+ else
21
+ str
22
+ end
23
+ end
24
+
25
+ def drb_uri
26
+ drb_uri = "druby://127.0.0.1:#{options[:port] || DEFAULT_PORT }"
27
+ end
28
+
29
+ private
30
+ def optparse(args)
31
+ @options = {:args => []}
32
+ args.each do |arg|
33
+ case arg
34
+ when /^--port=(\d+)$/
35
+ @options[:port] = $1.to_i
36
+ when /^--rails$/
37
+ @options[:rails] = true
38
+ when /^--bundler$/
39
+ @options[:bundler] = true
40
+ when /^--drb$/
41
+ # nothing..
42
+ else
43
+ @options[:args] << arg
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ class Runner < Base
50
+ def self.run(args)
51
+ self.new(args).run ? exit(0) : exit(1)
52
+ end
53
+
54
+ def run(err = STDERR, out = STDOUT)
55
+ @drb_service ||= DRb.start_service(nil)
56
+
57
+ result = nil
58
+ begin
59
+ result = DRbObject.new_with_uri(drb_uri).run(options[:args], err, out)
60
+ @drb_service.stop_service
61
+ rescue DRb::DRbConnError => e
62
+ @drb_service.stop_service
63
+ err.puts "Can't connect to prspecd. Run in normal rspec."
64
+ require_libraries
65
+ RSpec::Core::Runner.disable_autorun!
66
+ result = RSpec::Core::Runner.run(options[:args], err, out)
67
+ end
68
+ result
69
+ end
70
+
71
+ def require_libraries
72
+ begin
73
+ require 'bundler' if options[:bundler]
74
+ require 'rspec/core'
75
+ rescue LoadError
76
+ require 'rubygems'
77
+ require 'bundler' if options[:bundler]
78
+ require 'rspec/core'
79
+ end
80
+ end
81
+ end
82
+
83
+ class Server < Base
84
+ require 'stringio'
85
+
86
+ def self.listen(args, script)
87
+ begin
88
+ server = self.new(args)
89
+ register_handlers(server, args, script)
90
+ server.listen
91
+ rescue SystemExit
92
+ # silent
93
+ rescue Exception => e
94
+ warn "ServerError: #{e}"
95
+ warn e.backtrace.map {|l| " " + l}.join("\n")
96
+ end
97
+ end
98
+
99
+ @@force_exit = false
100
+ def self.register_handlers(server, args, script)
101
+ [:TERM, :KILL].each do |signal|
102
+ Signal.trap(signal) {
103
+ force_exit!
104
+ }
105
+ end
106
+
107
+ sigint_first_called = false
108
+ Signal.trap(:INT) {
109
+ if sigint_first_called
110
+ force_exit!
111
+ else
112
+ sigint_first_called = true
113
+ warn " reloding... [Ctrl-C quick press shoudown]"
114
+ Thread.new {
115
+ sleep 1.5
116
+ exit
117
+ }
118
+ end
119
+ }
120
+
121
+ at_exit {
122
+ if @@force_exit
123
+ server.cwarn("shutdown: ...")
124
+ else
125
+ server.cwarn("")
126
+ server.cwarn("self restart: " + [script, args.to_a].flatten.join(' '))
127
+ exec(script, *args.to_a)
128
+ end
129
+ }
130
+ end
131
+
132
+ def self.force_exit!
133
+ @@force_exit = true
134
+ exit 1
135
+ end
136
+
137
+ def run(options, err, out)
138
+ while !@prefetched
139
+ sleep 0.1
140
+ end
141
+ if @prefetch_out
142
+ @prefetch_out.rewind
143
+ out.print @prefetch_out.read
144
+ end
145
+ if @prefetch_err
146
+ @prefetch_err.rewind
147
+ err.print @prefetch_err.read
148
+ end
149
+
150
+ call_before_run(err, out)
151
+ RSpec::Core::Runner.disable_autorun!
152
+ result = replace_io_execute(err, out, nil) { RSpec::Core::Runner.run(options, err, out) }
153
+ call_after_run(err, out)
154
+ Thread.new {
155
+ sleep 0.01
156
+ stop_service!
157
+ }
158
+ result
159
+ end
160
+
161
+ def stop_service!
162
+ if @drb_service
163
+ @drb_service.stop_service
164
+ else
165
+ false
166
+ end
167
+ end
168
+
169
+ def prefetch(&block)
170
+ @prefetch = block
171
+ end
172
+
173
+ def before_run(&block)
174
+ @before_run = block
175
+ end
176
+
177
+ def after_run(&block)
178
+ @after_run = block
179
+ end
180
+
181
+ def timewatch(name)
182
+ now = Time.now.to_f
183
+ cwarn("#{name}: start", 35)
184
+ yield
185
+ cwarn("#{name}: finished (%.3f sec)" % (Time.now.to_f - now), 35)
186
+ end
187
+
188
+ def call_prefetch
189
+ if @prefetch
190
+ timewatch('prefetch') do
191
+ @prefetch_err = StringIO.new
192
+ @prefetch_out = StringIO.new
193
+ replace_io_execute(@prefetch_err, @prefetch_out, 'prefetch') {
194
+ @prefetch.call
195
+ }
196
+ @prefetch_err.rewind
197
+ end
198
+ end
199
+ @prefetched = true
200
+ end
201
+
202
+ def replace_io_execute(err, out, catch_fail)
203
+ orig_out = $stdout
204
+ orig_err = $stderr
205
+ result = nil
206
+ begin
207
+ $stdout = out
208
+ $stderr = err
209
+ result = yield
210
+ rescue Exception => exception
211
+ if catch_fail
212
+ err.puts color("hook #{catch_fail} raise error: #{exception}", 31)
213
+ err.puts color(exception.backtrace.map {|l| " " + l}.join("\n"), 37)
214
+ end
215
+ ensure
216
+ $stdout = orig_out
217
+ $stderr = orig_err
218
+ end
219
+ result
220
+ end
221
+
222
+ def call_before_run(err, out)
223
+ if @before_run
224
+ timewatch('before_run') do
225
+ replace_io_execute(err, out, 'before_run') { @before_run.call }
226
+ end
227
+ end
228
+ end
229
+
230
+ def call_after_run(err, out)
231
+ if @after_run
232
+ timewatch('after_run') do
233
+ replace_io_execute(err, out, 'after_run') { @after_run.call }
234
+ end
235
+ end
236
+ end
237
+
238
+ def load_config_prspecd
239
+ dot_prspecd = Pathname.new(Dir.pwd).join('.prspecd')
240
+ if dot_prspecd.exist?
241
+ self.instance_eval dot_prspecd.read, dot_prspecd.to_s
242
+ else
243
+ end
244
+ end
245
+
246
+ def load_config(path)
247
+ if path.exist?
248
+ self.instance_eval path.read, path.to_s
249
+ cwarn("config loaded: #{path}", 37)
250
+ else
251
+ cwarn("config not found:#{path}", 31)
252
+ banner
253
+ self.class.force_exit!
254
+ end
255
+ end
256
+
257
+ def banner
258
+ cwarn "usage: #{File.basename($0)} [--rails] [config_file(default .prspecd)]"
259
+ end
260
+
261
+ def detect_load_config
262
+ require 'pathname'
263
+ if options[:rails]
264
+ load_config Pathname.new(File.expand_path(__FILE__)).parent.parent.join('examples/rails.prspecd')
265
+ elsif options[:args].first
266
+ load_config Pathname.new(Dir.pwd).join(options[:args].first)
267
+ else
268
+ load_config(Pathname.new(Dir.pwd).join('.prspecd'))
269
+ end
270
+ end
271
+
272
+ def listen
273
+ detect_load_config
274
+
275
+ begin
276
+ @drb_service = DRb.start_service(drb_uri, self)
277
+ rescue DRb::DRbConnError => e
278
+ cwarn("client connection abort", 31)
279
+ @drb_service.stop_service
280
+ exit 1
281
+ end
282
+ call_prefetch
283
+ @drb_service.thread.join
284
+ end
285
+ end
286
+ end
287
+
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{prefetch-rspec}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Yuichi Tateno"]
12
+ s.date = %q{2010-12-11}
13
+ s.description = %q{ }
14
+ s.email = %q{hotchpotch@gmail.com}
15
+ s.executables = ["prspecd", "prspec"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/prspec",
30
+ "bin/prspecd",
31
+ "examples/rails.prspecd",
32
+ "lib/prefetch_rspec.rb",
33
+ "prefetch-rspec.gemspec",
34
+ "spec/prefetch_rspec_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "specs.watchr"
37
+ ]
38
+ s.homepage = %q{http://github.com/hotchpotch/prefetch-rspec}
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Prefetch initialize phase before run rspec}
43
+ s.test_files = [
44
+ "spec/prefetch_rspec_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
54
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
57
+ s.add_development_dependency(%q<rcov>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
60
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rspec>, ["~> 2.0.0"])
67
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,220 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'stringio'
3
+
4
+ describe PrefetchRspec do
5
+ describe PrefetchRspec::Base do
6
+ describe "optparse" do
7
+ it "default" do
8
+ options = PrefetchRspec::Base.new([]).options
9
+ options[:args].should be_empty
10
+ options[:rails].should be_nil
11
+ options[:port].should be_nil
12
+ options[:bundler].should be_nil
13
+ end
14
+
15
+ it "port assign" do
16
+ PrefetchRspec::Base.new(['--port=10001', 'a']).options.should == {:port => 10001, :args => ['a']}
17
+ end
18
+
19
+ it "deb_uri" do
20
+ base = PrefetchRspec::Base.new([])
21
+ base.drb_uri.should == "druby://127.0.0.1:#{PrefetchRspec::DEFAULT_PORT}"
22
+ base = PrefetchRspec::Base.new(['--port=10001', 'a'])
23
+ base.drb_uri.should == "druby://127.0.0.1:10001"
24
+ end
25
+
26
+ it "remove --drb options" do
27
+ base = PrefetchRspec::Base.new(['--drb', 'a'])
28
+ base.options[:args].should == ['a']
29
+ end
30
+
31
+ it "bundler option" do
32
+ base = PrefetchRspec::Base.new(['--bundler', 'a'])
33
+ base.options[:bundler].should be_true
34
+ end
35
+
36
+ it "rails option" do
37
+ base = PrefetchRspec::Base.new(['--rails', 'a'])
38
+ base.options[:rails].should be_true
39
+ end
40
+ end
41
+ end
42
+
43
+ describe PrefetchRspec do
44
+ before(:each) do
45
+ RSpec::Mocks::setup(RSpec::Core::Runner)
46
+ RSpec::Core::Runner.stub!(:run).and_return {|args, err, out|
47
+ if args.first.kind_of? Proc
48
+ args.first.call
49
+ else
50
+ args.first
51
+ end
52
+ }
53
+ end
54
+
55
+ after(:each) do
56
+ sleep 0.001 # wait thread
57
+ @server.stop_service! if @server
58
+ end
59
+
60
+ def server(args = [])
61
+ unless @server
62
+ @server = PrefetchRspec::Server.new(args)
63
+ @server.stub(:cwarn)
64
+ @server.stub(:detect_load_config)
65
+ end
66
+ @server
67
+ end
68
+
69
+ def listen
70
+ Thread.new { server.listen }
71
+ sleep 0.001
72
+ end
73
+
74
+ def runner(*args, &block)
75
+ PrefetchRspec::Runner.new([args, block].flatten)
76
+ end
77
+
78
+ def run(args = [], &block)
79
+ runner(args, &block).run
80
+ end
81
+
82
+ def err_io
83
+ @err_io ||= StringIO.new
84
+ end
85
+
86
+ def out_io
87
+ @out_io ||= StringIO.new
88
+ end
89
+
90
+ describe PrefetchRspec::Runner do
91
+ it "running over drb" do
92
+ listen
93
+ r = runner(false)
94
+ r.run(err_io).should be_false
95
+ err_io.rewind
96
+ err_io.read.should_not match(/Can't connect to prspecd/)
97
+ end
98
+
99
+ it "running over drb 2nd" do
100
+ listen
101
+ r = runner(false)
102
+ r.run(err_io).should be_false
103
+ err_io.rewind
104
+ err_io.read.should_not match(/Can't connect to prspecd/)
105
+ end
106
+
107
+ it "not running over drb" do
108
+ r = runner(false)
109
+ r.run(err_io).should be_false
110
+ err_io.rewind
111
+ err_io.read.should match(/Can't connect to prspecd/)
112
+ end
113
+
114
+ it "not running over drb 2nd" do
115
+ r = runner(false)
116
+ r.run(err_io).should be_false
117
+ err_io.rewind
118
+ err_io.read.should match(/Can't connect to prspecd/)
119
+ end
120
+ end
121
+
122
+ describe PrefetchRspec::Server do
123
+ it "listen" do
124
+ listen
125
+ server.stop_service!.should be_true
126
+ end
127
+
128
+ it "call prefetch only" do
129
+ hooks = double('hooks')
130
+ hooks.should_receive('prefetch')
131
+ hooks.should_not_receive('before_run')
132
+ hooks.should_not_receive('after_run')
133
+ server.prefetch { hooks.prefetch }
134
+ server.before_run { hooks.before_run }
135
+ @after_run_run = true
136
+ server.after_run {
137
+ hooks.after_run if @after_run
138
+ }
139
+ listen
140
+ end
141
+
142
+ it "call prefetch/before_run" do
143
+ hooks = double('hooks')
144
+ hooks.should_receive('prefetch')
145
+ hooks.should_receive('before_run')
146
+ hooks.should_not_receive('after_run')
147
+ server.prefetch { hooks.prefetch }
148
+ server.before_run { hooks.before_run }
149
+ @after_run_run = true
150
+ server.after_run {
151
+ hooks.after_run if @after_run
152
+ }
153
+ listen
154
+ r = runner { @after_run_run = false ; true}
155
+ r.run(err_io).should be_true
156
+ err_io.rewind
157
+ err_io.read.should_not match(/Can't connect to prspecd/)
158
+ end
159
+
160
+ it "wait prefetch" do
161
+ hooks = double('hooks')
162
+ hooks.should_receive('prefetch')
163
+ hooks.should_receive('before_run')
164
+ hooks.should_not_receive('after_run')
165
+ server.prefetch { sleep 0.2 ;hooks.prefetch }
166
+ server.before_run { hooks.before_run }
167
+ @after_run_run = true
168
+ server.after_run {
169
+ hooks.after_run if @after_run
170
+ }
171
+ listen
172
+ r = runner { @after_run_run = false ; true}
173
+ r.run(err_io).should be_true
174
+ err_io.rewind
175
+ err_io.read.should_not match(/Can't connect to prspecd/)
176
+ end
177
+
178
+ it "get hooks output" do
179
+ server.prefetch { print '1'; $stderr.print '4' }
180
+ server.before_run { print '2'; $stderr.print '5' }
181
+ server.after_run { print '3'; $stderr.print '6' }
182
+ listen
183
+ r = runner { true }
184
+ r.run(err_io, out_io).should be_true
185
+ out_io.rewind
186
+ out_io.read.should match(/123/)
187
+ err_io.rewind
188
+ err_io.read.should match(/456/)
189
+ end
190
+
191
+ it "prefetch raise error catch" do
192
+ server.prefetch { raise Exception.new('MyErrorOOO') }
193
+ listen
194
+ r = runner { true }
195
+ r.run(err_io, out_io).should be_true
196
+ err_io.rewind
197
+ err_io.read.should match(/MyErrorOOO/)
198
+ end
199
+
200
+ it "before_run raise error catch" do
201
+ server.before_run { raise Exception.new('MyErrorOOO') }
202
+ listen
203
+ r = runner { true }
204
+ r.run(err_io, out_io).should be_true
205
+ err_io.rewind
206
+ err_io.read.should match(/MyErrorOOO/)
207
+ end
208
+
209
+ it "after_run raise error catch" do
210
+ server.after_run { raise Exception.new('MyErrorOOO') }
211
+ listen
212
+ r = runner { true }
213
+ r.run(err_io, out_io).should be_true
214
+ err_io.rewind
215
+ err_io.read.should match(/MyErrorOOO/)
216
+ end
217
+ end
218
+ end
219
+ end
220
+
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'prefetch_rspec'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.filter_run :focus => true
12
+ config.run_all_when_everything_filtered = true
13
+
14
+ config.mock_with :rspec
15
+ end
data/specs.watchr ADDED
@@ -0,0 +1,2 @@
1
+
2
+ watch('(lib/*.rb)|(spec/*.rb)') {|md| system("rspec spec/prefetch_rspec_spec.rb") }
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prefetch-rspec
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Yuichi Tateno
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-11 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 0
48
+ - 6
49
+ - 0
50
+ version: 0.6.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 0
66
+ version: 1.0.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 1
78
+ segments:
79
+ - 1
80
+ - 5
81
+ - 1
82
+ version: 1.5.1
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rcov
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ description: " "
100
+ email: hotchpotch@gmail.com
101
+ executables:
102
+ - prspecd
103
+ - prspec
104
+ extensions: []
105
+
106
+ extra_rdoc_files:
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ files:
110
+ - .document
111
+ - .rspec
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
115
+ - README.rdoc
116
+ - Rakefile
117
+ - VERSION
118
+ - bin/prspec
119
+ - bin/prspecd
120
+ - examples/rails.prspecd
121
+ - lib/prefetch_rspec.rb
122
+ - prefetch-rspec.gemspec
123
+ - spec/prefetch_rspec_spec.rb
124
+ - spec/spec_helper.rb
125
+ - specs.watchr
126
+ has_rdoc: true
127
+ homepage: http://github.com/hotchpotch/prefetch-rspec
128
+ licenses:
129
+ - MIT
130
+ post_install_message:
131
+ rdoc_options: []
132
+
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ requirements: []
154
+
155
+ rubyforge_project:
156
+ rubygems_version: 1.3.7
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Prefetch initialize phase before run rspec
160
+ test_files:
161
+ - spec/prefetch_rspec_spec.rb
162
+ - spec/spec_helper.rb