- Overview
- Transcript
3.3 Testing With Capybara
In this lesson we'll see how to create e2e tests with Capybara.
1.Introduction1 lesson, 01:12
1.1Introduction01:12
2.Application Setup2 lessons, 17:25
2.1Front-End Application Setup10:37
2.2Backend Application Setup06:48
3.Public Area7 lessons, 1:37:56
3.1Routes, Navigation and Directives12:06
3.2Unit Tests and E2E Tests With Protractor15:24
3.3Testing With Capybara04:39
3.4Display Edges on the Page16:46
3.5Filter Edges22:35
3.6Testing Boundaries of Two Applications14:39
3.7Acceptance Tests With Capybara and Factory Girl11:47
4.User Section5 lessons, 1:04:12
4.1Front-End Login Form and Validation12:54
4.2Token Authentication27:56
4.3Create New Edge10:32
4.4Refactor09:36
4.5Delete Edges03:14
5.Conclusion1 lesson, 00:31
5.1Conclusion00:31
3.3 Testing With Capybara
Hi. In this excerpt, we'll see how to create end to end tests with Capybara. So, the most difficult thing in end to end testing is to prepare, interact, and clean database between tests. Royal's infrastructure makes it quite easy, with such tools as database cleaner and [UNKNOWN]. So, it makes sense to use it for your end to end tests, especially if you work on hybrid application, which combines standard web application and only parts of it as a single page applications. So, let's set it up. Let's open Gemfile, and at the bottom here I'm gonna create new group for development and test. And inside of it let's add our spec, Rails and Gem, Capybara. Also as we go in to test JavaScript application, we'll add selenium driver. Let's save it, go to terminal, and run bundle. Okay, I've got an error so, not a simple driver, but webdriver. Let's save it, and let's run bundle again. Okay, it is installed. So now let's initialize, rspec. So we do, Rails g rspec:install. That will create spec folder and spec helper. And now let's write our first feature. So let's go back to editor. And here in spec folder, let's create new one. We call it features. And the feature we're going to create is a navigation_spec.rb. So first we need to require spec helper. And then let's describe the behavior that we want to test. So we describe navigation menu, and this is feature with JavaScript, so we need to provide javaScript true. And now let's create example. It changes active menu element depending on route. Okay, so first of all, we visit Home page. And then, we expect to find active element, and inside of it, we want to find [UNKNOWN] and its text, and we expect it to equal home. Okay. Then, I want to click on link, edges, and then I expect to find that active changed, and I find anchor with text, and this text should be equal edges. Okay, so let's save it. I also need to create folder, and let's save it. And now if you try to run this spec. We will fail, but still, let's do this. So, with spec, feature, navigation, spec. Say it uses Firefox and it can't get anywhere. And it happens because it tries to go to the local host to the port 3,000 where Rails application is, but we want to test Angular application. So, we need to have a little bit of modifications. So, let's open spec helper. And inside of it, right here, we go in to set up Capybara app host. And we specify that we want it to be http://127.0.0.1 port 9000. And another thing that we should specify is run server for Capybara to false, because basically, we have two different applications, we have front end application and we have back end application. When we test them together, we just run both services, and it, Capybara should not run server by itself. So now, we save it and go back to terminal. Let's try it again. And now it works, like charm. Excellent. So this is how we can test application with the help of Capybara instead of protractor. So, what's to use is up to you. In this course, we'll use more Capybara approach. Okay. Let's make our changes. Rspec and capybara setup. Okay, so this way, we can use Capybara and Rspec to test the whole stack, and that also will give us ability to manage our database quite easily. So thank you very much for your time, and see you in the next episode.