Created
March 1, 2011 14:11
-
-
Save Sixeight/849177 to your computer and use it in GitHub Desktop.
はやい、Spork ひつよー。 via @jugyo http://blog.twiwt.org/e/cafcfe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
## | |
# script/spec_server_irb | |
require 'drb' | |
require 'irb' | |
require 'g' | |
class FastRSpec | |
def rspec(file) | |
result = $spec_server.run(["--color", "--format", "s", file], STDERR, STDOUT) | |
file_name = File.basename(file) | |
g "[%s] %s" % [result ? 'SUCCESS' : 'FAILED', file_name] | |
end | |
SPEC_DIR = File.expand_path('spec') | |
def model(name) | |
path = File.join(SPEC_DIR, 'models', name + '_spec.rb') | |
return 'no such spec' unless File.exists?(path) | |
rspec path | |
end | |
def controller(name) | |
path = File.join(SPEC_DIR, 'controllers', name + '_controller_spec.rb') | |
return 'no such spec' unless File.exists?(path) | |
rspec path | |
end | |
def view(name) | |
path = File.join(SPEC_DIR, 'views', name + '.html.erb_spec.rb') | |
return 'no such spec' unless File.exists?(path) | |
rspec path | |
end | |
def spec | |
rspec SPEC_DIR | |
end | |
def e | |
puts | |
puts 'bye' | |
exit | |
end | |
end | |
begin | |
begin | |
DRb.start_service("druby://localhost:12345", FastRSpec.new) | |
rescue SocketError, Errno::EADDRNOTAVAIL | |
DRb.start_service("druby://:0", FastRSpec.new) | |
end | |
$spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989") | |
rescue DRb::DRbConnError | |
err.puts "No DRb server is running. Running in local process instead ..." | |
end | |
puts <<FASTRSPEC | |
Fast Rspec servr is running: #{DRb.uri} | |
FASTRSPEC | |
$fast_rspec = FastRSpec.new | |
def rspec(file) | |
$fast_rspec.rspec(file) | |
end | |
def model(name) | |
$fast_rspec.model(name) | |
end | |
def controller(name) | |
$fast_rspec.controller(name) | |
end | |
def view(name) | |
$fast_rspec.view(name) | |
end | |
def spec | |
$fast_rspec.spec | |
end | |
def e | |
$fast_rspec.e | |
end | |
puts <<DESC | |
Example: | |
> rspec 'spec/models/user_spec.rb' | |
DESC | |
IRB.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment