RSpec Installation - thuy-econsys/rails_app GitHub Wiki
Configuration file
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# set to true, database is rolled back after each example group is run
config.use_transactional_fixtures = true
# so that RSpec knows what the Spec type is based on directory location relative to ./spec
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
scaffold specs
# RSpec also provides its own spec file generators
$ rails generate rspec:model user
create spec/models/user_spec.rb
Optimize
Make sure you already have spring in your Gemfile and then add gem spring-commands-rspec to Gemfile. Run bundle
to install and then bundle exec spring binstub rspec
to generate an RSpec binstub - create an RSpec executable inside the application’s bin directory. Now instead of running rspec
, run bin/rspec
. The load time should now only be a fraction of the time. Run both to compare.
OR if you'd rather not add another gem and don't mind prefixing spring
command to your rspec command, just run spring rspec
and that's pretty much the same thing, just more typing.