You can then execute all specs with:
bundle exec rspec spec
And only run your decoupled tests with:
bundle exec rspec spec --tag ~rails
You can then execute all specs with:
bundle exec rspec spec
And only run your decoupled tests with:
bundle exec rspec spec --tag ~rails
require 'spec_helper' | |
# Note that a symbol is used because the class will not be loaded when run in non-rails mode | |
# but the spec will still be loaded (but not executed) | |
describe :SomeClass :rails do | |
# this spec needs Rails | |
end | |
require 'spec_helper' | |
require 'some_other_class' | |
# You should require other dependencies here. This also has the benefit of exposing | |
# your dependencies - think about them. | |
describe SomeOtherClass do | |
# this spec does not need Rails | |
end |
Rspec.configure do |config| | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
if config.filter_manager.exclusions.include?(:rails) | |
# Rails not wanted here | |
config.filter_run_excluding :rails => true | |
# since Rails isn't loaded, you need to include the paths that matter to you for requires | |
$:.unshift('./app') | |
# more setup for non-Rails tests | |
else | |
# Rails wanted here | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
end | |
# The following will allow you to use a symbol and still have subject work correctly. | |
config.shared_context :rails => :true do | |
subject do | |
Kernel.const_get(example.metadata[:example_group][:description_args].first).new | |
end | |
end | |
end |
Here's what I've come up with so far in terms of keeping tests in line.
I'm not done yet, it evolves as my project does. I'm using it in a couple places, but I haven't used any meaningful tags yet.
I have some ideas for some.
I can't edit or amend my previous comment.
Here's my (spec/)[https://github.com/Velocitous/blog/tree/master/spec] directory. Mayhaps give me some feedback on the helpers?
Ideally I want to move all specs to be decoupled whenever possible. I would then run those specs in VIM as I'm working on a class. I consider specs coupled with Rails to be integration tests and ultimately I want those to be run by my CI. I'm not there yet, but that's what I'm evolving the code towards. At the moment I typically just run the specs with Rails enabled which will run both the decoupled and non-decoupled tests.