Skip to content

Commit

Permalink
Setup Guard
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tom Johnson committed Feb 1, 2017
1 parent 00b0a57 commit bd5b40f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd5b40f

Please sign in to comment.