[MUSIC] Hey, good morning, welcome back. Did you have fun with the last module with all the UI development choices? Just know, the cap zone, you can use any of the options that I demonstrated last week. But as I move forward, from this module forward, my examples will be primarily focused at the asset pipeline. But you saw how easy it was to copy those over. And as long as we conform to a certain number of conventions, we really don't have to worry that much about moving from development to production. So the topic this week is testing. We want to learn more about testing before we develop our complex code. We want to now what to test, how to test, and the gotchas that come along. We'll not only test our code, we'll find a few errors and we'll fix it. We'll bring in several tools, like RSpec, a DSL, a domain-specific language for testing. And with testing, you're going to want to get your database in a known state. So we'll bring in Database Cleaner to give us some transactional and truncation database cleanup strategies. So as our objects get more complex, our tests aren't going to want to worry about the details of what it takes to create some of our objects. So we'll bring in Factory Girl to extract away those required fields and relationships that might be there. And we'll also bring in the Faker Gem to insert some simulated data. We're going to treat our test code as if it were production, and try to dry it as much as possible. To do that, we'll take advantage of RSpec's shared context and shared examples. We're going to treat our test code with some of the same care we do with our application code, and try dry it as much as possible. And we'll leverage RSpecs, shared context, and shared examples, where we can build abstract test artifacts and plug them into concrete test box. And we'll leverage Ruby Modules, to build helper methods around some complex application interactions, like login and logout, that we don't want to repeat everywhere. RSpec gives us many different types of tests that we can execute. I'd like to categorize them into two categories, unit and integration. With unit tests, the item under test is isolated, and we bring in things like stubs and mocks, and focus our testing specifically on that item. It tends to be very efficient, but isolated. With integration tests, we're going to take the item under test and put it in the flow. We're going to take some point in the application and go to the database and back. It may take a little bit longer to execute the test, and we might be a little bit more limited in what we can test. But we'll come away with a degree of confidence that what we have works in the overall flow of the operation. Because in the capstone we have a limited amount of time that we have for testing. But we can't do without it. Testing does give us a convenient platform to demonstrate our code, but it also makes sure that it works before we move on. And the regression testing will also point out if we break something while we're implementing a feature down the road. Our specific types are going to be model, request, and feature specs. With model specs we're going to focus on query scopes, facade methods, and relationships. We're going to assume that ActiveRecord and Mongoid work, we don't need to test those. With request backs, we're going to evaluate the APIs for its functionality and the payload concepts before we build the UI on top of it. It's much easier to test the API and make sure that's sound before we bring in the user interface. With feature specs we're going to use Capybara to test the web UI and bring in two drivers to do that, Selenium and PhantomJS with the poltergeist gem. Selenium is a good choice for authoring, where can see the interaction with the browser, keystrokes, button clicks, fields being filled in. Where Poltergeist and PhantomJS have a nice headless solution, where we can use that more for regression testing. For things we have finished and we want to make sure that we haven't broken anything. I will point out, though, that that testing asynchronous applications like the Web UI is a very complex thing to do. It's going to take a good bit of knowledge and good decisions in order to come out with deterministic results. This is the last warm up module before we start developing the application code that's part of the capstone, so we want to make sure you get these concepts well understood before we get into that more complicated code, okay? So put your stuff down and let's get started.