From c54fbebfec544f43365ed2dc8d9b6ad5d0fc7bbd Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Thu, 28 Feb 2013 00:06:29 -0300 Subject: [PATCH] Guard and rspec boilerplate --- .gitignore | 2 ++ Gemfile | 5 +++++ Gemfile.lock | 19 +++++++++++++++++++ Guardfile | 30 ++++++++++++++++++++++++++++-- Rakefile | 6 +++++- setup-vagrant-dev-box | 2 +- spec/spec_helper.rb | 28 ++++++++++++++++++++++++++++ spec/unit_helper.rb | 5 +++++ tasks/coverage.rake | 5 +++++ tasks/spec.rake | 4 ---- 10 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit_helper.rb create mode 100644 tasks/coverage.rake delete mode 100644 tasks/spec.rake diff --git a/.gitignore b/.gitignore index 6d588d6..d3c3b58 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,7 @@ tmp _yardoc doc/ +/gems.tags + .vagrant /cache diff --git a/Gemfile b/Gemfile index 98545dc..b3f0dd4 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 4952507..8f9673d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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! diff --git a/Guardfile b/Guardfile index a148482..190fdc0 100644 --- a/Guardfile +++ b/Guardfile @@ -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 diff --git a/Rakefile b/Rakefile index eea5261..8247fb1 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/setup-vagrant-dev-box b/setup-vagrant-dev-box index 0f8f342..76db20b 100755 --- a/setup-vagrant-dev-box +++ b/setup-vagrant-dev-box @@ -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" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..c525fdf --- /dev/null +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/unit_helper.rb b/spec/unit_helper.rb new file mode 100644 index 0000000..f3b8d6c --- /dev/null +++ b/spec/unit_helper.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +RSpec.configure do |config| + config.include RSpec::Fire +end diff --git a/tasks/coverage.rake b/tasks/coverage.rake new file mode 100644 index 0000000..8dc9835 --- /dev/null +++ b/tasks/coverage.rake @@ -0,0 +1,5 @@ +desc 'Run specs with code coverage enabled' +task :coverage do + ENV['COVERAGE'] = 'true' + Rake::Task["spec"].execute +end diff --git a/tasks/spec.rake b/tasks/spec.rake deleted file mode 100644 index b72e1cf..0000000 --- a/tasks/spec.rake +++ /dev/null @@ -1,4 +0,0 @@ -if ENV['USER'] == 'vagrant' - require 'rspec/core/rake_task' - RSpec::Core::RakeTask.new(:spec) -end