Created
March 2, 2011 16:25
-
-
Save fixlr/851199 to your computer and use it in GitHub Desktop.
Collection of files I like to have in new ruby projects
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
--color | |
--format nested |
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
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
source :rubygems | |
gem 'rspec' | |
gem 'watchr' |
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
require 'rspec/core/rake_task' | |
task :default => :spec | |
RSpec::Core::RakeTask.new(:spec) | |
desc "Run RSpec with watchr" | |
task :watch do | |
sh %{bundle exec watchr spec/spec_watchr.rb} | |
end |
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
# Run me with: | |
# | |
# $ watchr spec/specs_watchr.rb | |
# -------------------------------------------------- | |
# Convenience Methods | |
# -------------------------------------------------- | |
def all_spec_files | |
Dir['spec/**/*_spec.rb'] | |
end | |
def run_spec_matching(thing_to_match) | |
matches = all_spec_files.grep(/#{thing_to_match}/i) | |
if matches.empty? | |
puts "There were no matches for #{thing_to_match}" | |
else | |
run matches.join(' ') | |
end | |
end | |
def run(files_to_run) | |
puts("Running: #{files_to_run}") | |
system("clear;rspec -cfs #{files_to_run}") | |
no_int_for_you | |
end | |
def run_all_specs | |
run(all_spec_files.join(' ')) | |
end | |
# -------------------------------------------------- | |
# Watchr Rules | |
# -------------------------------------------------- | |
watch('^spec/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^lib/(.*)\.rb') { |m| run_spec_matching(m[1]) } | |
watch('^spec/spec_helper\.rb') { run_all_specs } | |
# -------------------------------------------------- | |
# Signal Handling | |
# -------------------------------------------------- | |
def no_int_for_you | |
@sent_an_int = nil | |
end | |
Signal.trap 'INT' do | |
if @sent_an_int then | |
puts " Shutting down now." | |
exit | |
else | |
puts " Interrupt a second time to quit." | |
@sent_an_int = true | |
Kernel.sleep 1.5 | |
run_all_specs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment