Guard and rspec boilerplate

This commit is contained in:
Fabio Rehm 2013-02-28 00:06:29 -03:00
parent d7fd676adb
commit c54fbebfec
10 changed files with 98 additions and 8 deletions

2
.gitignore vendored
View file

@ -17,5 +17,7 @@ tmp
_yardoc
doc/
/gems.tags
.vagrant
/cache

View file

@ -11,7 +11,12 @@ gem 'vagrant', path: './vagrant'
gem 'rake'
gem 'net-ssh'
gem 'rspec'
gem 'rspec-fire', require: 'rspec/fire'
gem 'rspec-spies', require: false
gem 'simplecov', require: false
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'guard-ctags-bundler'
gem 'rb-inotify'
gem 'log4r'

View file

@ -30,6 +30,11 @@ GEM
pry (>= 0.9.10)
terminal-table (>= 1.4.3)
thor (>= 0.14.6)
guard-bundler (1.0.0)
bundler (~> 1.0)
guard (~> 1.1)
guard-ctags-bundler (0.1.6)
guard (>= 1.1)
guard-rspec (2.4.1)
guard (>= 1.1)
rspec (~> 2.11)
@ -39,6 +44,7 @@ GEM
log4r (1.1.10)
lumberjack (1.0.2)
method_source (0.8.1)
multi_json (1.6.1)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.2.2)
@ -56,7 +62,15 @@ GEM
rspec-core (2.13.0)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-fire (1.1.3)
rspec (~> 2.11)
rspec-mocks (2.13.0)
rspec-spies (2.1.3)
rspec (~> 2.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.4.3)
terminal-table (1.4.5)
thor (0.17.0)
@ -66,11 +80,16 @@ PLATFORMS
DEPENDENCIES
guard
guard-bundler
guard-ctags-bundler
guard-rspec
log4r
net-ssh
rake
rb-inotify
rspec
rspec-fire
rspec-spies
simplecov
vagrant!
vagrant-lxc!

View file

@ -3,8 +3,34 @@
raise 'You should start guard from the dev box!' unless ENV['USER'] == 'vagrant'
guard 'bundler' do
watch('Gemfile')
watch(/^.+\.gemspec/)
end
guard 'ctags-bundler', :src_path => ["lib"] do
watch(/^(lib|spec\/support)\/.*\.rb$/)
watch('Gemfile.lock')
end
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch('spec/spec_helper.rb') { 'spec' }
watch('lib/provider') { 'spec' }
watch(%r{^lib/vagrant-lxc/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch('spec/unit_helper.rb') { "spec/unit" }
watch('spec/spec_helper.rb') { "spec/" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

View file

@ -2,4 +2,8 @@ raise 'This Rakefile is meant to be used from the dev box' unless ENV['USER'] ==
Dir['./tasks/**/*.rake'].each { |f| load f }
task :default => :spec
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :coverage
rescue LoadError; end

View file

@ -78,7 +78,7 @@ vagrant_ssh 'sudo sed -i -e "s/be.archive/br.archive/g" /etc/apt/sources.list'
vagrant_ssh "sudo apt-get update && sudo apt-get upgrade -y"
# Install dependencies
vagrant_ssh "sudo apt-get install lxc rinetd libffi-dev bsdtar libffi-ruby ruby1.9.1-dev htop git virtualbox virtualbox-ose-dkms linux-headers-generic linux-headers-3.5.0-17-generic -y && sudo gem install bundler --no-ri --no-rdoc -v 1.2.5"
vagrant_ssh "sudo apt-get install lxc rinetd libffi-dev bsdtar exuberant-ctags libffi-ruby ruby1.9.1-dev htop git virtualbox virtualbox-ose-dkms linux-headers-generic linux-headers-3.5.0-17-generic -y && sudo gem install bundler --no-ri --no-rdoc -v 1.2.5"
vagrant_ssh "sudo dkms install virtualbox/4.1.18"
vagrant_ssh "sudo service virtualbox start"

28
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,28 @@
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
# This can probably go away once we stop using vagrant as submodule
add_filter { |source_file| source_file.filename =~ /\/vagrant\/plugins\// }
add_filter { |source_file| source_file.filename =~ /\/vagrant\/lib\/vagrant(\/|\.rb)/ }
end
end
require 'bundler/setup'
Bundler.require
require 'rspec-spies'
Dir[File.dirname(__FILE__) + "/spec/support/**/*.rb"].each { |f| require f }
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end

5
spec/unit_helper.rb Normal file
View file

@ -0,0 +1,5 @@
require 'spec_helper'
RSpec.configure do |config|
config.include RSpec::Fire
end

5
tasks/coverage.rake Normal file
View file

@ -0,0 +1,5 @@
desc 'Run specs with code coverage enabled'
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task["spec"].execute
end

View file

@ -1,4 +0,0 @@
if ENV['USER'] == 'vagrant'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
end