Permalink
Browse files

Merge guillaumegentil's rspactor fork

  • Loading branch information...
rubyphunk
rubyphunk committed Oct 10, 2009
1 parent fcddab1 commit ce0fcc90fc9b281aa11604f8591dadf53819dd17
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Mislav Marohnić
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,58 @@
+task :default => :spec
+
+desc "starts RSpactor"
+task :spec do
+ system "ruby -Ilib bin/rspactor"
+end
+
+desc "generates .gemspec file"
+task :gemspec => "version:read" do
+ spec = Gem::Specification.new do |gem|
+ gem.name = "rspactor"
+ gem.summary = "RSpactor is a command line tool to automatically run your changed specs & cucumber features (much like autotest)."
+ gem.description = "read summary!"
+ gem.email = "guillaumegentil@gmail.com"
+ gem.homepage = "http://github.com/guillaumegentil/rspactor"
+ gem.authors = ["Mislav Marohnić", "Andreas Wolff", "Pelle Braendgaard", "Thibaud Guillaume-Gentil"]
+ gem.has_rdoc = false
+
+ gem.version = GEM_VERSION
+ gem.files = FileList['Rakefile', '{bin,lib,images,spec}/**/*', 'README*', 'LICENSE*']
+ gem.executables = Dir['bin/*'].map { |f| File.basename(f) }
+ end
+
+ spec_string = spec.to_ruby
+
+ begin
+ Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
+ rescue
+ abort "unsafe gemspec: #{$!}"
+ else
+ File.open("#{spec.name}.gemspec", 'w') { |file| file.write spec_string }
+ end
+end
+
+task :bump => ["version:bump", :gemspec]
+
+namespace :version do
+ task :read do
+ unless defined? GEM_VERSION
+ GEM_VERSION = File.read("VERSION")
+ end
+ end
+
+ task :bump => :read do
+ if ENV['VERSION']
+ GEM_VERSION.replace ENV['VERSION']
+ else
+ GEM_VERSION.sub!(/\d+$/) { |num| num.to_i + 1 }
+ end
+
+ File.open("VERSION", 'w') { |v| v.write GEM_VERSION }
+ end
+end
+
+task :release => :bump do
+ system %(git commit VERSION *.gemspec -m "release v#{GEM_VERSION}")
+ system %(git tag -am "release v#{GEM_VERSION}" v#{GEM_VERSION})
+end
View
@@ -0,0 +1 @@
+0.5.3
View
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+require 'rspactor/runner'
+
+RSpactor::Runner.start({
+ :coral => ARGV.delete('--coral'),
+ :celerity => ARGV.delete('--celerity'),
+ :spork => ARGV.delete('--drb'),
+ :view => ARGV.delete('--view'), # by default, rspactor didn't catch specs view
+ :clear => ARGV.delete('--clear'),
+ :run_in => ARGV.last
+})
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,61 @@
+require 'cucumber'
+require 'cucumber/formatter/console'
+require File.dirname(__FILE__) + '/rspactor/growl'
+
+module CucumberGrowler
+ include RSpactor::Growl
+
+ def self.included(base)
+ base.class_eval do
+ alias original_print_stats print_stats
+ include InstanceMethods
+
+ def print_stats(features)
+ title, icon, messages = '', '', []
+ [:failed, :skipped, :undefined, :pending, :passed].reverse.each do |status|
+ if step_mother.steps(status).any?
+ icon = icon_for(status)
+ # title = title_for(status)
+ messages << dump_count(step_mother.steps(status).length, "step", status.to_s)
+ end
+ end
+
+ notify "Cucumber Results", messages.reverse.join(", "), icon
+ original_print_stats(features)
+ end
+ end
+ end
+
+ module InstanceMethods
+ def icon_for(status)
+ case status
+ when :passed
+ 'success'
+ when :pending, :undefined, :skipped
+ 'pending'
+ when :failed
+ 'failed'
+ end
+ end
+
+ def title_for(status)
+ case status
+ when :passed
+ 'Features passed!'
+ when :pending
+ 'Some steps are pending...'
+ when :undefined
+ 'Some undefined steps...'
+ when :skipped
+ 'Some steps skipped...'
+ when :failed
+ 'Failures occurred!'
+ end
+ end
+ end
+
+end
+
+module Cucumber::Formatter::Console
+ include CucumberGrowler
+end
View
@@ -0,0 +1,9 @@
+module RSpactor
+ autoload :Interactor, 'rspactor/interactor'
+ autoload :Listener, 'rspactor/listener'
+ autoload :Inspector, 'rspactor/inspector'
+ autoload :Runner, 'rspactor/runner'
+ autoload :Growl, 'rspactor/growl'
+ autoload :Spork, 'rspactor/spork'
+ autoload :Celerity, 'rspactor/celerity'
+end
View
@@ -0,0 +1,29 @@
+require 'rspactor'
+
+module RSpactor
+ class Celerity
+
+ def self.start(dir)
+ pid_path = "#{dir}/tmp/pids/mongrel_celerity.pid"
+ if File.exist?(pid_path)
+ system("kill $(head #{pid_path}) >/dev/null 2>&1")
+ system("rm #{pid_path} >/dev/null 2>&1")
+ end
+ # kill other mongrels
+ system("kill $(ps aux | grep 'mongrel_rails' | grep -v grep | awk '//{print $2;}') >/dev/null 2>&1")
+ system("rake celerity_server:start >/dev/null 2>&1 &")
+ Interactor.ticker_msg "** Starting celerity server"
+ end
+
+ def self.restart
+ system("rake celerity_server:stop >/dev/null 2>&1 && rake celerity_server:start >/dev/null 2>&1 &")
+ Interactor.ticker_msg "** Restarting celerity server"
+ end
+
+ def self.kill_jruby
+ system("kill $(ps aux | grep jruby | grep -v grep | awk '//{print $2;}') >/dev/null 2>&1")
+ true
+ end
+
+ end
+end
View
@@ -0,0 +1,14 @@
+module RSpactor
+ module Growl
+ extend self
+
+ def notify(title, msg, icon, pri = 0)
+ system("growlnotify -w -n rspactor --image #{image_path(icon)} -p #{pri} -m #{msg.inspect} #{title} &")
+ end
+
+ # failed | pending | success
+ def image_path(icon)
+ File.expand_path File.dirname(__FILE__) + "/../../images/#{icon}.png"
+ end
+ end
+end
View
@@ -0,0 +1,110 @@
+require 'rspactor'
+
+module RSpactor
+ # Maps the changed filenames to list of specs to run in the next go.
+ # Assumes Rails-like directory structure
+ class Inspector
+ EXTENSIONS = %w(rb erb builder haml rhtml rxml yml conf opts feature)
+
+ attr_reader :runner, :root
+
+ def initialize(runner)
+ @runner = runner
+ @root = runner.dir
+ end
+
+ def determine_files(file)
+ candidates = translate(file)
+ cucumberable = candidates.delete('cucumber')
+ candidates.reject { |candidate| candidate.index('.') }.each do |dir|
+ candidates.reject! { |candidate| candidate.index("#{dir}/") == 0 }
+ end
+ files = candidates.select { |candidate| File.exists? candidate }
+
+ if files.empty? && !candidates.empty? && !cucumberable
+ $stderr.puts "doesn't exist: #{candidates.inspect}"
+ end
+
+ files << 'cucumber' if cucumberable
+ files
+ end
+
+ # mappings for Rails are inspired by autotest mappings in rspec-rails
+ def translate(file)
+ file = file.sub(%r:^#{Regexp.escape(root)}/:, '')
+ candidates = []
+
+ if spec_file?(file)
+ candidates << file
+ elsif cucumber_file?(file)
+ candidates << 'cucumber'
+ else
+ spec_file = append_spec_file_extension(file)
+
+ case file
+ when %r:^app/:
+ if file =~ %r:^app/controllers/application(_controller)?.rb$:
+ candidates << 'controllers'
+ elsif file == 'app/helpers/application_helper.rb'
+ candidates << 'helpers' << 'views'
+ elsif !file.include?("app/views/") || runner.options[:view]
+ candidates << spec_file.sub('app/', '')
+
+ if file =~ %r:^app/(views/.+\.[a-z]+)\.[a-z]+$:
+ candidates << append_spec_file_extension($1)
+ elsif file =~ %r:app/helpers/(\w+)_helper.rb:
+ candidates << "views/#{$1}"
+ elsif file =~ /_observer.rb$/
+ candidates << candidates.last.sub('_observer', '')
+ end
+ end
+ when %r:^lib/:
+ candidates << spec_file
+ # lib/foo/bar_spec.rb -> lib/bar_spec.rb
+ candidates << candidates.last.sub($&, '')
+ # lib/bar_spec.rb -> bar_spec.rb
+ candidates << candidates.last.sub(%r:\w+/:, '') if candidates.last.index('/')
+ when 'config/routes.rb'
+ candidates << 'controllers' << 'helpers' << 'views' << 'routing'
+ when 'config/database.yml', 'db/schema.rb', 'spec/factories.rb'
+ candidates << 'models'
+ when 'config/boot.rb', 'config/environment.rb', %r:^config/environments/:, %r:^config/initializers/:, %r:^vendor/:, 'spec/spec_helper.rb'
+ Spork.reload if runner.options[:spork]
+ Celerity.restart if runner.options[:celerity]
+ candidates << 'spec'
+ when %r:^config/:
+ # nothing
+ when %r:^(spec/(spec_helper|shared/.*)|config/(boot|environment(s/test)?))\.rb$:, 'spec/spec.opts', 'spec/fakeweb.rb'
+ candidates << 'spec'
+ else
+ candidates << spec_file
+ end
+ end
+
+ candidates.map do |candidate|
+ if candidate == 'cucumber'
+ candidate
+ elsif candidate.index('spec') == 0
+ File.join(root, candidate)
+ else
+ File.join(root, 'spec', candidate)
+ end
+ end
+ end
+
+ def append_spec_file_extension(file)
+ if File.extname(file) == ".rb"
+ file.sub(/.rb$/, "_spec.rb")
+ else
+ file + "_spec.rb"
+ end
+ end
+
+ def spec_file?(file)
+ file =~ /^spec\/.+_spec.rb$/
+ end
+ def cucumber_file?(file)
+ file =~ /^features\/.+$/
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit ce0fcc9

Please sign in to comment.