This article describes the RSpec setup process in both Ruby and Rails. After setting up in whichever environment you'll be developing in, we recommend you check out Writing Specs in RSpec, and then move on to RSpec Methods.
└── application_root ├── Gemfile ├── Rakefile ├── lib │ └── app.rb └── spec └── app_spec.rb
rspec specas your default rake task. That way, you can simply type
raketo run your test suite. Save this code to your Rakefile:
begin require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task default: :spec rescue LoadError # rspec not available end
require "rspec" require_relative "../lib/app"
Where app is the name of the app.rb file. Now your spec file is linked to your app file, and ready to rock and roll. Make sure, if you haven't already got the gem in the current gemset that you run:
To download RSpec and get moving.
--skip-test-unitto supress creation of the test directory associated with the default Test::Unit framework.
group :development, :test do gem 'rspec-rails' end
rails generate rspec:install
-sto skip editing existing files
--migration=falseto skip creation of migration files ( note that '-s' should take care of this )
rails g model ModelName -s --migration=false
raketo run your test suite.