-
Notifications
You must be signed in to change notification settings - Fork 1
Run Test Suite
- Set up the application for RSpec
- Run the local test suite
If you are completing the lessons in order during the workshop, your system should be all ready. If you're completing this lesson on it's own, please complete the same Lesson Setup as the previous lesson.
In this workshop, we're going to follow the practices recommended by Test Driven Development. That means we're going to be writing automated tests for each new feature we develop. In order to do that, we first need to set up an automated test suite.
The Samvera community tends to use RSpec for testing rails applications. When we generated a new Hyrax work type, we also auto-generated some RSpec tests for that new work type. However, we need to do some setup before those tests will run.
-
Ensure the RSpec-required gems are included in your
Gemfile
. The file is found in the root of your Rails application. Look for a block beginning withgroup :development, :test do
. Note thatrspec-rails
andcapybara
are installed. These are the main testing libraries we'll be working with. -
Setup database cleanup for Fedora/Solr and the relational database: Open
spec/rails_helper.rb
. Around line 69 notice the cleanup tasks that we've added to this application. Why do we need to clean Fedora and our database before each test suite? -
Look at the
rake ci
task. Look at the file inlib/tasks/ci.rake
. What is it doing? What does CI mean?
Note Stop your development solr and fedora instances first, so your vagrant box doesn't run out of memory. In the window where you ran rake hydra:server
, enter Ctrl+c
This is useful with continuous integration (CI) services like TravisCI
- Run the CI task. You should see a passing test suite:
rake ci
This is useful if you want to run single tests, or run tests often and don't want the overhead of starting Solr and Fedora each time
- In a new terminal session, start the test servers and keep them running:
rake hydra:test_server
- In your main terminal session, run your test suite
rspec spec
- You can run a single test like this
rspec spec/models/image_spec.rb:6
- Compare the structure of our
/spec
directory to ourapp
directory - What is a rake task? What kinds of jobs make good tasks?
- What are the advantages of having the CI task launch Solr and Fedora test instances vs. leaving them running?
- What does "pending" mean in the context of our test suite?
- What does that
Randomized with seed
line mean? What are we randomizing and why?