Skip to content
Mark Bussey edited this page Sep 6, 2017 · 2 revisions

Goals:

Run a local test suite

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.

Hydra software uses rspec for testing. 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. Add rspec required gems to your Gemfile found in the root of your application, in one of the group :development, :test blocks:
      group :development, :test do
        # Call 'byebug' anywhere in the code to stop execution and get a debugger console
        gem 'byebug', platform: :mri
        gem 'capybara'
        gem 'database_cleaner'
        gem 'rspec', "~> 3.5"
        gem 'rspec-rails', "~> 3.5"
        gem 'shoulda-matchers'
      end
  2. Run bundle install to make sure those gems are installed
  3. Add this rails_helper.rb file to the spec folder
  4. Add this spec_helper.rb file to the spec folder
  5. Edit config/solr_wrapper_test.yml and config/fcrepo_wrapper_test.yml to add this line (so they will use our already downloaded version of the software):
    download_dir: /var/tmp
    
  6. Add this ci.rake file to lib/tasks
  7. Run rake ci. You should see a passing test suite.

Note: You can see everything we just changed, compared to our base application, here. You can check out a version of our test application with a working test suite here.

For discussion:

  • Compare the structure of our /spec directory to our app directory
  • What is a rake task? What kinds of jobs make good rake tasks?
  • Let's read through the ci.rake file together. What is it doing?
  • CI stands for "continuous integration". What does that mean? How might we run this automatically? (e.g., travis-ci)
  • 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?

Next: Add a metadata field