From bd5b40f948261647946413c021822353704e888f Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Wed, 1 Feb 2017 09:56:29 -0800 Subject: [PATCH] Setup Guard Adds a generic Guardfile. `spec_helper.rb` includes a stub on `Setting` in a before(:each), which prevents various spec files from running without the rest of the suite. This pattern also has the issue that it stubs `Setting#cache_backend` without warning to developers, giving unexpected results. We should find a way to remove it. See #38. In the meanwhile, we introduce a guard to prevent errors, and allow modules that don't depend on `Setting` to be tested independently. --- Gemfile | 1 + Guardfile | 30 ++++++++++++++++++++++++++++++ spec/spec_helper.rb | 5 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Guardfile diff --git a/Gemfile b/Gemfile index 1ff9f51..27cb972 100644 --- a/Gemfile +++ b/Gemfile @@ -57,6 +57,7 @@ group :development, :test do end group :development do + gem 'guard-rspec' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' end diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..785f342 --- /dev/null +++ b/Guardfile @@ -0,0 +1,30 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +# Using -W0 to suppress warnings in automatic test runs +guard :rspec, cmd: 'RUBYOPT="-W0" bundle exec rspec' do + require 'guard/rspec/dsl' + dsl = Guard::RSpec::Dsl.new(self) + + # Feel free to open issues for suggestions and improvements + + # RSpec files + rspec = dsl.rspec + watch(rspec.spec_helper) { rspec.spec_dir } + watch(rspec.spec_support) { rspec.spec_dir } + watch(rspec.spec_files) +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e9e8b76..f10031d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -45,7 +45,10 @@ end config.before(:each) do - allow(Setting).to receive(:cache_backend).and_return('repository') + # @todo: Eliminate this. + if Object.const_defined?('Setting') + allow(Setting).to receive(:cache_backend).and_return('repository') + end end # The settings below are suggested to provide a good initial experience