Skip to content

Run Test Suite

Bess Sadler edited this page Feb 1, 2019 · 21 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.

Once you have your docker containers setup and running, make sure you have the necessary code checked out. The new code includes additional dependencies, so you'll need to run bundler again:

git checkout rspec_setup
bundle install

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, and ideally, we write our tests before we write our code. 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

  • We generally set up a rake task to make it to integrate (CI) services like TravisCI*
  1. Run the CI task. You should see a passing test suite:
    rake ci

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?