like_a_virgin 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/bin/lav +13 -0
- data/lib/like_a_virgin.rb +121 -0
- data/lib/like_a_virgin/file_map.rb +41 -0
- data/lib/like_a_virgin/monkey_patches.rb +7 -0
- data/lib/like_a_virgin/options.rb +18 -0
- data/lib/like_a_virgin/world.rb +37 -0
- data/spec/like_a_virgin_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +126 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 miyucy
|
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,17 @@
|
|
1
|
+
= like_a_virgin
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 miyucy. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "like_a_virgin"
|
8
|
+
gem.summary = %Q{Like a Virgin}
|
9
|
+
gem.description = %Q{Like a Virgin}
|
10
|
+
gem.email = "miyucy@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/miyucy/like_a_virgin"
|
12
|
+
gem.authors = ["miyucy"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_runtime_dependency "rb-inotify"
|
15
|
+
gem.add_runtime_dependency "parallel_tests"
|
16
|
+
gem.executables = "lav"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
task :default => :spec
|
39
|
+
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "like_a_virgin #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/lav
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "like_a_virgin"
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] ||= "test"
|
5
|
+
begin
|
6
|
+
require File.expand_path(File.join("config","environment"), Dir.pwd)
|
7
|
+
rescue LoadError
|
8
|
+
$stderr.puts "could not load config/environment.rb. Are we in Rails.root?"
|
9
|
+
end
|
10
|
+
require "spec"
|
11
|
+
require "spec/rails"
|
12
|
+
|
13
|
+
LikeAVirgin.start
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "rb-inotify"
|
2
|
+
require "like_a_virgin/file_map"
|
3
|
+
require "like_a_virgin/options"
|
4
|
+
require "like_a_virgin/world"
|
5
|
+
require "like_a_virgin/monkey_patches"
|
6
|
+
|
7
|
+
module LikeAVirgin
|
8
|
+
def self.start
|
9
|
+
setup_sigtrap
|
10
|
+
@options = Options.new
|
11
|
+
@changing_files = []
|
12
|
+
@notifier = setup_notifier find_specs
|
13
|
+
World.init(@options)
|
14
|
+
|
15
|
+
@exit = false
|
16
|
+
while !@exit
|
17
|
+
@notifier.process while @changing_files.empty?
|
18
|
+
changed_files = @changing_files.flatten.uniq.sort.dup
|
19
|
+
break if changed_files.first.nil?
|
20
|
+
@changing_files.clear
|
21
|
+
World.emit changed_files
|
22
|
+
sleep 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.stop
|
27
|
+
@exit = true
|
28
|
+
@notifier.try :close
|
29
|
+
@changing_files << nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.setup_sigtrap
|
33
|
+
# restart
|
34
|
+
Signal.trap(:INT) do
|
35
|
+
LikeAVirgin.stop
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
# quit
|
40
|
+
Signal.trap(:TSTP) do
|
41
|
+
LikeAVirgin.stop
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.setup_notifier(fm)
|
47
|
+
notifier = INotify::Notifier.new
|
48
|
+
|
49
|
+
files = fm.keys
|
50
|
+
dirs = files.map{ |f| File.dirname f }.uniq
|
51
|
+
dirs.each do |dir|
|
52
|
+
notifier.watch(dir, :all_events) do |event|
|
53
|
+
next unless event.flags.include?(:modify) || event.flags.include?(:move_to)
|
54
|
+
next unless files.include? event.absolute_name
|
55
|
+
@changing_files << fm[event.absolute_name]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
notifier
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.find_specs
|
63
|
+
file_map = FileMap.new Rails.root, Dir[Rails.root + "**/*"]
|
64
|
+
|
65
|
+
file_map.matches(%r"spec/(models|controllers|routing|views|helpers|lib)/.*\.rb") do |fm, file|
|
66
|
+
fm[file] = file
|
67
|
+
end
|
68
|
+
|
69
|
+
file_map.matches(%r"spec/fixtures/.*\.yml") do |fm, file|
|
70
|
+
model = File.basename(file, ".yml")
|
71
|
+
fm[file] = "spec/models/#{model.singularize}_spec.rb"
|
72
|
+
fm[file] = file_map.matches(%r"spec/views/#{model}/.*_spec\.rb")
|
73
|
+
end
|
74
|
+
|
75
|
+
file_map.matches(%r"app/models/.*\.rb") do |fm, file|
|
76
|
+
model = File.basename(file, ".rb")
|
77
|
+
fm[file] = "spec/models/#{model}_spec.rb"
|
78
|
+
end
|
79
|
+
|
80
|
+
file_map.matches(%r"app/views/") do |fm, file|
|
81
|
+
fm[file] = "spec/views/#{file.sub("app/views/","")}_spec.rb"
|
82
|
+
end
|
83
|
+
|
84
|
+
file_map.matches(%r"app/controllers/.*\.rb") do |fm, file|
|
85
|
+
controller = File.basename(file, ".rb")
|
86
|
+
if controller == "application_controller"
|
87
|
+
fm[file] = file_map.matches(%r"spec/controllers/.*_spec\.rb")
|
88
|
+
else
|
89
|
+
fm[file] = "spec/controllers/#{controller}_spec.rb"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
file_map.matches(%r"app/helpers/.*_helper\.rb") do |fm, file|
|
94
|
+
helper = File.basename(file, ".rb")
|
95
|
+
if helper == "application_helper"
|
96
|
+
fm[file] = file_map.matches(%r"spec/(views|helpers)/.*_spec\.rb")
|
97
|
+
else
|
98
|
+
fm[file] = "spec/helpers/#{helper}_spec.rb"
|
99
|
+
fm[file] = file_map.matches(%r"spec/views/#{helper.sub("_helper","")}/.*_spec\.rb")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
file_map.matches(%r"spec/shared/.*\.rb") do |fm, file|
|
104
|
+
fm[file] = file_map.matches(%r"spec/(controllers|routing|views|helpers)/.*_spec\.rb")
|
105
|
+
end
|
106
|
+
|
107
|
+
file_map.matches(%r"config/(boot|environment(s/test)?).rb") do |fm, file|
|
108
|
+
fm[file] = file_map.matches(%r"spec/(controllers|routing|views|helpers)/.*_spec\.rb")
|
109
|
+
end
|
110
|
+
|
111
|
+
file_map.matches(%r"lib/.*\.rb") do |fm, file|
|
112
|
+
fm[file] = "spec/#{file}_spec.rb"
|
113
|
+
end
|
114
|
+
|
115
|
+
file_map["config/routes.rb"] = file_map.matches(%r"spec/(controllers|routing|views|helpers)/.*_spec\.rb")
|
116
|
+
file_map["spec/spec_helper.rb"] = file_map.matches(%r"spec/(controllers|routing|views|helpers)/.*_spec\.rb")
|
117
|
+
file_map["config/database.yml"] = file_map.matches(%r"spec/models/.*_spec\.rb")
|
118
|
+
|
119
|
+
file_map.pattern
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module LikeAVirgin
|
2
|
+
class FileMap
|
3
|
+
def initialize(root, files)
|
4
|
+
@root = root
|
5
|
+
@files = files
|
6
|
+
@mapping = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def clear
|
10
|
+
@mapping = {}
|
11
|
+
@pattern = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def pattern
|
15
|
+
@pattern ||= @mapping.inject({}) do |result, (source, depends)|
|
16
|
+
depend = depends.flatten.select{ |f| file? f }
|
17
|
+
result[source] = depend unless depend.empty?
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def matches(pattern)
|
23
|
+
if block_given?
|
24
|
+
@files.grep(pattern) do |file|
|
25
|
+
yield self, file
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@files.grep(pattern)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def []=(source, depends)
|
33
|
+
@mapping[source] ||= []
|
34
|
+
@mapping[source] << depends
|
35
|
+
end
|
36
|
+
|
37
|
+
def file?(file)
|
38
|
+
FileTest.exist?(file) and FileTest.file?(file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module LikeAVirgin
|
4
|
+
class Options
|
5
|
+
attr_reader :count
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@count = 2
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: luv [options]"
|
11
|
+
|
12
|
+
opts.on('-c COUNT') do |c|
|
13
|
+
@count = c
|
14
|
+
end
|
15
|
+
end.parse!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LikeAVirgin
|
2
|
+
class World
|
3
|
+
def self.init(options)
|
4
|
+
@count = options.count
|
5
|
+
@worlds = {}
|
6
|
+
@count.times{ |i| @worlds[i] = nil }
|
7
|
+
@cycle = @worlds.cycle
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.emit(files)
|
11
|
+
number, world = @cycle.next
|
12
|
+
world.try :join
|
13
|
+
|
14
|
+
stream = $stdout
|
15
|
+
pid = fork do
|
16
|
+
$stdout = stream
|
17
|
+
$stderr = stream
|
18
|
+
LikeAVirgin.stop
|
19
|
+
ENV["TEST_ENV_NUMBER"] = number.to_s || ""
|
20
|
+
ActiveRecord::Base.configurations = Rails.configuration.database_configuration
|
21
|
+
ActiveRecord::Base.establish_connection
|
22
|
+
|
23
|
+
ARGV.clear
|
24
|
+
ARGV.push files.shift while !files.empty?
|
25
|
+
ARGV.push "-O"
|
26
|
+
ARGV.push "spec/spec.opts"
|
27
|
+
|
28
|
+
require "spec/spec_helper"
|
29
|
+
Spec::Runner.run
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
exit 1 if pid.nil?
|
33
|
+
|
34
|
+
@worlds[number] = Thread.new { Process.waitpid pid }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: like_a_virgin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- miyucy
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-02 00:00:00 +09:00
|
19
|
+
default_executable: lav
|
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: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rb-inotify
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: parallel_tests
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
description: Like a Virgin
|
66
|
+
email: miyucy@gmail.com
|
67
|
+
executables:
|
68
|
+
- lav
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- LICENSE
|
73
|
+
- README.rdoc
|
74
|
+
files:
|
75
|
+
- .document
|
76
|
+
- .gitignore
|
77
|
+
- LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
- Rakefile
|
80
|
+
- VERSION
|
81
|
+
- bin/lav
|
82
|
+
- lib/like_a_virgin.rb
|
83
|
+
- lib/like_a_virgin/file_map.rb
|
84
|
+
- lib/like_a_virgin/monkey_patches.rb
|
85
|
+
- lib/like_a_virgin/options.rb
|
86
|
+
- lib/like_a_virgin/world.rb
|
87
|
+
- spec/like_a_virgin_spec.rb
|
88
|
+
- spec/spec.opts
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
has_rdoc: true
|
91
|
+
homepage: http://github.com/miyucy/like_a_virgin
|
92
|
+
licenses: []
|
93
|
+
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- --charset=UTF-8
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Like a Virgin
|
124
|
+
test_files:
|
125
|
+
- spec/like_a_virgin_spec.rb
|
126
|
+
- spec/spec_helper.rb
|