Skip to content

Run Test Suite

Bess Sadler edited this page Oct 31, 2018 · 16 revisions

Goals

  • Set up the application for RSpec
  • Run the local test suite

Lesson Setup

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.

Set up RSpec

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.

  1. 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 with group :development, :test do. Note that rspec-rails and capybara are installed. These are the main testing libraries we'll be working with.

  2. 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?

  3. Look at the rake ci task. Look at the file in lib/tasks/ci.rake. What is it doing? What does CI mean?

Run the test suite

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

Option One: start servers as needed

This is useful with continuous integration (CI) services like TravisCI

  1. Run the CI task. You should see a passing test suite:
    rake ci

Option Two: keep test servers running in the background

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

  1. In a new terminal session, start the test servers and keep them running:
    rake hydra:test_server
  2. In your main terminal session, run your test suite
    rspec spec
  3. You can run a single test like this
    rspec spec/models/image_spec.rb:6

For discussion

  • Compare the structure of our /spec directory to our app 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?