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.
- Add rspec required gems to your
Gemfile
found in the root of your application, in one of thegroup :development, :test
blocks:
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.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
- Run
bundle install
to make sure those gems are installed - Add this
rails_helper.rb
file to thespec
folder - Add this
spec_helper.rb
file to thespec
folder - Start a test solr & fedora server
- Open a new terminal window
- Change directory
cd
to your vagrant directory - Connect to your virtual machine using
vagrant ssh
- start your test server
cd /vagrant/connect2017 && rake hydra:test_server
- Start a new window to run your tests
- Open a new terminal window
- Change directory
cd
to your vagrant directory - Connect to your virtual machine using
vagrant ssh
- start your test server
cd /vagrant/connect2017 && rake spec
ALTERNATE STEPS
- Add this
ci.rake
file tolib/tasks
- 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 ourapp
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