Run Test Suite - RepoCamp/connect2017 GitHub Wiki

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
    
    NOTE: Some of these gems may already be included in your gem file with more specific versions, you can't have duplicates, so you can remove the less specific line in case of any conflicts.
  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. Start a test solr & fedora server
    1. Open a new terminal window
    2. Change directory cd to your vagrant directory
    3. Connect to your virtual machine using vagrant ssh
    4. start your test server cd /vagrant/connect2017 && rake hydra:test_server
  6. Start a new window to run your tests
    1. Open a new terminal window
    2. Change directory cd to your vagrant directory
    3. Connect to your virtual machine using vagrant ssh
    4. start your test server cd /vagrant/connect2017 && rake spec

ALTERNATE STEPS

  1. Add this ci.rake file to lib/tasks
  2. 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

HOME